CONTROL WHO CAN FRAME YOU

X-Frame-Options missing: how clickjacking works, DENY and SAMEORIGIN versus CSP frame-ancestors, and how to configure and test framing protection

Clickjacking hides your real page inside an invisible frame so a visitor clicks your buttons without knowing it. One response header stops it: X-Frame-Options or the CSP frame-ancestors directive. This guide compares the two, shows how to allow legitimate embedding, gives configurations for common servers, CDNs and frameworks, and explains how to verify the result.

Concept illustration of an ivory ceramic picture frame on a dark surface, its mint-glowing glass pane secured by a small copper latch, while a thin transparent glass overlay carrying a copper decoy button leans aside, unable to slide in front.
Concept illustration

Any web page can load any other web page inside an iframe unless the framed page says otherwise. Most of the time that is harmless. Clickjacking turns it into a trick: another site loads your page in a frame, makes the frame invisible or disguises it, and places a decoy on top, so a visitor who thinks they are clicking a harmless button is really clicking a button on your site, with their own session.

The defence does not live in your page's HTML or JavaScript. It is a response header that tells the browser who may embed the page: the older X-Frame-Options header, or the frame-ancestors directive of Content-Security-Policy. When neither is present, browsers allow any site to frame the page, and an audit reports that clickjacking protection is missing.

This guide explains how clickjacking works, the difference between DENY, SAMEORIGIN and frame-ancestors, how to keep legitimate embeds working, and how to set the header on Nginx, Apache, IIS, CDNs and common frameworks. It ends with tests you can run against your own site and what Sitelemetry checks. All examples use example.com.

Scope of this guide

This guide covers framing protection visible in public HTTP response headers. An automated check reads one response and confirms a header is present; it cannot judge every page, your embedding needs or whether a value works as intended, and it is not a pentest.

1. How clickjacking works and why framing matters

The OWASP description of clickjacking calls it a UI redress attack. The mechanism is simple:

  1. A page on another site embeds your page in an <iframe>.
  2. CSS makes the frame transparent or hides most of it, and positions it so that one of your buttons sits exactly under a decoy, such as a play button or a prize claim.
  3. The visitor clicks the decoy. The browser delivers the click to the topmost element under the pointer, which is your invisible page, so the action happens on your site.

The attack does not steal passwords or read your page; the other site cannot see inside a cross-origin frame. What it borrows is the visitor's click, and sometimes their keystrokes. It matters most on pages where a single click changes something: account and privacy settings, deleting data, approving a payment or a connection, following or sharing, granting an app access, or changing an email address.

Whether the click succeeds also depends on whether the visitor's session travels into the frame. Cookies marked SameSite=Lax or SameSite=Strict are not sent with requests from a cross-site frame, which removes the logged-in state that many attacks depend on. The OWASP Clickjacking Defense Cheat Sheet lists SameSite cookies as defence in depth, not as a replacement: cookies set with SameSite=None, sign-in flows and pages that work without a session remain exposed. The primary control is to tell the browser not to render your page inside frames you did not approve.

Older advice relied on frame-busting JavaScript that checks whether window.top is the page itself. OWASP describes these scripts as a legacy defence: a framing page can use the iframe sandbox attribute to block scripts while still displaying the page. Use headers.

2. X-Frame-Options: DENY, SAMEORIGIN and the obsolete ALLOW-FROM

X-Frame-Options was introduced by browsers and documented in RFC 7034; its processing is now specified in the HTML standard. It applies to <frame>, <iframe>, <embed> and <object>. According to MDN, it has two valid values:

  • DENY: the page cannot be displayed in a frame at all, not even by your own site.
  • SAMEORIGIN: the page can be framed only by pages from the same origin. An origin is scheme, host and port together, so https://www.example.com and https://app.example.com are different origins, and so are http://example.com and https://example.com.

A third value, ALLOW-FROM https://partner.example.net, appears in old tutorials. MDN marks it obsolete: modern browsers that see it ignore the whole header, which leaves the page frameable by anyone. If your configuration contains ALLOW-FROM, replace it with frame-ancestors (section 3).

Three practical rules apply:

  • It must be an HTTP response header. MDN states that setting X-Frame-Options in a <meta http-equiv> element has no effect.
  • Send one value. When a CDN, a reverse proxy and the application each add the header, responses can carry duplicates or conflicting values such as DENY and SAMEORIGIN. Decide which layer owns the header and remove it from the others.
  • It cannot express a list. There is no valid way to allow a specific third-party site with X-Frame-Options. That limitation is why CSP added frame-ancestors.

3. CSP frame-ancestors and which header wins

The frame-ancestors directive of Content Security Policy Level 3 lists the origins allowed to embed the page. It is sent inside the Content-Security-Policy header:

