Clickjacking
Clickjacking tricks a victim into clicking UI elements overlaid on top of the targeted application page.
Material
Clickjacking tricks a victim into clicking an interface element layered on top of the targeted application. The attacker loads the victim app in a transparent frame and overlays their own page with an enticing button on top of it.
How it works
The browser only refuses to render the frame when the application sends protection headers or a CSP policy that restricts embedding. Without either, the attacker's page is free to place an iframe to the victim domain over any content on the page.
A click on the decoy button lands on the control that really exists inside the iframe, the one hidden from the victim. The CSRF token is present inside that frame too, so CSRF protection does not stop this attack.
<div style="position:relative;height:240px;font-family:sans-serif">
<iframe src="https://target.website/account/change-email"
style="position:absolute;top:0;left:0;width:720px;height:260px;
border:0;opacity:0" scrolling="no"></iframe>
<button style="position:absolute;top:120px;left:40px;width:240px;height:48px">
Klaim hadiah Anda
</button>
</div><iframe src="https://target.website/account/change-email?email=attacker@example.com"
style="position:absolute;width:680px;height:220px;border:0;opacity:0"></iframe>
<button style="position:absolute;top:110px;left:60px;width:200px;height:44px">
Perbarui email
</button>Attack forms
- An action button overlay: the victim clicks a button disguised to mimic the original site layout.
- Pre-filled from a URL parameter: the form inside the frame is already filled in, so the victim only has to press one confirmation button.
- A multi-step attack: several frames make the victim complete a sequence of actions that each look ordinary on their own.
- Click-triggered DOM-based XSS: a click on the target element runs a script in the context of the victim application.
- Frame busters backfiring: the framing check sometimes runs too late or is disabled, and the frame still renders.
Prevention
- Send X-Frame-Options with the value DENY or SAMEORIGIN.
- Add Content-Security-Policy: frame-ancestors 'none' or a list of your own origins.
- Apply these headers at the edge or CDN layer, not only at the origin, so they are not missed when traffic is routed through a proxy.
- Make sure pages that display sensitive data, such as a dashboard, carry the same protection.
- Remember that framing protection only blocks embedding from outside; an overlay built inside the page itself is out of reach.
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
X-Frame-Options: DENY
Content-Security-Policy: default-src 'self'; frame-ancestors 'none'
Set-Cookie: session=8f2c19b7e0; HttpOnly; Secure; SameSite=StrictCheck these headers on the response the browser actually receives, not on the documentation. A header written in the docs but stripped by the reverse proxy protects nothing at all.
Labs in this topic
Labs run on a domain separate from this site, so a payload cannot reach your account session.
Labs for this category land in Phase 2. The material is readable now.
Challenges in this category
Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.