问题
Content-Security-Policy应该默认将脚本和样式解析列入黑名单,并根据各种指令允许它,其中一个指令被验证为预期输出的散列。浏览器必须无法实现任何未提前匹配哈希的Javascript或CSS。具有匹配哈希的代码应该正常执行。 Microsoft Edge拒绝所有JS / CSS页内阻止。
说明访问Microsoft Edge以及任何其他浏览器中的实时演示链接。
演示原始源代码
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'sha256-JtUhvM7uQO2KX5IEGWxN+rhEyzzsyFelfO2gXvYEuWA='; script-src https://ajax.googleapis.com 'sha256-iZzrsbzuGxfOaTdnB/E6RQBssyXQRp7W8YtZD2Wg/Rc=';" />
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; style-src 'sha256-JtUhvM7uQO2KX5IEGWxN+rhEyzzsyFelfO2gXvYEuWA='; script-src https://ajax.googleapis.com 'sha256-iZzrsbzuGxfOaTdnB/E6RQBssyXQRp7W8YtZD2Wg/Rc=';" />
<style>#loading{color:transparent}#loading:after{color:green;content:"Style loaded."}</style>
</head>
<body>
<span id="loading">Hashes loading...</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>alert("Script loaded.")</script>
CSP14304: Unknown source ‘'sha256-JtUhvM7uQO2KX5IEGWxN+rhEyzzsyFelfO2gXvYEuWA='’ for directive ‘style-src’ in - source will be ignored.
CSP14306: No sources given for directive ‘style-src’ for - this is equivalent to using ‘none’ and will prevent the downloading of all resources of this type.
CSP14304: Unknown source ‘'sha256-iZzrsbzuGxfOaTdnB/E6RQBssyXQRp7W8YtZD2Wg/Rc='’ for directive ‘script-src’ in - source will be ignored.
CSP14312: Resource violated directive ‘style-src 'sha256-JtUhvM7uQO2KX5IEGWxN+rhEyzzsyFelfO2gXvYEuWA='’ in : inline style. Resource will be blocked.
CSP14312: Resource violated directive ‘script-src LINK-REMOVED-INSUFFICIENT-REPUTATION-ON-STACKOVERFLOW-SHOULD-BE-THE-GOOGLE-API-URL 'sha256-iZzrsbzuGxfOaTdnB/E6RQBssyXQRp7W8YtZD2Wg/Rc='’ in : inline script. Resource will be blocked.
尝试修复
default-src
和connect-src
的值更改为self
而不是none
我想不出任何其他事情可以尝试。
24小时后更新:为完整性添加了X-Content-Security-Policy&amp; JSBin URL已更新,但它对这种特定情况没有任何影响。
答案 0 :(得分:9)
编辑:这可能不正确。见上面的评论。
IE 11不支持Content-Security-Policy
(仅X-Content-Security-Policy
),此操作无法打开。
IE 12支持CSP,但不会删除nonce / hashes,它会关闭...除非你还在'unsafe-inline'
标题中提供Content-Security-Policy
。
CSP级别2表示“如果提供了哈希或随机数,请忽略'unsafe-inline'
。”这是为了向后兼容,因为旧版浏览器会查看'unsafe-inline'
而不是nonces / hashes。见http://www.w3.org/TR/CSP2/#directive-script-src
答案 1 :(得分:3)
http://caniuse.com/#feat=contentsecuritypolicy
http://caniuse.com/#feat=contentsecuritypolicy2
IE Edge不支持内容安全策略级别2,hash-source
属于级别2。