Csp Via Meta Tag Inside Sandboxed Iframes
Sources: 1 • Confidence: Medium • Updated: 2026-04-04 03:48
Key takeaways
- Injecting a <meta http-equiv="Content-Security-Policy"> tag at the top of an iframe document causes that CSP to be enforced for the iframe content.
- A CSP enforced from a top-of-document CSP meta tag remains in effect even if later untrusted JavaScript manipulates that CSP meta tag.
- For content rendered in a sandboxed iframe, one option to apply CSP without hosting the content on a separate domain is to include a Content-Security-Policy meta tag inside the iframe document.
Sections
Csp Via Meta Tag Inside Sandboxed Iframes
- Injecting a <meta http-equiv="Content-Security-Policy"> tag at the top of an iframe document causes that CSP to be enforced for the iframe content.
- A CSP enforced from a top-of-document CSP meta tag remains in effect even if later untrusted JavaScript manipulates that CSP meta tag.
- For content rendered in a sandboxed iframe, one option to apply CSP without hosting the content on a separate domain is to include a Content-Security-Policy meta tag inside the iframe document.
Unknowns
- Do major browsers consistently enforce CSP delivered via <meta http-equiv="Content-Security-Policy"> inside sandboxed iframes across different sandbox attribute configurations?
- What specific CSP directives (and combinations) are required in this setup to block key attacker actions relevant to the intended threat model (e.g., script execution, external loads, network exfiltration)?
- Is the “top-of-document” placement requirement strict (e.g., must be the first element), and what happens if content is injected before the CSP meta tag?
- Does the persistence of the originally enforced CSP after DOM manipulation of the meta tag hold for all subsequent action types (e.g., actions triggered after mutation, dynamic script insertion attempts), and are there any observable edge cases?
- Is there any clear decision-readthrough (operator, product, or investor) implied by this corpus beyond “test and validate CSP-meta behavior in target browsers”?