CSP: worker-src
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.
HTTP の Content-Security-Policy
(CSP) における worker-src
ディレクティブは、 Worker
, SharedWorker
, ServiceWorker
スクリプトの有効なソースを指定します。
CSP バージョン | 3 |
---|---|
ディレクティブ種別 | フェッチディレクティブ |
代替 |
このディレクティブがない場合、ユーザーエージェントはワーカーの実行を制御するとき、まず |
構文
Content-Security-Policy: worker-src 'none';
Content-Security-Policy: worker-src <source-expression-list>;
ソース
このディレクティブは、次のいずれかの値を指定することができます。
'none'
-
この種類のリソースは読み込まれません。単一引用符は必須です。
<source-expression-list>
-
ソース表現の値を空白で区切ったリストです。この種類のリソースは、指定されたソース表現のいずれかと一致した場合に読み込まれます。このディレクティブでは、以下のソース表現の値が適用できます。
例
違反の場合
この CSP ヘッダーが与えられている時、
Content-Security-Policy: worker-src https://example.com/
Worker
, SharedWorker
, ServiceWorker
はブロックされ、読み込まれません。
<script>
let blockedWorker = new Worker("data:application/javascript,…");
blockedWorker = new SharedWorker("https://not-example.com/");
navigator.serviceWorker.register("https://not-example.com/sw.js");
</script>
仕様書
Specification |
---|
Content Security Policy Level 3 # directive-worker-src |