Content-Security-Policy: frame-ancestors 'none'
Content-Security-Policy: frame-ancestors 'self'
Content-Security-Policy: frame-ancestors 'self' https://partner.example.net https://*.example.com

'none' behaves like DENY and 'self' like SAMEORIGIN. Unlike X-Frame-Options, you can name several origins, use a wildcard for subdomains, and the browser checks every ancestor in a chain of nested frames, not only the direct parent. The keywords need their single quotes; frame-ancestors none without quotes is read as a host called none. Directives such as 'unsafe-inline', nonces and hashes do not apply here.

The CSP specification also settles precedence: when a response carries an enforced policy containing frame-ancestors, the browser must ignore X-Frame-Options. Two limits matter in practice. First, frame-ancestors is ignored when the policy is delivered in a <meta> element, as the MDN frame-ancestors page notes. Second, a Content-Security-Policy-Report-Only header never blocks anything; it can tell you what would be blocked, but it does not protect.

PropertyX-Frame-OptionsCSP frame-ancestors
Block all framingDENYframe-ancestors 'none'
Allow own origin onlySAMEORIGINframe-ancestors 'self'
Allow named third-party originsNot possible (ALLOW-FROM is obsolete and ignored)List them: 'self' https://partner.example.net
Wildcard subdomainsNoYes, for example https://*.example.com
Works in a meta elementNoNo
When both are presentIgnored by browsers that support frame-ancestorsTakes precedence when enforced
Report-only modeNot availableReport-Only header reports but never blocks

OWASP's cheat sheet recommends frame-ancestors as the primary control and X-Frame-Options for older browsers. Sending both, with matching intent, costs nothing. To add frame-ancestors to a complete policy, see the Content-Security-Policy examples guide.

4. Choosing a policy without breaking legitimate embeds

Before you set anything, find out where your pages are framed on purpose. Typical cases:

  • your own pages framing each other, such as a CMS preview pane, a page builder or an admin dashboard that shows the live site;
  • another of your own origins, such as app.example.com embedding a help page from www.example.com;
  • partners or customers embedding a widget, a booking form, a map or a video player you host;
  • tools that preview your pages inside their own interface.

Then pick a policy per type of page rather than one compromise for everything:

Page typeSuggested headersReason
Most sites, defaultX-Frame-Options: SAMEORIGIN and frame-ancestors 'self'Keeps your own previews and same-origin frames working
Login, account, payment, adminX-Frame-Options: DENY and frame-ancestors 'none'No reason for anyone to frame them
Embeddable widget routeframe-ancestors 'self' https://partner.example.net, no restrictive X-Frame-OptionsOnly CSP can name third-party origins
Public embeds for anyoneframe-ancestors * on that route only, and keep actions there harmlessFraming is the product; limit what a click can do

On a route that partners embed, do not send X-Frame-Options: SAMEORIGIN next to a broader frame-ancestors. Modern browsers follow the CSP and ignore the older header, but browsers without frame-ancestors support would block the partner. Keep embeddable routes narrow, such as /embed/, and keep state-changing actions off them or behind a confirmation step that opens in a new window.

If a page builder or analytics tool stops working after the change, the browser console names the blocked frame. Add that origin to frame-ancestors on the routes it needs, rather than removing protection site-wide.

5. Configuration on Nginx, Apache and IIS

Nginx

Add the headers in the HTTPS server block. The always parameter makes Nginx send them on error responses too; without it, add_header applies only to a set of success and redirect status codes.

server {
    listen 443 ssl;
    server_name example.com;

    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header Content-Security-Policy "frame-ancestors 'self'" always;

    location /embed/ {
        # add_header here replaces ALL headers inherited from the server block
        add_header Content-Security-Policy "frame-ancestors 'self' https://partner.example.net" always;
        add_header Strict-Transport-Security "max-age=31536000" always;
    }
}

The comment marks the classic trap described in the nginx headers module documentation: add_header directives are inherited from the previous level only if the current level defines none. Any location with its own add_header silently drops the server-level ones, so repeat every header you still want there. In the example, dropping X-Frame-Options on /embed/ is intended; dropping HSTS would not be, so it is repeated.

Apache

With mod_headers enabled, in the virtual host or .htaccess:

<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Content-Security-Policy "frame-ancestors 'self'"
</IfModule>

always selects the header table that also applies to error responses. If the application behind Apache already sends its own Content-Security-Policy, Header set in the always table can produce a second CSP header next to it. Browsers enforce every policy they receive, so a separate policy that contains only frame-ancestors is valid and restricts nothing else, but one policy maintained in one place is easier to reason about. Prefer adding frame-ancestors to the existing policy.

