我在 Visual Studio 2015 Professional 中创建了新的 asp.net mvc 5 项目
而且我在内容安全策略的布局中添加了元标记 -
<meta http-equiv="content-security-policy"
content="default-src 'none'; script-src 'self';
connect-src 'self'; img-src 'self'; style-src 'self';" />
现在,当我运行我的应用程序时,我在 chrome 浏览器控制台中收到以下错误 -
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-CwE3Bg0VYQOIdNAkbB/Btdkhul49qZuwgNCMPgNY5zw='), or a nonce ('nonce-...') is required to enable inline execution. modernizr-2.6.2.js:157
modernizr-2.6.2.js:157 有 6 个错误,其中一个与脚本有关,即拒绝加载脚本 localhost
我认为我的项目中没有任何内联样式,那么为什么 CSP 拒绝应用错误?
最佳答案
显然,modernizr 要么注入(inject) style
带有一些 CSS 属性的元素,或者注入(inject)一些 style
属性;您可以通过更改您的 CSP 策略来处理它:
<meta http-equiv="content-security-policy"
content="default-src 'none'; script-src 'self';
connect-src 'self'; img-src 'self';
style-src 'self' 'sha256-CwE3Bg0VYQOIdNAkbB/Btdkhul49qZuwgNCMPgNY5zw=';" />
关于asp.net - 拒绝应用内联样式,因为它违反了以下内容安全策略指令 : "style-src ' self'"modernizr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44495929/