Chapter 68: Preventing XSS & Clickjacking

What is Clickjacking / UI Redressing?

**Part 14: Security & Best Practices** — Chapter 68: Preventing XSS & Clickjacking in HTML

LEARNING OBJECTIVES
  • Understand the mechanics of Clickjacking (UI Redressing) attacks.
  • Learn how transparent <iframe> overlays trick authenticated users into clicking sensitive buttons.
  • Examine real-world Clickjacking attack vectors: Likejacking, 1-click purchases, account deletions.
  • Master historical JS frame-busting scripts vs modern browser-level HTTP defenses.
🎬 INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
🌐
1. Input
Directives & Tags
⚙️
2. Parse
Tokenizer & AST
🌳
3. Layout
Box Model & Flow
🎨
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

📖 The Anatomy of a Clickjacking Attack

An attacker builds a game or survey page with an enticing button ("Click here to win a free iPhone!").

In the background, the attacker embeds your banking or social media settings page inside an <iframe> positioned directly above the button, set to CSS opacity: 0.0001 (invisible). When the user clicks the "Win iPhone" button, their physical click lands directly on the invisible "Transfer All Funds" or "Delete Account" button inside the authenticated iframe!

+--------------------------------------------------------------+
| ATTACKER WEBPAGE (https://evil.com)                          |
|                                                              |
|   Visible UI:   [ 🎁 Click to Claim $1,000 Prize! ]          |
|                                                              |
|   Invisible Iframe (opacity: 0, z-index: 9999):              |
|     https://bank.com/settings/transfer-all-funds             |
|     [ 💸 Confirm Transfer ] <--- Physical click lands here! 🚨|
+--------------------------------------------------------------+

📌 Key Takeaways

  • Clickjacking exploits a logged-in user's authenticated session by masking sensitive action buttons under transparent iframe layers.
  • JavaScript-based frame-busting scripts (if (top !== self) ...) can be bypassed by sandbox="allow-forms" and should never be used instead of HTTP headers.
  • --

❓ Knowledge Check

1. Which of the following is correct?

2. Which of the following is correct?