Clickjacking (Clickjacking)
The Essentials
- Tricks users into clicking hidden elements by overlaying transparent iframes
- Can capture clicks on buttons, links, and form submissions
- Prevented by X-Frame-Options or CSP frame-ancestors directive
- Also called UI redress attack
- Particularly dangerous for one-click actions like payments or permission grants
Why You Should Care About Clickjacking
Clickjacking can trick users into performing actions they did not intend - liking social media posts, confirming financial transactions, changing account settings, or granting permissions. The attack is effective because the user sees a completely different page from what they are actually clicking on.
The primary defenses are the X-Frame-Options header (set to DENY or SAMEORIGIN) and the CSP frame-ancestors directive (set to 'none' or 'self'). Both prevent your pages from being embedded in frames on other sites, which is the prerequisite for clickjacking attacks.
JavaScript frame-busting code (checking if window.top === window.self) was an older defense but is unreliable because it can be circumvented. HTTP headers are the definitive solution because they are enforced by the browser before any page code runs.
Testing Your Configuration
A security audit checks for X-Frame-Options and CSP frame-ancestors headers. Both should be set to prevent unauthorized framing. If your site never needs to be embedded in iframes, use the strictest settings (DENY / 'none').