coderef

Content Security Policy (CSP)Baseline · Widely available

Content Security Policy (CSP) helps to mitigate certain security threats, including cross-site scripting (XSS) and clickjacking attacks. It consists of a set of directives from a website to a browser, which instruct the browser to restrict the things that the site is allowed to do.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Aug 2, 2016. Widely available since Feb 2, 2019.

Browser support

DesktopChrome
1–24Not supported
25+Supportedsince Feb 21, 2013
Current: 155
Edge
12–13Not supported
14+Supportedsince Aug 2, 2016
Current: 154
Firefox
1–22Not supported
23+Supportedsince Aug 6, 2013
Current: 157
Safari
1–6Not supported
7+Supportedsince Oct 22, 2013
Current: 27
MobileChrome Android
18–18Not supported
25+Supportedsince Feb 27, 2013
Current: 155
Firefox Android
4–22Not supported
23+Supportedsince Aug 6, 2013
Current: 157
Safari iOS
1–6Not supported
7+Supportedsince Sep 18, 2013
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: securitypolicyviolation event.

Feature detection

JS · check before using
if ("HTMLIFrameElement" in globalThis && "csp" in HTMLIFrameElement.prototype) {
  // HTMLIFrameElement.csp is available
}

Sub-features

Support for each part of the feature (52). The overall table above shows when the whole feature works.

Show 32 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
iframe.csp6179✕✕61✕✕
meta.http-equiv.content-security-policy≤59121≤10.1≤594≤10.3
nonce61797515.5617915.5
http.headers.Content-Security-Policy251423725237
http.headers.Content-Security-Policy-Report-Only251423725237
http.headers.Content-Security-Policy.base-uri4079351040359.3
http.headers.Content-Security-Policy.child-src4015451040459.3
http.headers.Content-Security-Policy.connect-src251450725237
http.headers.Content-Security-Policy.default-src251423725237
http.headers.Content-Security-Policy.font-src251423725237
http.headers.Content-Security-Policy.form-action4015361040369.3
http.headers.Content-Security-Policy.frame-ancestors4015581040589.3
http.headers.Content-Security-Policy.frame-src251423725237
http.headers.Content-Security-Policy.img-src251423725237
http.headers.Content-Security-Policy.manifest-src40794111404111
http.headers.Content-Security-Policy.media-src251423725237
http.headers.Content-Security-Policy.meta-element-support25≤1845725457
http.headers.Content-Security-Policy.object-src251423725237
http.headers.Content-Security-Policy.report-sample59796315.4596315.4
http.headers.Content-Security-Policy.sandbox251450725507
http.headers.Content-Security-Policy.script-src251423725237
http.headers.Content-Security-Policy.script-src-attr757910815.47510815.4
http.headers.Content-Security-Policy.script-src-elem757910815.47510815.4
http.headers.Content-Security-Policy.script-src.external_scripts597911615.65911615.6
http.headers.Content-Security-Policy.script-src.wasm-unsafe-eval9797102169710216
http.headers.Content-Security-Policy.strict-dynamic52795215.4525215.4
http.headers.Content-Security-Policy.style-src251423725237
http.headers.Content-Security-Policy.style-src-attr757910815.47510815.4
http.headers.Content-Security-Policy.style-src-elem757910826.27510826.2
http.headers.Content-Security-Policy.unsafe-hashes697910915.46910915.4
http.headers.Content-Security-Policy.worker-src59795815.5595815.5
http.headers.Content-Security-Policy.worker_support56795010565010