Beginner·14 min read·Updated 2026-10-15

Clickjacking Prevention: Frame Busting, CSP frame-ancestors & UX Traps

Original WeSecureX guide for authorized testing of sites you own. Linked Sources are citations for verification - not copied articles. Ads are not served on this page.

Clickjacking (also known as a UI Redressing Attack - CWE-1021) is a malicious technique where an attacker tricks a user into clicking transparent or hidden user interface elements on a legitimate website while the user believes they are clicking an entirely different webpage. By embedding your authenticated web application inside an invisible `<iframe>` overlaid on a decoy game or phishing page, attackers hijack user clicks to perform unauthorized actions - such as executing financial transfers, changing account passwords, or granting OAuth permissions. This guide outlines modern header defenses, CSP `frame-ancestors` directives, and audit verification with the [WeSecureX Security Scanner](/scanner), [Security Headers Checker](/tools/security-headers-checker), and [CORS Checker](/tools/cors-checker). Learn more in our blog on [Why Security Headers Are Your First Line of Defense](/blog/why-security-headers-are-your-first-line-of-defense-and-how-to-implement-them).

Quick Answer

Enforce Content-Security-Policy: frame-ancestors 'none' (or an explicit allowlist) alongside X-Frame-Options: DENY to prevent browsers from embedding your pages inside third-party iframes.

Key Takeaways
  • Clickjacking tricks users into executing hidden UI actions via transparent iframes.
  • CSP `frame-ancestors` is the authoritative modern defense against UI redressing.
  • Legacy JavaScript frame-busting code is easily bypassed using sandboxed iframes.
  • Default to disallowing framing across all application routes.
Visual Diagram · UI Redressing Clickjacking Overlay & CSP Defense Flow
1

1. Malicious Decoy Page

Attacker hosts a decoy website containing attractive click buttons ('Claim Free Prize').

2

2. Transparent Iframe

Attacker embeds target application (`https://bank.com/transfer`) inside a 0% opacity iframe directly over the button.

3

3. Header Policy Check

Browser fetches target page, inspects `frame-ancestors 'none'`, and blocks iframe rendering immediately.

4

4. Click Hijack Prevented

Because the iframe rendering is aborted, the user click does not execute actions on the target application.

ShareShare on XLinkedIn

1. Clickjacking Attack Mechanics & Framing Risks

WeSecureX Security Headers Checker auditing X-Frame-Options and CSP frame-ancestors
WeSecureX Security Headers Checker auditing X-Frame-Options and CSP frame-ancestorsWeSecureX Platform View

