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.
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
Code-driven AI illustrations are more useful than images from dedicated image models
Code-driven AI illustrations let designers edit assets directly in code, saving time on iteration and ensuring consistency, which is a game-changer for teams that need rapid, reusable visual content.
A hierarchical note-taking app for building large personal knowledge bases
Trilium lets users build and navigate massive personal knowledge bases without duplicating content, saving time on organization and retrieval.
Desktop apps in Go with native UI or web frontend
Go developers can now ship cross-platform desktop and mobile apps in a single small binary without cgo or heavy runtimes, cutting build complexity and deployment size.
OpenBitFun: an agent workspace with four harness modes and phone remote control
OpenBitFun lets agents run on any machine and be controlled from a phone, eliminating the need to choose between local power and remote access, saving developers time switching contexts.
Intel One Mono: a monospaced font designed with low-vision developers
Developers with low vision or eye fatigue can read code more clearly, reducing errors and improving productivity.