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
ディレクティブ種別 フェッチディレクティブ
フォールバック

このディレクティブがない場合、ユーザーエージェントはワーカーの実行を制御するとき、まず child-src ディレクティブを探し、次に script-src ディレクティブ、そして最後に default-src ディレクティブを探します。

構文

worker-src ポリシーには 1 つ以上のソースを指定することができます。

http
Content-Security-Policy: worker-src <source>;
Content-Security-Policy: worker-src <source> <source>;

ソース

<source> は、 CSP ソース値にあるいずれかの値を取ることができます。

なお、この同じ値のセットはすべてのフェッチディレクティブ(と 他の多くのディレクティブ)で使用できます。

違反の場合

この CSP ヘッダーが与えられている時、

http
Content-Security-Policy: worker-src https://example.com/

Worker, SharedWorker, ServiceWorker はブロックされ、読み込まれません。

html
<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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
worker-src

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

関連情報