Clickjacking and UI Redress Attacks
What you'll learn: How attackers trick users into clicking hidden elements by overlaying malicious content on legitimate web pages.
The Core Idea
Clickjacking (also called a "UI redress attack") is a deceptive technique where an attacker tricks users into clicking on something different from what they perceive. The attacker overlays or embeds an invisible or disguised iframe containing a legitimate site over their malicious page. When users think they're clicking on harmless content (like a play button or "Click here to win" link), they're actually clicking on hidden elements from the legitimate site—potentially authorizing transactions, changing settings, or granting permissions without realizing it.
How It Works
Imagine a transparent glass pane placed over a keyboard. You see the keyboard, but when you try to press keys, you're actually pressing buttons on a hidden device behind the glass. That's clickjacking.
The attacker creates a page with:
- Enticing visible content (fake buttons, games, etc.)
- An invisible iframe positioned over that content, loading a legitimate target site
- The iframe styled with CSS opacity set to zero or very small dimensions
When the victim clicks what appears to be the attacker's button, they're actually clicking elements in the hidden iframe from the trusted site—like a "Delete Account" button or "Grant Permissions" link.
Defense: X-Frame-Options and CSP
Modern defenses prevent pages from being embedded in iframes on other domains:
- The
X-Frame-OptionsHTTP header can be set toDENYorSAMEORIGIN - Content Security Policy's
frame-ancestorsdirective provides finer control - JavaScript frame-busting code (though less reliable)
Key Takeaway: Clickjacking exploits visual deception by hiding legitimate clickable elements beneath malicious overlays, tricking users into performing unintended actions; defend by preventing your site from being framed using HTTP headers like X-Frame-Options.