IIS

In web.config, custom headers apply to every response the site serves:

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-Frame-Options" value="SAMEORIGIN" />
        <add name="Content-Security-Policy" value="frame-ancestors 'self'" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

ASP.NET applications sometimes add X-Frame-Options from code as well. Check a live response for duplicates after deploying, and remove one source.

6. CDNs and hosting platforms

When a CDN or a static host sits in front of your site, you can set the header at the edge, at the origin, or both. Pick one owner. Setting it in both places is the most common cause of duplicate or contradictory values.

  • Cloudflare: response header rules (Transform Rules that modify response headers) can set a static header on matching requests. Scope the rule to your hostname, and add a narrower rule for an embed path if you have one.
  • Netlify: a _headers file in the publish directory sets headers per path.
  • Vercel: the headers array in vercel.json sets headers per source pattern.
  • Object storage behind a CDN: buckets usually cannot add arbitrary response headers themselves; set them in the CDN's response header policy or edge function.

A Netlify _headers example:

/*
  X-Frame-Options: DENY
  Content-Security-Policy: frame-ancestors 'none'

The equivalent in vercel.json:

{
  "headers": [
    {
      "source": "/(.*)",
      "headers": [
        { "key": "X-Frame-Options", "value": "DENY" },
        { "key": "Content-Security-Policy", "value": "frame-ancestors 'none'" }
      ]
    }
  ]
}

After a change at the edge, cached responses can keep the old headers until they expire or you purge them. Test with a URL that bypasses the cache, or purge first, before you decide the change did not work.

7. Frameworks and CMSs: defaults and overrides

Many frameworks already send a framing header, and some do not. Check what yours does before adding a second layer:

  • Django: XFrameOptionsMiddleware, enabled in the default project settings, sends X-Frame-Options using the X_FRAME_OPTIONS setting, which defaults to DENY in current versions. The xframe_options_exempt and xframe_options_sameorigin decorators change it per view.
  • Ruby on Rails: the default headers in config.action_dispatch.default_headers include X-Frame-Options: SAMEORIGIN. The content security policy initializer accepts policy.frame_ancestors :self.
  • Express: the Helmet middleware sends X-Frame-Options: SAMEORIGIN and a default CSP that includes frame-ancestors 'self'. Without Helmet or an equivalent, Express sends neither.
  • Next.js: add the headers in the headers() function of next.config.js, with a source such as '/:path*'.
  • Spring Security: sends X-Frame-Options: DENY by default; the headers configuration switches it to same origin or adds frame-ancestors.
  • WordPress: core sends X-Frame-Options: SAMEORIGIN on the login and admin screens, but not on public pages. Set public pages at the web server, CDN or with a well-maintained security plugin.

Framework defaults change between major versions, so confirm the result on a live response rather than relying on documentation for a version you may not be running. When the framework and the server both set the header, keep the one closest to the code that knows which routes are embeddable.

8. How to test and verify the fix

Start with the raw headers of the pages that matter:

curl -sS -D - -o /dev/null https://example.com/ | grep -iE '^(x-frame-options|content-security-policy)'
curl -sS -D - -o /dev/null https://example.com/account/ | grep -iE '^(x-frame-options|content-security-policy)'
curl -sS -D - -o /dev/null https://example.com/this-page-does-not-exist | grep -iE '^(x-frame-options|content-security-policy)'

Each command should print one X-Frame-Options line, a Content-Security-Policy line that contains frame-ancestors, or both. The third command checks an error page, which is often served by a different layer. On Windows, use curl.exe and -o NUL, and replace grep with findstr /i.

Then confirm that a browser actually refuses to frame your page from another origin. Save this file on your own machine:

<!doctype html>
<title>Frame test</title>
<iframe src="https://example.com/account/" width="900" height="600"></iframe>

Serve it from a different origin, for example by running python3 -m http.server 8000 in its folder and opening http://localhost:8000/ with the file name. With protection in place, the frame stays empty or shows a browser error, and the developer tools console explains that the page refused to be framed and which header or directive caused it. Without protection, your page renders inside the frame. Repeat the test from an origin you have allowed, such as a partner staging page, to confirm legitimate embeds still work.

Watch for these edge cases:

  • the home page is protected but sign-in, account or checkout pages come from another application without the header;
  • a location block in Nginx dropped the inherited headers;
  • the header exists only in a <meta> tag or only in Content-Security-Policy-Report-Only;
  • X-Frame-Options still says ALLOW-FROM, which modern browsers ignore;
  • the CDN cache still serves responses from before the change.

9. What Sitelemetry checks

The finding http.header.frame.missing, titled “Clickjacking protection missing”, comes from the HTTP security headers module. It requests the home page (root URL) of the scanned origin, follows redirects, reads the response headers of the final page and raises a medium-severity finding when the response has no X-Frame-Options header and its Content-Security-Policy header does not contain a frame-ancestors directive. The evidence reads “X-Frame-Options or CSP frame-ancestors not present”, and the remediation suggests adding either one. If the response is a bot challenge, an access denial or an edge error page, the module reports the result as not measured instead of raising header findings.

What the response containsFinding raised?What to keep in mind
Neither headerYesAny site can frame the page
X-Frame-Options: DENY or SAMEORIGINNoProtected
CSP with frame-ancestorsNoProtected; check the origin list is what you intend
CSP without frame-ancestorsYesA policy for scripts does not restrict framing
frame-ancestors only in Report-OnlyYesThe check reads only the enforced CSP header; report-only never blocks
frame-ancestors only in a second, separate Content-Security-Policy headerYesThe two headers arrive joined into one value, and the check does not recognise frame-ancestors at the start of the second policy; merge it into one policy or also send X-Frame-Options
Protection only in a meta tagYesBrowsers ignore both mechanisms in meta elements
X-Frame-Options: ALLOW-FROM ...NoThe check sees the header is present but does not validate its value; browsers ignore this value

The check is about presence. It does not judge whether the value fits your embedding needs, and it looks at one response, the home page, so other paths, error pages and separate applications need the tests in section 8. If you add a Content-Security-Policy header that contains only frame-ancestors, the separate CSP-missing finding is also no longer raised, even though such a policy does nothing against cross-site scripting; treat it as a first step towards a full policy.

The module is passive and runs in every scan profile on every plan: Free ($0), Starter ($49/month), Professional ($149/month) and Enterprise ($249/month); see pricing. It reads only what any visitor receives, so it needs no ownership verification on its own: the free Launch Readiness Snapshot and the free security headers checker run it without signup, and a Free-plan security audit runs it even before you verify the site. A security audit that also includes checks that need ownership proof, as paid-plan audits do by default, asks you to verify the site first. Sitelemetry is an automated audit tool, not a penetration test. For the other headers in the same module, read the security headers check guide, the TLS and security headers guide and the broader website security audit guide.

Common questions

Is X-Frame-Options deprecated?

The header itself still works in current browsers for DENY and SAMEORIGIN. Only the ALLOW-FROM value is obsolete and ignored. CSP frame-ancestors is the more flexible replacement, and when an enforced policy contains it, browsers ignore X-Frame-Options. Sending both is a reasonable choice.

Should I send both X-Frame-Options and frame-ancestors?

Yes, as long as they express the same intent, such as SAMEORIGIN with frame-ancestors 'self'. Modern browsers follow frame-ancestors and older ones fall back to X-Frame-Options. On routes that partners embed, send only frame-ancestors with the allowed origins, because X-Frame-Options cannot name them.

How do I allow one partner site to embed my page?

Use Content-Security-Policy: frame-ancestors 'self' https://partner.example.net on the routes that partner needs, and do not send a restrictive X-Frame-Options on those routes. Keep the embeddable routes narrow and avoid one-click actions that change data on them.

Can I set clickjacking protection in an HTML meta tag?

No. Browsers ignore X-Frame-Options in a meta http-equiv element, and the CSP specification ignores frame-ancestors when a policy is delivered through a meta element. Both must be sent as HTTP response headers by your server, CDN or framework.

I added the header, so why is the finding still reported?

Common causes are a CDN serving cached responses from before the change, the header being set only on some paths or status codes and missing from the home page, which is the response the check reads, an Nginx location block that dropped inherited headers, protection placed only in a meta tag, frame-ancestors placed only in a Content-Security-Policy-Report-Only header, or frame-ancestors sent in a second, separate Content-Security-Policy header. Check the live response with curl.

Sources & further reading

  1. MDN: X-Frame-Options headerdeveloper.mozilla.org
  2. MDN: CSP frame-ancestors directivedeveloper.mozilla.org
  3. W3C: Content Security Policy Level 3www.w3.org
  4. RFC 7034: HTTP Header Field X-Frame-Optionswww.rfc-editor.org
  5. OWASP Clickjacking Defense Cheat Sheetcheatsheetseries.owasp.org
  6. OWASP Community: Clickjackingowasp.org
  7. nginx: ngx_http_headers_module (add_header)nginx.org
  8. Apache HTTP Server: mod_headershttpd.apache.org
Sitelemetry team

Prepared by the Sitelemetry editorial team. Explore the linked sources for further detail.

SITELEMETRY

Put what you learned to work.

Explore your website’s structure, settings and signals with Sitelemetry.