Clickjacking (UI Redress Attack)
1. Definition
Clickjacking (also known as âUI Redress Attackâ) is a malicious technique where an attacker tricks a user into clicking on something different from what the user perceives. The attacker loads a target website in a transparent iframe and overlays it on top of a decoy page, causing clicks on the visible page to actually register on the hidden target.
This allows attackers to hijack clicks intended for the visible page and redirect them to perform unintended actions on another site where the user is authenticated.
2. Technical Explanation
The attack exploits the browserâs ability to layer web content using CSS positioning and opacity.
Attack Structure:
<!-- Attacker's Page -->
<style>
iframe {
position: absolute;
top: 0;
left: 0;
width: 500px;
height: 200px;
opacity: 0; /* Invisible */
z-index: 2; /* On top */
}
.decoy-button {
position: absolute;
top: 50px;
left: 100px;
z-index: 1; /* Below iframe */
}
</style>
<button class="decoy-button">Click to Win a Prize!</button>
<iframe src="https://bank.com/transfer?to=attacker&amount=1000"></iframe>When the user clicks the âWin a Prizeâ button, they actually click the invisible âTransferâ button on bank.com.
Key Conditions:
- Target site allows embedding in iframes.
- User is authenticated on the target site.
- The target action can be triggered with a single click.
3. Attack Flow
sequenceDiagram
participant Victim
participant AttackerPage as Attacker Page
participant TargetSite as Target Site in iframe
Victim->>AttackerPage: Visits malicious page
Note over AttackerPage: Page loads target site<br/>in invisible iframe
AttackerPage-->>Victim: Shows decoy content<br/>Win a Prize button
Victim->>AttackerPage: Clicks decoy button
Note over Victim,TargetSite: Click passes through<br/>to invisible iframe
Victim->>TargetSite: Actual click on Delete Account button
TargetSite-->>TargetSite: Action executed<br/>Account deleted
TargetSite-->>Victim: Confirmation page in hidden iframe4. Real-World Case Study: Twitter Worm (2009)
Target: Twitter âFollowâ button functionality. Vulnerability Class: Classic Clickjacking / UI Redress.
The Vulnerability: In 2009, Twitter did not implement frame-busting or X-Frame-Options headers. Any page could embed Twitter in an iframe.
The Attack:
- Attackers created pages with enticing content like âDonât Click Thisâ or fake Flash player buttons.
- Behind these buttons was an invisible iframe containing Twitterâs Follow button for a specific account.
- When users clicked, they unknowingly followed the attackerâs Twitter account.
- The followed account then sent Direct Messages with links to the same malicious page.
Impact: The worm spread virally, with some accounts gaining hundreds of thousands of followers in hours. It demonstrated how clickjacking could enable self-propagating attacks on social platforms.
5. Detailed Defense Strategies
A. X-Frame-Options Header
The classic defense against framing attacks.
X-Frame-Options: DENYDENY: Page cannot be displayed in any frame.SAMEORIGIN: Page can only be framed by pages from the same origin.
Note: This header is now considered legacy. Use CSP frame-ancestors instead.
B. Content-Security-Policy: frame-ancestors
The modern and more flexible approach.
Content-Security-Policy: frame-ancestors 'self' https://trusted-partner.com'none': Equivalent to X-Frame-Options: DENY.'self': Only same-origin can frame.- Specific domains: Allowlist trusted embedders.
C. JavaScript Frame Busting (Fallback)
A legacy technique for older browsers that do not support headers.
// Basic frame buster
if (top !== self) {
top.location = self.location;
}Warning: This can be bypassed with sandbox attribute:
<iframe src="target.com" sandbox="allow-scripts"></iframe>Modern defense should rely on HTTP headers, not JavaScript.
D. SameSite Cookies
Even if framed, prevent session cookies from being sent in cross-site iframe contexts.
Set-Cookie: session=abc123; SameSite=Strict; SecureThis breaks the attack because the target site will not recognize the user as authenticated.
E. User Interaction Confirmation
For critical actions, require additional confirmation:
- Re-authentication: Require password for sensitive operations.
- CAPTCHA: Proves human intent.
- Two-step actions: Require explicit confirmation dialog.
