| Type | String |
|---|---|
| Mandatory | No |
| Manifest version | 2 or higher |
| Example | Manifest V2: "content_security_policy": "default-src 'self'" "content_security_policy": { "extension_pages": "default-src 'self'" } |
Extensions have a content security policy (CSP) applied to them by default. The default policy restricts the sources from which extensions can load code (such as <script> resources) and disallows potentially unsafe practices such as the use of eval(). See Default content security policy to learn more about the implications of this.
You can use the "content_security_policy" manifest key to loosen or tighten the default policy. This key is specified in the same way as the Content-Security-Policy HTTP header. See Using Content Security Policy for a general description of CSP syntax.
For example, you can use this key to:
- Restrict permitted sources for other types of content, such as images and stylesheets, using the appropriate policy directive.
- Allow the extension to take advantage of WebAssembly by including the
'wasm-unsafe-eval'source in thescript-srcdirective. - Loosen the default
script-srcpolicies (Manifest V2 only):- Allow the extension to load scripts from outside its package by supplying their URL in the
script-srcdirective. - Allow the extension to execute inline scripts by supplying the hash of the script in the
script-srcdirective. - Allow the extension to use
eval()and similar features by including'unsafe-eval'in thescript-srcdirective.
- Allow the extension to load scripts from outside its package by supplying their URL in the
There are restrictions on the policy you can specify with this manifest key:
- The
script-srcdirective must include at least the'self'keyword and may only contain secure sources. The set of permitted secure sources differs between Manifest V2 and Manifest V3. - The policy may include
default-srcalone (withoutscript-src) if its sources meet the requirement for thescript-srcdirective. - The
object-srckeyword may be required, see object-src directive for details. - Directives that reference code –
script-src,script-src-elem,worker-src, anddefault-src(if used as a fallback) – share the same secure source requirement. There are no restrictions on CSP directives that cover non-script content, such asimg-src.
In Manifest V3, all CSP sources that refer to external or non-static content are forbidden. The only permitted values are 'none', 'self', and 'wasm-unsafe-eval'. In Manifest V2, a source for a script directive is considered secure if it meets these criteria:
- Wildcard hosts are not permitted, such as
"script-src 'self' *". - Remote sources must use
https:schemes. - Remote sources must not use wildcards for any domains in the public suffix list (so "*.co.uk" and "*.blogspot.com" are not allowed, although "*.foo.blogspot.com" is permitted).
- All sources must specify a host.
- The only permitted schemes for sources are
blob:,filesystem:,moz-extension:,https:, andwss:. - The only permitted keywords are:
'none','self','unsafe-eval', and'wasm-unsafe-eval'.