Can JavaScript Escape a CSP Meta Tag Inside an Iframe?

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Developers can rely on meta-tag CSP in sandboxed iframes as tamper-proof even against untrusted scripts, avoiding a separate hosting domain.

Read this as

Simon Willison tested whether JavaScript running inside a sandboxed iframe can bypass a security rule called a Content Security Policy when that rule is set with a meta tag in the page's code. He found it cannot: scripts can't remove, edit, or escape the policy, even by replacing the page, and it holds in both Chromium and Firefox. This matters to people building apps that display untrusted code, like his own attempt to recreate Claude Artifacts. No product or benchmark figures are given; it's a hands-on testing write-up.

Willison investigated whether a Content Security Policy injected via a meta tag could be trusted to confine untrusted JavaScript inside a sandboxed iframe, without paying for or operating a separate domain to host content. His conclusion: yes, the policy is enforced at parse time and survives script manipulation and even navigation to a data: URI in Chromium and Firefox. Teams building platforms that run third-party or generated code, such as Artifact-style features, can drop a hosting domain and its cost from the architecture.

A <meta http-equiv="Content-Security-Policy"> tag placed in sandbox="allow-scripts" iframe content is enforced at parse time and cannot be disabled by subsequent JavaScript: removal, mutation, and document.open-style replacement all fail, and the policy persists across navigation to a data: URI. Verified empirically on Chromium and Firefox. Motivated by hosting Artifact-style generated code without a separate domain; performance figures, Safari results, and browser versions are not stated.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

Content Security Policy Claude Artifacts Chromium Firefox Datasette Pyodide

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading