Lesson 14 of 14 · 13m
iframes, sandbox, and Clickjacking
The sandbox attribute's capability tokens, the allow-same-origin plus allow-scripts escape, frame-ancestors as the real anti-framing control, and COOP/COEP isolation.
sandbox: downgrade the framed document
An iframe is a nested browsing context running someone else's document inside your page's real estate. The sandbox attribute decides how dangerous that document is: with no tokens, the framed page gets a unique opaque origin — no cookies, no storage, no DOM reach into the parent — and its scripting, forms, popups, downloads, and top navigation are all blocked.
Each token re-enables a capability: allow-scripts, allow-same-origin, allow-forms, allow-popups, allow-top-navigation, allow-top-navigation-by-user-activation, allow-modals, allow-downloads, allow-pointer-lock. The -by-user-activation variant gates top navigation behind a real click — a fit for payment and login widgets. The combination that bites people:
<iframe sandbox="allow-scripts allow-same-origin" src="/untrusted.html"></iframe>For a same-origin frame this pair is a self-own. allow-same-origin keeps the document in your origin; allow-scripts lets it run — and a same-origin scripted frame can reach parent.document, remove its own sandbox attribute, and reload unrestricted. You built a cage the prisoner can unlock. For untrusted same-origin content, allow-scripts without allow-same-origin: JS runs, but the opaque origin means the same-origin policy walls it off from your DOM and credentials.
srcdoc frames parse a full inline document — <iframe srcdoc="..."> — and inherit the embedding origin, so the same token logic applies. A CSP sandbox directive on a response sandboxes your own document — rare, but it exists as a self-imposed limit. On the introspection side, location.ancestorOrigins tells a framed document exactly which origins embedded it — supported in Chromium for years and shipped in Firefox 148 (February 2026) — so a page that consents to being embedded can enforce its own partner list in script, in addition to relying on frame-ancestors at the header.
Clickjacking: your page as the attacker's UI
UI redress is the inverse embedding: the attacker iframes your page, transparent or cropped, over a decoy. The victim clicks the decoy's "play video"; the click lands on your "transfer" button. Jeremiah Grossman and Robert Hansen made the class public in 2008 — the canonical demo was hijacking Adobe Flash's settings manager to enable the victim's webcam — and it never stopped working, because the web composes by default.
The defense is a response header, not JavaScript. CSP's frame-ancestors directive lists who may embed you: frame-ancestors 'none' for bank-shaped surfaces, 'self' or a partner list for embeddables. It replaced X-Frame-Options (DENY/SAMEORIGIN; ALLOW-FROM was dropped) — XFO still works and sending both is fine, but frame-ancestors is the directive that supports real host lists. JS framebusting — if (top !== self) top.location = self.location — is cosmetic: the attacker iframes you inside sandbox without allow-top-navigation, your bust script throws on the navigation attempt, and your page renders anyway inside their overlay.
COOP, COEP: isolating your own window
Two newer headers isolate your page from attacker-controlled windows rather than attacker content:
Cross-Origin-Opener-Policy: same-originejects your page from any browsing-context group shared with cross-origin openers —window.openeris severed, and cross-origin windows cannot script your handle. It also closes the class of tab-nabbing and opener-based leaks lesson 13 skirted.Cross-Origin-Embedder-Policy: require-corprequires every subresource to opt in viaCross-Origin-Resource-Policyor CORS. Both together yieldcrossOriginIsolated, which unlocksSharedArrayBufferand high-resolution timers — gated behind isolation since the Spectre mitigations (Chrome ~91, 2021). If you do not need SAB or precise timers, COOP alone is cheap and useful; COEP has real adoption cost because every third-party resource must cooperate.
What to actually do
Untrusted embeds get sandbox="allow-scripts" and nothing else; never pair it with allow-same-origin on same-origin content. Every sensitive response ships frame-ancestors (and XFO for old engines). Treat framebusting scripts as decoration. Add Cross-Origin-Opener-Policy: same-origin where the app tolerates it — it severs the last casual cross-window channel the sandbox does not cover.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
They Got Root on a Fully Patched Ivanti VPN and the Integrity Checker Said Everything Was Fine
Volexity caught an attacker chaining zero-days into unauthenticated root on an Ivanti Connect Secure appliance running the latest build. The payload never touched disk, commands rode in over the same HTTPS requests as the exploit, and Ivanti's Integrity Checker reported no modifications.
Gitea Shipped 21 CVEs in One Release and Eleven of Them Are the Same Bug
Gitea 28.3.0 landed November 1 with twenty-one CVE fixes. Read the list and a pattern jumps out: more than half are the same failure repeated across different route handlers, where a token scoped to public data gets handed private data anyway. That's not twenty-one mistakes.
php2shell: The PHP Bug That Fires Before Your Code Runs
Two critical PHP flaws landed October 21 and were in CISA's exploited-vulnerabilities catalog five days later. The 9.2 score isn't the part that should bother you. It's where the bug lives — it goes off while PHP is still assembling $_POST, before a single line of your application has run.
A Certificate Authority's Private Keys Were the Numbers 4, 56 and 66
Eight eMudhra intermediate CA keys turned out to be recoverable from their own public certificates. Not stolen — computable, because the key generation produced almost no entropy. A researcher pulled all eight in under a second and signed a message with each one to prove it.