Content Security Policy の 'strict-dynamic' で nonce をちゃんと設定しているのにエラーになるときは prefetch/preload が原因かも
結論
<link rel="preload" href="/_nuxt/dddd88be1484ef5d94bc.js" as="script" nonce="2UhC1DHXJTpbvWCe">
<link rel="preload" href="/_nuxt/dddd88be1484ef5d94bc.js" as="script" nonce="2UhC1DHXJTpbvWCe">
上記のように preload(prefetchなども?)
している script にも nonce をつけたらエラーが消えました。
経緯
ヘッダーは
Content Security Policy: script-src 'nonce-2UhC1DHXJTpbvWCe' 'unsafe-inline' 'strict-dynamic' https: http:;
となっていて、読み込むソースも
<script nonce="2UhC1DHXJTpbvWCe" src="***"></script>
となっているのに、なぜかChromeで
Refused to load the script "/_nuxt/dddd88be1484ef5d94bc.js" because it violates the following Content Security Policy directive: "script-src 'nonce-2UhC1DHXJTpbvWCe' 'unsafe-inline' 'strict-dynamic' https: http:". 'strict-dynamic' is present, so host-based whitelisting is disabled. Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
というエラーが出てしまっていた。
Nuxtを使っていたので、ずっとServiceWorker(worker-src
)や
manifest.jsonの content_security_policy
など色々と疑っていたのですが、
まさかの盲点でした。
Author And Source
この問題について(Content Security Policy の 'strict-dynamic' で nonce をちゃんと設定しているのにエラーになるときは prefetch/preload が原因かも), 我々は、より多くの情報をここで見つけました https://qiita.com/naota70/items/6ce5e334041f6e2f1d1b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .