Prevent Clickjacking with Frame Policies and Protected Actions
Clickjacking tricks users into clicking controls hidden inside a framed page. Use frame-ancestors to restrict embedding, and protect sensitive actions with server-side checks because frame headers do not stop every UI-redress variant.
How the attack redirects a click
An attacker can place a transparent iframe containing a signed-in site beneath a decoy button. The user thinks they are clicking the decoy, while the browser sends the click to a real control such as changing a sharing setting. The attack changes the visual context; it does not need to steal the site's code. Restricting framing is the primary defense, while authorization and reauthentication limit the impact. MDN: Clickjacking
Choose an embedding policy
Send a Content-Security-Policy HTTP response header with frame-ancestors. Use 'none' to prohibit framing, 'self' for same-origin parents, or list only required partner origins. This directive does not inherit from default-src; it must be sent as an HTTP header, not a meta element. Every ancestor frame must be allowed. X-Frame-Options: DENY or SAMEORIGIN can supplement CSP for older browsers, but ALLOW-FROM is obsolete and less flexible. Test any legitimate embed before blocking it. W3C CSP Level 3, MDN: X-Frame-Options
Treat cookies and sensitive actions as additional controls
SameSite=Lax or Strict can keep session cookies out of some cross-site iframe requests, but it does not prevent framing and can affect authentication flows. DoubleClickjacking can exploit a window or tab transition and is not necessarily stopped by frame headers. For payments, account deletion, or permission changes, verify the user and authorization on the server; require recent authentication or a clear confirmation when appropriate. A disabled button is not a substitute for server checks. OWASP Clickjacking Defense
Deploy and verify
Inventory pages that genuinely need embedding. Set the narrowest frame-ancestors policy at the application or edge, then inspect the final HTML response with curl -I https://example.com/account. Confirm the header is present on the final response (including after redirects), not only in HTML or default-src. Test allowed and disallowed parents in a browser and inspect its console and network panel for blocked frames or overwritten headers. If a legitimate embed breaks, check all ancestor origins and proxy/CDN header merging; allow only the required origins and retain server-side checks. Server configuration syntax varies by product.
Sources: OWASP, MDN Clickjacking, W3C CSP3, MDN X-Frame-Options.