【发布时间】:2015-05-29 18:14:28
【问题描述】:
当我从 CSP 标头上的 script-src 中删除 unsafe-inline 时,Modernizr 2.8.3 上出现多个错误,JQuery 2.1.3 上出现错误。这很奇怪,因为我只在我的一个网站上收到此错误,尽管我在其他网站上使用相同的库而没有 CSP 问题。
错误示例:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' *.github.com *.bootstrapcdn.com *.jsdelivr.net *.twitter.com *.googleapis.com *.google.com dmjwor2go9n1u.cloudfront.net". Either the 'unsafe-inline' keyword, a hash ('sha256-CwE3Bg0VYQOIdNAkbB_Btdkhul49qZuwgNCMPgNY5zw='), or a nonce ('nonce-...') is required to enable inline execution.
我有一种预感是和剧本的部分有关:
style = ['­','<style id="s', mod, '">', rule, '</style>'].join('');
当我单击 chrome 控制台将我链接到错误时,我被放置在此处:
<style id="s',v,'">',e,"</style>"].join(""),u.id=v,(l?u:d).innerHTML+=a,d.appendChild(u)
对于为什么会发生这种情况非常迷茫,并且似乎无法在我的谷歌搜索中找到任何真正的方向。这些错误是否会引发我如何使用这些库?任何帮助或见解表示赞赏。
【问题讨论】:
标签: jquery security modernizr content-security-policy