尝试将CDN加载到Play Framework应用程序时出现CSP错误

时间:2018-01-06 19:15:52

标签: jquery playframework cdn

我是Play Framework的新手,我试图将jquery CDN放到我的播放应用程序中。每次我将任何类型的CDN放入我的视图文件(scala.html扩展名)时,我都会收到一条CSP错误说:

Refused to load the script 
'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js' because 
it violates the following Content Security Policy directive: "default-src 
'self'". Note that 'script-src' was not explicitly set, so 'default-src' is 
used as a fallback.

我提到How does Content Security Policy work?并相应地添加了元标记元素,并引用了http://content-security-policy.com/
但仍无法使其发挥作用。

如果有人能帮助我的话,我会非常感激。谢谢你提前!

2 个答案:

答案 0 :(得分:1)

我认为问题出在application.conf文件中,您没有正确设置参数play.filters.headers.contentSecurityPolicy

有关参考,请参阅this page

答案 1 :(得分:0)

Luca T.答案是对的。如果其他人偶然遇到同样的问题,我会用这个来提供更详细的答案。

要让CSP错误消失,我必须添加:

contentSecurityPolicy = null

在application.conf文件中' play.filters.headers'部分如下所示:

enter image description here

注意:这对应用程序的安全性不利,但如果您只是尝试创建一个简单的应用程序,则可以完成工作。