1. Clickjacking Attack Mechanics & Framing Risks

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

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.
# 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

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
GET /account/transfer HTTP/1.1
Host: yoursite.comResponse with no frame protection
HTTP/1.1 200 OK
# no Content-Security-Policy: frame-ancestors
# no X-Frame-OptionsThe 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
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.
WeSecureX modules for this topic
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
Related Guides
Continue exploring related technical architecture and defensive guides
security headers · CSP
Complete Guide to HTTP Security Headers (CSP, HSTS & More)
Master the essential HTTP security headers: CSP Level 3, HSTS preloading, clickjacking defense, MIME sniffing prevention, and production server configurations.
CSP · XSS
Content Security Policy (CSP): Deploy Without Breaking Production
A practical CSP rollout: Report-Only -> enforce, nonces over unsafe-inline, and violation monitoring that doesn't brick marketing tags overnight.
XSS · web security
Cross-Site Scripting (XSS): Stored, Reflected & DOM-Based
Exhaustive guide to Cross-Site Scripting: DOM sources and sinks, context-aware output encoding, framework security, and Content Security Policy (CSP Level 3).