'strict-dynamic' 存在,因此 host-based 白名单被禁用
'strict-dynamic' is present, so host-based whitelisting is disabled
我正在从源加载一个虚拟 JS 脚本,例如:
<script src="http://www.this-host.test/loadMe.js"></script>
CSP header 设置为:
script-src 'self' 'strict-dynamic' 'nonce-{randomString}';
由于脚本源来自它的 原始主机 并且被 CSP
header 允许,所以 loadMe.js
应该加载并执行。
相反,我得到:
Refused to load the script 'http://www.this-host.test/loadMe.js' because it
violates the following Content Security Policy directive: "script-src 'self' 'strict-dynamic' 'nonce-{randomString}';.
'strict-dynamic' is present, so host-based whitelisting is disabled.
在 Macintosh; Mac OS X 10_15_2
、浏览器 Chrome/79.0.3945.117, Firefox/71.0
.
上测试
虽然我在 Safari
上没有收到这条消息。
也许值得一提的是我正在本地测试它。
无论如何,当 CSP
header 允许从 origin host 加载资源时,我不想使用 nonce-{randomString}
。
对此有什么想法吗?
根据 csp.withgoogle.com 服务器:
On its own, 'strict-dynamic' causes the browser to rely only on nonces or hashes and ignore the URI whitelist in script-src, for backwards compatibility reasons.
这告诉我应该这样定义它:
<script nonce="{randomString}" src="http://www.this-host.test/loadMe.js"></script>
如果 loadMe.js"
在运行时加载另一个 script src
文件,请像这样定义它:
<script strict-dynamic nonce="{randomString}" src="http://www.this-host.test/loadMe.js"></script>
当然你必须信任loadMe.js
源文件。
我正在从源加载一个虚拟 JS 脚本,例如:
<script src="http://www.this-host.test/loadMe.js"></script>
CSP header 设置为:
script-src 'self' 'strict-dynamic' 'nonce-{randomString}';
由于脚本源来自它的 原始主机 并且被 CSP
header 允许,所以 loadMe.js
应该加载并执行。
相反,我得到:
Refused to load the script 'http://www.this-host.test/loadMe.js' because it
violates the following Content Security Policy directive: "script-src 'self' 'strict-dynamic' 'nonce-{randomString}';.
'strict-dynamic' is present, so host-based whitelisting is disabled.
在 Macintosh; Mac OS X 10_15_2
、浏览器 Chrome/79.0.3945.117, Firefox/71.0
.
虽然我在 Safari
上没有收到这条消息。
也许值得一提的是我正在本地测试它。
无论如何,当 CSP
header 允许从 origin host 加载资源时,我不想使用 nonce-{randomString}
。
对此有什么想法吗?
根据 csp.withgoogle.com 服务器:
On its own, 'strict-dynamic' causes the browser to rely only on nonces or hashes and ignore the URI whitelist in script-src, for backwards compatibility reasons.
这告诉我应该这样定义它:
<script nonce="{randomString}" src="http://www.this-host.test/loadMe.js"></script>
如果 loadMe.js"
在运行时加载另一个 script src
文件,请像这样定义它:
<script strict-dynamic nonce="{randomString}" src="http://www.this-host.test/loadMe.js"></script>
当然你必须信任loadMe.js
源文件。