internet-explorer - 内容安全策略在 Internet Explorer 11 中不起作用

标签 internet-explorer asp.net-core internet-explorer-11 content-security-policy coreclr

在我为每个响应的 asp.net 核心应用程序中,我添加了内容安全策略 header 。我知道对于 IE,标题名称是 X-Content-Security-Policy对于其他浏览器,如 chrome,它的 Content-Security-Policy
header 值如下所示,其中 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;   

该应用程序在几个页面上使用内联 javascript。所以为了修复内联脚本违规,我添加了相同的 nonce脚本标签中的值。<script type="text/javascript" nonce="somerandomvalue-differnt-foreach-reasone">这里重要的是 nonce 值需要与 header 中的 nonce 值匹配。 some details here

我实现了中间件和标签助手,分别将随机数添加到 header 和脚本标签中。我确保两个 nonce页面呈现时,值确实匹配。

然后只是为了在页面上进行测试,我添加了脚本 没有随机数
<script type="text/javascript">
    $(function () {
        alert('i am hacker');
    })
</script>

谷歌浏览器检测到此违规并按预期阻止上述脚本。然而,在 IE 11 中,上面的脚本被执行而没有任何违规。再次,我确保 IE 中的标题是 X-Content-Security-Policy
为什么 IE 11 没有阻止脚本?

最佳答案

IE 11 不支持使用 nonce属性和 nonce-源值。

The only CSP directive IE11 supports is the sandbox directive .它忽略所有其他 CSP 指令。

所以你可以完全放弃 'nonce-somerandomvalue-differnt-foreach-reasone'部分来自您的 X-Content-Security-Policy header 和 IE11 仍将允许内联脚本。

无论您做什么,IE11 都将允许内联脚本,除非您让服务器发送带有 X-Content-Security-Policy: sandbox 的响应。 header ,在这种情况下,它将禁止所有脚本。而唯一放松的方法就是发送 X-Content-Security-Policy: sandbox allow-scripts ,但这将允许所有脚本,包括内联脚本。

所以我认为 IE11 没有办法告诉它只禁止内联脚本。您只能告诉 IE11 允许所有脚本或不允许任何脚本。

另请注意:IE11 于 2013 年发布,早于 nonce属性在任何地方指定。我认为第一个 CSP 草案规范是 nonce属性是在 2014 年的某个时候指定的。

http://caniuse.com/#feat=contentsecuritypolicy有关于 CSP1 directives 的浏览器支持的详细信息:

Partial support in Internet Explorer 10-11 refers to the browser only supporting the 'sandbox' directive by using the X-Content-Security-Policy header.


nonce属性是 a CSP2 feature .见 http://caniuse.com/#feat=contentsecuritypolicy2

Support for nonce and other CSP2 features was added in Edge 15 .因此 Edge 14 及更早版本不支持 nonce或其他新的 CSP2 功能。但 Edge12+ 完全支持 all of CSP1 .

关于internet-explorer - 内容安全策略在 Internet Explorer 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42937146/

相关文章:

html - 字体在 IE 或 Edge 中不工作

asp.net - 在单独的选项卡/窗口中打开 PDF

javascript - .hasOwnProperty ('getComputedStyle' ) 在 IE 11 中为 false

javascript - 下载链接在 Internet Explorer 上不起作用

javascript - jQuery 脚本无法在 Internet Explorer 中运行(第 1 行第 1 个字符出现语法错误)

javascript - 如果 Internet Explorer 将打印页面大小调整为 60%

linux - 外部服务登录链接 asp core

ubuntu - 尝试在 Ubuntu 16.04 下运行 asp .net core 应用程序时出现 core-dump 错误

c# - Razor Pages OnPost 方法中的 Page() 方法有什么作用?

internet-explorer - 从 Canvas 下载图像在 IE 11 中不起作用