sandbox
sandbox applies the same restrictions to the response as the <iframe sandbox> attribute does to an embedded document: no scripts, no forms, no popups, and an opaque origin, until you grant each capability back by token.
It is the odd directive out. It takes tokens rather than sources, it is not allowed in a <meta> tag, and - the part that catches people - it is ignored in a report-only policy. You cannot trial it the way you trial the rest of CSP.
Syntax
Section titled “Syntax”Content-Security-Policy: sandbox;Content-Security-Policy: sandbox <token> <token>;What it controls
Section titled “What it controls”- Script execution, unless
allow-scriptsis granted. - Form submission, unless
allow-formsis granted. - Popups, unless
allow-popupsis granted. - Modal dialogs -
alert(),confirm(),prompt(),print()- unlessallow-modalsis granted. - Top-level navigation, unless
allow-top-navigationorallow-top-navigation-by-user-activationis granted. - The document’s origin: without
allow-same-originthe response gets an opaque origin, which means no cookies, nolocalStorage, and no same-origin access to anything.
What it does not control
Section titled “What it does not control”- Anything at all when sent on
Content-Security-Policy-Report-Only. The directive is ignored there. - Anything at all in a
<meta http-equiv>policy. Header only.
Fallback
Section titled “Fallback”sandbox has no fallback and takes tokens rather than sources. It applies only when written, only on an enforcing header, and only from an HTTP response - not from a <meta> tag.
Recommended value
Section titled “Recommended value”Content-Security-Policy: sandbox- Start with no tokens and grant back only what the response needs. There is no useful default token set - the right one is entirely specific to what the response is for.
- Reach for
sandboxon user-uploaded content, previews and untrusted HTML you have to serve from your own origin, not on your application’s own pages. - Do not grant
allow-scriptsandallow-same-origintogether on untrusted content. Between them they let the document reach its own sandbox and remove it, which leaves you with the syntax of a sandbox and none of the effect.
Examples
Section titled “Examples”Allowed
Section titled “Allowed”Serving an uploaded HTML preview with scripts off and an opaque origin:
Content-Security-Policy: sandbox; default-src 'none'Blocked
Section titled “Blocked”Under a bare sandbox, every one of these is refused:
<script> init();</script><form action="/submit" method="post">…</form><a href="https://example.com" target="_blank">Open</a>Browser support
Section titled “Browser support”- Widely available across browsers since November 2016.
- Not supported in
<meta>elements or inContent-Security-Policy-Report-Only. A report-only rollout will tell you nothing about what this directive would break.
In a HeaderHawk report
Section titled “In a HeaderHawk report”sandboxproduces no violation reports, so it never appears as a directive in HeaderHawk.- The directive is ignored in report-only policies, so the usual way of finding out what a directive would break does not work here. Test it on a staging response in enforce mode instead.
- In enforce mode a sandbox restriction surfaces as a console error rather than as the kind of resource-blocked report that reaches a reporting endpoint.
- HeaderHawk’s normalizer does recognise
sandboxas a directive name, so a report naming it would be filed undersandboxrather than underdefault-src- but no browser sends one, so the facet stays empty.
Related directives
Section titled “Related directives”Getting reports for this directive
Section titled “Getting reports for this directive”Point your policy’s report-uri at your site’s HeaderHawk endpoint and the violations above arrive in the dashboard, grouped as described. The Quick Start sets that up in five minutes, and the integration guides cover the header syntax for each platform.