Content-Security-Policy: worker-src directive

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.

The HTTP Content-Security-Policy (CSP) worker-src directive specifies valid sources for Worker, SharedWorker, or ServiceWorker scripts.

CSP version 3
Directive type Fetch directive
Fallback

If this directive is absent, the user agent will first look for the child-src directive, then the script-src directive, then finally for the default-src directive, when governing worker execution.

Syntax

http
Content-Security-Policy: worker-src 'none';
Content-Security-Policy: worker-src <source-expression-list>;

This directive may have one of the following values:

'none'

No resources of this type may be loaded. The single quotes are mandatory.

<source-expression-list>

A space-separated list of source expression values. Resources of this type may be loaded if they match any of the given source expressions. For this directive, the following source expression values are applicable:

Examples

Violation cases

Given this CSP header:

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

Worker, SharedWorker, ServiceWorker are blocked and won't load:

html
<script>
  let blockedWorker = new Worker("data:text/javascript,…");
  blockedWorker = new SharedWorker("https://not-example.com/");
  navigator.serviceWorker.register("https://not-example.com/sw.js");
</script>

Specifications

Specification
Content Security Policy Level 3
# directive-worker-src

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
worker-src
Chrome – Full support
Chrome 59 (Release date: 2017-06-05)
footnote
footnote Chrome 59 and higher skips the deprecated child-src directive.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 58 (Release date: 2018-01-23)
footnote Full support
Opera – Full support
Opera 46 (Release date: 2017-06-22)
footnote
footnote Opera 46 and higher skips the deprecated child-src directive.
Safari – Full support
Safari 15.5 (Release date: 2022-05-16)
footnote Full support
Chrome Android – Full support
Chrome Android 59 (Release date: 2017-06-06)
footnote
footnote Chrome Android 59 and higher skips the deprecated child-src directive.
Firefox for Android – Full support
Firefox for Android 58 (Release date: 2018-01-22)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote
footnote Opera Android 43 and higher skips the deprecated child-src directive.
Safari on iOS – Full support
Safari on iOS 15.5 (Release date: 2022-05-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 59 (Release date: 2017-06-06)
footnote
footnote WebView Android 59 and higher skips the deprecated child-src directive.
WebView on iOS – Full support
WebView on iOS 15.5 (Release date: 2022-05-16)
footnote Full support

Legend

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

Full support
Full support
See implementation notes.

See also