Clickjacking attacks rely on clever CSS opacity manipulation (opacity: 0), absolute coordinate positioning (z-index: 9999), and pointer event capturing. An attacker creates an alluring decoy website (such as an online survey or prize giveaway game). Embedded invisibly above the game's "Click to Play" button is a transparent iframe displaying your application's administrative settings or payment authorization view (https://bank.example.com/transfer).

When an authenticated victim clicks the visible decoy button, their click is intercepted by the invisible iframe directly above it. Because the victim is logged into the legitimate service, their browser automatically sends ambient session cookies with the iframe click, authorizing the hidden action (e.g., adding an attacker's email to the admin team or transferring funds) without the user's knowledge.

Historically, developers attempted to defend against framing using client-side JavaScript "frame-busting" scripts (e.g., if (top !== self) top.location = self.location). However, modern browsers support the HTML5 sandbox attribute (<iframe sandbox="allow-forms allow-scripts">). This attribute explicitly blocks top-level window redirection while still allowing form submissions, completely neutralizing JavaScript frame-busting routines. The only foolproof defense is enforcing HTTP response headers. Audit your domain headers today using the WeSecureX Security Headers Checker.

2. Modern Header Protections: CSP frame-ancestors & X-Frame-Options

WeSecureX Website Scanner verifying HTTP response headers across all routes
WeSecureX Website Scanner verifying HTTP response headers across all routesWeSecureX Platform View

The authoritative defense against clickjacking is enforcing HTTP response headers that instruct visitor browsers to disallow framing directly at the network boundary.

1. Content-Security-Policy: frame-ancestors 'none' (W3C Standard): The CSP Level 2 and Level 3 frame-ancestors directive specifies exactly which parent origins are authorized to embed the current webpage inside <frame>, <iframe>, <embed>, <object>, or <applet> elements. Setting frame-ancestors 'none' completely prohibits all framing, while specifying origins (frame-ancestors 'self' https://trusted-partner.com) permits embedding strictly by authorized partner portals.

2. X-Frame-Options: DENY (Legacy Fallback): While frame-ancestors is supported by all modern browsers, legacy user agents require the X-Frame-Options response header. Setting X-Frame-Options: DENY blocks all framing, while SAMEORIGIN permits framing strictly within the identical origin. Whenever both headers are present, modern browsers give precedence to CSP frame-ancestors. Configure these headers in your reverse proxy as shown below, and verify live response headers with our CORS Checker Tool.

nginx
# Production Nginx Clickjacking Prevention Header Configuration
# Disallow framing globally across all routes
add_header Content-Security-Policy "frame-ancestors 'none';" always;
add_header X-Frame-Options "DENY" always;

# Or allow specific trusted parent origins for embedded widgets:
# add_header Content-Security-Policy "frame-ancestors 'self' https://trusted-partner.com;" always;

3. Handling Intentional Frame Embedding Safely

WeSecureX Free Tools Directory showing CORS and Security Header Checkers
WeSecureX Free Tools Directory showing CORS and Security Header CheckersWeSecureX Platform View

Many web applications provide embeddable UI components - such as payment checkout modals, interactive customer support chat widgets, or embedded video players - that must legitimately be framed by third-party partner websites. In these scenarios, blanket frame-ancestors 'none' directives would break core business functionality.

To safely support intentional embedding, isolate embeddable widgets on a dedicated subdomain (e.g., embed.example.com or widgets.example.com). On widget routes, declare an explicit allowlist in your CSP header: Content-Security-Policy: frame-ancestors 'self' https://partner.com https://checkout.store.com. Furthermore, configure cookies used by the embedded widget with SameSite=None; Secure, while keeping sensitive authentication cookies for your primary web app strictly set to SameSite=Strict.

Never permit framing on administrative portals, user settings pages, or password reset screens. Verify that all sensitive routes enforce framing protection by scanning your web properties with the WeSecureX Security Scanner.

Apply it with WeSecureX

WeSecureX requests each page and reads the framing controls in the response headers. A clickjacking finding is raised when a sensitive page can be embedded in a cross-origin frame.

Header check on a page you own

http
GET /account/transfer HTTP/1.1
Host: yoursite.com

Response with no frame protection

http
HTTP/1.1 200 OK
# no Content-Security-Policy: frame-ancestors
# no X-Frame-Options
What the finding shows

The finding lists the page and the missing directive. Without `frame-ancestors`, an attacker page can overlay your transfer form and harvest clicks.

Fix: send frame-ancestors

http
Content-Security-Policy: frame-ancestors 'self'

After the rescan

Rescan the same page. When the header is present and scoped to `'self'`, WeSecureX sees the framing control and closes the finding.

Checks that belong with this topic

  • Include Content-Security-Policy: frame-ancestors 'none' on all authenticated pages.
  • Set X-Frame-Options: DENY as a fallback header for legacy browsers.
  • Disallow framing on administrative consoles and sensitive settings routes.
  • Do not rely on legacy JavaScript frame-busting scripts.
  • Audit HTTP security headers continuously using the [WeSecureX Security Scanner](/scanner).

Actionable Checklist

WeSecureX Platform · Scanner Engine

Automated Vulnerability Scanner

Launch targeted or full-domain security audits to detect OWASP Top 10 vulnerabilities automatically.

Includes: OWASP Top 10 automated test suites · Real-time severity scoring (CVSS v3.1) · Instant remediation code snippets

Frequently Asked Questions

`X-Frame-Options` is a legacy single-origin header (`DENY` or `SAMEORIGIN`). CSP `frame-ancestors` is the modern W3C standard supporting multiple domain allowlists and granular frame control.

SameSite cookies prevent cross-site GET/POST cookie transmission, which mitigates CSRF, but they do not prevent an iframe from displaying a logged-in session if the user navigates directly inside the iframe.

Attackers can embed your page inside a sandboxed iframe with `sandbox="allow-scripts allow-forms"`, which prevents your JavaScript frame-busting script from redirecting the top-level window.

Yes. Use `Content-Security-Policy: frame-ancestors 'self' https://partner1.com https://partner2.com` to grant embedding permissions strictly to trusted origins.

Audit your domain response headers using the [WeSecureX Security Scanner](/scanner) and [Security Headers Checker](/tools/security-headers-checker) to verify CSP `frame-ancestors` enforcement.

Authoritative Sources & References

  • OWASP - Clickjacking Defense Cheat SheetOWASP (official)
    View Source

Continue exploring related technical architecture and defensive guides

Security Research & Engineering Articles

All articles