LP1*_*P13 5 internet-explorer content-security-policy internet-explorer-11 coreclr asp.net-core
在我的每个响应的asp.net核心应用程序中,我正在添加内容安全策略标头.我理解,对于IE,标题名称是X-Content-Security-Policy
和其他浏览器一样,如chromeContent-Security-Policy
标题值看起来如下所示nonce
每个响应的不同之处.
default-src 'none';
script-src 'self' 'nonce-somerandomvalue-differnt-foreach-reasone' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
img-src 'self' data:;
font-src 'self';
object-src 'self';
connect-src 'self';
report-uri /csp/report;
Run Code Online (Sandbox Code Playgroud)
该应用程序在几页上使用内联JavaScript.因此,要修复内联脚本违规,我nonce
在脚本标记中添加相同的值.
<script type="text/javascript" nonce="somerandomvalue-differnt-foreach-reasone">
这里重要的是nonce值需要与header中的nonce值匹配.这里有一些细节
我实现了中间件和tag-helper,它们分别将nonce添加到header和script标签中.我确保nonce
在页面渲染时两个值都匹配.
然后只是为了在页面上测试目的我添加脚本没有随机数
<script type="text/javascript">
$(function () {
alert('i am hacker');
})
</script>
Run Code Online (Sandbox Code Playgroud)
Google Chrome会检测到此违规行为并按预期阻止上述脚本.但是在上面的IE 11中,脚本被执行而没有任何违规.再次,我确定IE中的标题是X-Content-Security-Policy
为什么IE 11没有阻止脚本?
sid*_*ker 13
IE 11根本不支持使用nonce
属性和nonce-
源值.
IE11支持的唯一CSP指令是sandbox
指令.它忽略了所有其他CSP指令.
所以你可以完全'nonce-somerandomvalue-differnt-foreach-reasone'
从X-Content-Security-Policy
标题中删除部分,IE11仍然允许内联脚本.
IE11将允许内联脚本,无论您做什么,除非您的服务器发送带有X-Content-Security-Policy: sandbox
标头的响应,在这种情况下,它将禁止所有脚本.放松的唯一方法是发送X-Content-Security-Policy: sandbox allow-scripts
,但这将允许所有脚本,包括内联脚本.
所以我认为使用IE11没有办法告诉它不允许只使用内联脚本.您只能告诉IE11允许所有脚本,或者不允许任何脚本.
另请注意:IE11于2013年发布,早在nonce
任何地方指定属性之前.我认为该nonce
属性的第一个CSP草案规范是在2014年的某个时候.
http://caniuse.com/#feat=contentsecuritypolicy有关于CSP1指令的浏览器支持的详细信息:
Internet Explorer 10-11中的部分支持是指仅使用
X-Content-Security-Policy
标头支持"sandbox"指令的浏览器.
该nonce
属性是CSP2功能.请参阅http://caniuse.com/#feat=contentsecuritypolicy2
nonce
Edge 15中添加了对CSP2功能的支持和其他功能.因此Edge 14及更早版本不支持nonce
或其他新的CSP2功能.但Edge12 +完全支持所有CSP1.
归档时间: |
|
查看次数: |
8540 次 |
最近记录: |