Clickjacking
| Class | Security misconfiguration |
|---|---|
| Also known as | UI redress attack; tapjacking (on touch screens) |
| CWE | CWE-1021: Improper Restriction of Rendered UI Layers or Frames |
| OWASP Top 10 | A02:2025 Security Misconfiguration |
| Typical severity | Medium; higher where one click moves money or grants access |
| Affects | Pages that change something with one click and send no frame restriction header |
A visitor on a prize page sees a button labelled "Click here for a free kitten!". Under it, at zero opacity, sits an iframe holding the visitor's bank, already signed in, and the bank's "Transfer all your money?" button is placed exactly where the kitten button appears. The click goes to the bank.1 In clickjacking, one site loads another inside a hidden or disguised frame so that a visitor's clicks land on controls they cannot see. The weakness sits with the framed site, which does not tell the browser that other sites may not embed it.2 The same trick on a phone, with taps and overlapping windows, is called tapjacking.2
How the overlay works
The attacking page needs two pieces: an iframe that loads the target page, and a decoy element to aim the click. The CSS hides the frame and moves the decoy over the target's button:
<button id="fake-button">Click here for a free kitten!</button>
<iframe width="800" height="200" src="https://my-bank.example.com"></iframe>
<style>
iframe { opacity: 0; }
#fake-button { position: absolute; top: 185px; left: 90px; }
</style>The invisible frame is still on top, so it receives the click. If the visitor is signed in, the click happens inside the bank's own session, so the request it triggers carries the visitor's real credentials, and the server has no reason to refuse it.1 The defence that addresses the cause is to stop the page from being framed at all.
Frame restriction headers
Two response headers tell the browser who may embed a page. The newer one is the frame-ancestors directive of the Content Security Policy. It lists which parent pages may load the document in a <frame>, <iframe>, <object> or <embed>, and 'none' blocks all of them.3 The older one, X-Frame-Options, has two working values: DENY blocks every frame, and SAMEORIGIN allows a frame only when every ancestor frame has the page's own origin.4
| Header and value | Who may frame the page |
|---|---|
Content-Security-Policy: frame-ancestors 'none' | Nobody |
Content-Security-Policy: frame-ancestors 'self' https://www.example.org | The page's own origin and the one listed site |
X-Frame-Options: DENY | Nobody, including the same origin |
X-Frame-Options: SAMEORIGIN | Pages on the same origin |
X-Frame-Options: ALLOW-FROM ... | Anyone: modern browsers ignore the whole header |
| Neither header | Anyone |
When a browser that supports frame-ancestors receives both headers, it follows the CSP directive and ignores X-Frame-Options.1 Some old browsers, such as Chrome 40 and Firefox 35, did the reverse, which is one reason sites send both.5
Several mistakes leave a page frameable while looking protected. Neither header works inside a <meta> tag; a browser applies them only as real response headers.43 A policy of default-src 'none' does not cover framing, because frame-ancestors has no fallback to default-src.3 A wildcard such as https://*.example.com matches subdomains but not example.com itself.5 A proxy or CDN that strips headers on the way out takes the protection with them.5
Cookies and scripts
A session cookie set with SameSite=Lax or Strict is left off requests from a frame on another site, so the server treats a click inside the frame as coming from a visitor who is not signed in.1 The cookie setting is a partial defence. It does not stop the page being framed, an attacker's sibling subdomain counts as the same site while being a different origin, and a control that needs no sign-in stays exposed.5 The rules are in Cookie attributes.
An older defence is frame-busting JavaScript, which checks whether the page is the top window. The common one-line form, if (top != self) top.location.href = self.location.href, can be defeated in several published ways, one of them a second frame wrapped around the first. The pattern still in use hides the whole body with a style rule and removes that rule only when self === top, so a framed copy keeps its body hidden.5 It is a fallback for browsers without header support.
DoubleClickjacking
In December 2024 the researcher Paulos Yibelo published a variant that uses no frame. The attacking page opens a second window that asks for a double-click, and that window points its opener back to a sensitive page, such as an OAuth consent screen. The first press, caught on mousedown, closes the top window; the second press lands on the newly exposed Allow button.6 Since the target is a top-level window, frame headers and SameSite cookies do not stop it. On consent, payment and account security screens, the defence moves to the server: the user reviews the action's details and completes a separate authorization step that the server checks, because one more confirmation button can be hijacked the same way.5
History
Robert Hansen and Jeremiah Grossman had planned a talk on the technique for the AppSec 2008 conference in New York in late September 2008, and cancelled it. The cancellation drew attention to the name, and in early October a blogger published a proof of concept that used Adobe Flash.7 Flash Player's dialog for granting a site the camera and microphone was among the affected products.7 Adobe rated the issue critical in advisory APSA08-08 on 7 October 2008 and fixed it in Flash Player 10.0.12.36, with 9.0.151.0 for users who could not upgrade.8
Setting the headers
Unless a page has to appear inside another site, send both headers on every HTML response:
Content-Security-Policy: frame-ancestors 'none'
X-Frame-Options: DENYIn nginx, the line add_header X-Frame-Options DENY always; sets the header.4 The Express package Helmet sends frame-ancestors 'self' in its default policy and X-Frame-Options: SAMEORIGIN, which allows framing only by the same origin.9 Django turns on XFrameOptionsMiddleware in every new project and sends DENY by default; the X_FRAME_OPTIONS setting changes the value, and the @xframe_options_exempt decorator allows one view to be framed.10 Configuration for Next.js, Vercel and other hosts is in HTTP security headers.
A page meant to be embedded, such as a widget or a payment form shown on partner sites, lists those parents in frame-ancestors instead of using 'none'. Where a frameable page has a destructive action, a confirmation dialog helps, though a browser may suppress it inside a frame with the sandbox attribute, in which case window.confirm() returns false and the action must not run.5
In SecFlash
A page that another site can load in a frame shows as SF-SEC-105 (Page can be framed) on the Security page. The ZAP scan reports a missing frame restriction header as SF-SEC-622.
See also
- HTTP security headers
- Content Security Policy
- Cross-site request forgery
- Cookie attributes
- Same-origin policy
- OAuth 2.0
- Category: Security misconfiguration
References
- a b c d "Clickjacking". MDN Web Docs. Mozilla (last modified 2 February 2026).
- a b "CWE-1021: Improper Restriction of Rendered UI Layers or Frames". Common Weakness Enumeration (version 5.0). MITRE.
- a b c "CSP: frame-ancestors". MDN Web Docs. Mozilla.
- a b c "X-Frame-Options header". MDN Web Docs. Mozilla.
- a b c d e f g "Clickjacking Defense Cheat Sheet". OWASP Cheat Sheet Series.
- back Yibelo, Paulos (December 2024). "DoubleClickjacking: A New Era of UI Redressing". Author's blog.
- a b Leyden, John (16 October 2008). "Adobe patch thwarts clickjacking attack". The Register.
- back Adobe (7 October 2008, revised 5 November 2008). "Flash Player workaround available for 'Clickjacking' issue (APSA08-08)". Adobe Security Advisories.
- back "Helmet". Helmet documentation.
- back "Clickjacking Protection". Django documentation (5.2).
External links
- Content Security Policy: frame-ancestors, W3C specification