CSP 和内联脚本被阻止

CSP and inline scripts getting blocked

努力理解 CSP,获得

Refused to apply inline style because it violates the following Content Security Policy directive: "script-src 'self' https://example;"

例如,我的域 https://example.com, in my policy, I have script-src 'self' https://example; yet inline scripts from https://example/static/js/19.b56ecbe.chunk.js 被阻止了。

我本以为 'self' 会允许脚本 运行,我这里哪里错了?

@sideshowbarker 已经解释了为什么你不能这样做,但是如果你想在你的页面上允许 "inline scripts",你可以使用一个小变体。

只需在所有 script 标签以及 CSP header 本身中包含 nonce。 在这里查看更多详细信息:https://www.troyhunt.com/locking-down-your-website-scripts-with-csp-hashes-nonces-and-report-uri/