Chapter 68: Preventing XSS & Clickjacking

Defending Against Clickjacking: frame-ancestors vs X-Frame-Options

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

LEARNING OBJECTIVES
  • Implement the CSP Level 3 frame-ancestors directive ('none', 'self', <source-list>).
  • Understand the legacy X-Frame-Options response header (DENY, SAMEORIGIN).
  • Explain why frame-ancestors is superior to X-Frame-Options (supports multi-domain whitelists and path filtering).
  • Prevent framing attacks while allowing trusted partner embed integrations.
🎬 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.

Security Header Comparison

# Modern W3C Standard (CSP Level 3)
Content-Security-Policy: frame-ancestors 'self' https://trusted-partner.com https://checkout.example.com;

# Legacy Fallback (Only supports DENY or SAMEORIGIN; fails if you have multiple partners)
X-Frame-Options: SAMEORIGIN

📌 Key Takeaways

  • If both headers are present, modern browsers prioritize CSP frame-ancestors and ignore X-Frame-Options.
  • Set frame-ancestors 'none' on all pages with sensitive user forms or authenticated sessions.
  • --

❓ Knowledge Check

1. Which of the following is correct?

2. Which of the following is correct?

🏋️ Study Exercise

Task: Review the http example above. Identify the key directives and their purpose, then try writing your own version from memory.

# Modern W3C Standard (CSP Level 3) Content-Security-Policy: frame-ancestors 'self' https://trusted-partner.com https://checkout.example.com; # Legacy Fallback (Only supports DENY or SAMEORIGIN; fails if you have multiple partners) X-Frame-Options: SAMEORIGIN