Article
X-Frame-Options vs frame-ancestors: which one actually protects your site
Published 2026-11-21
X-Frame-Options vs frame-ancestors: which one actually protects your site
Every security header guide eventually tells you the same two things: stop other sites from framing your pages, and use one of two mechanisms to do it. Then it usually stops, because the moment you open two browser tabs, one with the MDN page for X-Frame-Options and one with the CSP frame-ancestors directive, the guides split into two camps and your actual question goes unanswered. Your actual question is: which do I set, and is the other one now dead?
Short answer first: set both. frame-ancestors decides in every modern browser, X-Frame-Options exists as the old-browser fallback, and the mapping between them is mechanical. The long version is worth reading because the details decide whether a widget or partner page works at all, and because one common configuration is a genuine hole, not a style preference.
What the problem is
A page without framing control can be loaded inside an <iframe> by anyone. Most embeds are harmless. The attack is called clickjacking (UI redressing is the formal name): the attacker loads your page in a frame made transparent with CSS, puts their own content underneath, and gets a visitor's clicks to land on your page without the visitor knowing it. When the click means "transfer money" or "change my password", that matters.
<!-- the attacker's page -->
<iframe src="https://your-bank.example/account" style="opacity:0"></iframe>
Framing control makes the browser refuse to render the page in a frame the site did not authorize. There are two headers that do this, and their relationship is the whole subject.
X-Frame-Options: the old one
X-Frame-Options was the first mechanism browsers shipped for this. It is a response header (RFC 7034 is the formal record, though browsers never implemented it exactly as written) with two working values:
X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
DENY blocks every frame, including your own pages. SAMEORIGIN allows your own origin only. That is the entire grammar. There is no way to say "my partner site may frame this page but nobody else" - the header takes a single value and browsers honor one header, so two values on two lines get ignored. Nesting defeats it as well: SAMEORIGIN requires every frame in the chain to have your origin, so if your page sits inside your own iframe and that page is itself embedded by anyone else, the load is refused. There is no way to allow your iframe and block the rest.
There is a third value, ALLOW-FROM, which lets you name one origin. It is dead: modern browsers ignore a header carrying it, and a browser that ignores the header leaves the page completely unprotected, which is why it "fails open". If you find ALLOW-FROM anywhere in your config, treat it as a finding, not a quirk.
One more hard limit: it is only ever a header. <meta http-equiv="X-Frame-Options" content="deny"> does nothing, and OWASP's clickjacking cheat sheet says so plainly. Browsers only read it from the HTTP response.
frame-ancestors: the CSP one
The Content Security Policy Level 2 spec moved framing control into the frame-ancestors directive. Same job, but a source list instead of one value:
Content-Security-Policy: frame-ancestors 'none';
Content-Security-Policy: frame-ancestors 'self';
Content-Security-Policy: frame-ancestors 'self' https://partner.example.com https://*.example.org;
'none' and 'self' are the direct equivalents of DENY and SAMEORIGIN, quoted exactly, because unquoted self is a host-source, not the keyword. The win over the old header is the list: you can name partner sites, wildcard subdomains, or allow the https: scheme as a whole. OWASP recommends frame-ancestors 'none' unless a specific need for framing has been identified, which is most pages.
A few details from the spec and MDN bite people constantly:
It never falls back to default-src. A policy that reads default-src 'none'; script-src 'self' looks locked down and still lets anyone embed the page, because frame-ancestors is absent and nothing fills the gap. Every other content directive falls back to default-src; this one is explicitly exempt. If you care about framing at all, you must set it by name.
It checks every ancestor. If your page is framed inside a partner page which is itself framed by a third site, the directive checks both ancestors, and if any of them does not match the policy the load is blocked. For a frame-ancestors partner.com policy this means a partner page containing your frame must not itself be embedded by anyone else, or your page stops loading.
It is ignored in a <meta> tag. Unlike most CSP directives, frame-ancestors cannot be delivered via <meta http-equiv>; it only works as a real response header. On hosted platforms where you cannot set headers, this is bad news and the honest answer is that you cannot fully fix framing there.
Which one wins when both are present
The CSP spec settles the conflict explicitly: "If a resource is delivered with a policy that includes a directive named frame-ancestors and whose disposition is 'enforce', then the X-Frame-Options header MUST be ignored." Chromium implements that literally. So in any current browser, frame-ancestors is the only header that matters; X-Frame-Options is decoration alongside it.
Decorative is not useless. Old engines that predate CSP Level 2 never learned frame-ancestors, and for those clients X-Frame-Options is all there is. OWASP also records an odd historical wrinkle: a few very old versions (Chrome 40, Firefox 35) did the reverse and followed X-Frame-Options while ignoring the directive. Current engines follow the spec rule; the old ones are why "which header wins" has no single answer across every browser ever shipped.
The configuration that is a real hole
Wrong header is rarely the issue. Wrong value for the situation is. Three examples I keep seeing in real configs:
X-Frame-Options: ALLOW-FROM anywhere. Already covered: browsers ignore the whole header, the page has no framing protection, and the person who configured it believes protection exists. Replace it with frame-ancestors 'self' https://partner.example.com and keep X-Frame-Options: SAMEORIGIN alongside.
Two values on one line, or two headers. X-Frame-Options: SAMEORIGIN, DENY is undefined in every browser: engines pick one value or reject the line, and the result depends on the reader. One header, one value, chosen deliberately.
CSP without frame-ancestors. A long policy that starts with default-src 'none' and never mentions framing is the most common silent gap I find in real configs. It looks thorough, it gets copied around, and it protects nothing against clickjacking.
How to check what you actually send
The fastest check is curl against your own site:
curl -sI https://example.com/ | grep -iE 'x-frame-options|content-security-policy'
If both headers appear, verify the frame-ancestors value matches what you intended: grep -o "frame-ancestors[^;]*" on the CSP line. A misconfigured list is as bad as a missing header, because browsers enforce exactly what is written.
For the visual check, create a local HTML file that embeds your site and open it in a browser. If the page renders in the frame, your framing control is not working. If you get a refused connection or a blank frame, it is.
To see the refusals themselves, load the test frame with the browser console open. A frame-ancestors block logs a CSP violation entry naming the directive and the URL that was refused. An X-Frame-Options refusal produces no console entry or report at all: a partner quietly failing to embed your widget is often the first, and only, notice you get. That asymmetry is one more reason to send both headers rather than pick one.
What to send, by situation
Plain table, no ceremony:
| Your situation | Send this |
|---|---|
| Nothing should ever frame any page | Content-Security-Policy: frame-ancestors 'none' + X-Frame-Options: DENY |
| Only your own pages frame it | frame-ancestors 'self' + X-Frame-Options: SAMEORIGIN |
| Named partner sites frame it | frame-ancestors 'self' https://partner.example.com + X-Frame-Options: SAMEORIGIN |
| Config contains ALLOW-FROM | Replace it with the row above; it protects nothing |
Two implementation notes. First, header case matters to nobody but you: both headers are case-insensitive, but 'self' and 'none' keywords in CSP are case-sensitive and require their single quotes. Second, if a CDN or proxy is in front of your origin, verify the headers arrive at the browser, not just at your server config, because proxies are notorious for adding and stripping headers. OWASP documents this as a practical threat to the whole mechanism.
The short version
frame-ancestors governs in every modern browser and overrides the old header when both are present. X-Frame-Options is not deprecated - browsers still enforce it, and MDN's compatibility data shows no deprecation - but it can only say DENY or SAMEORIGIN, so the moment you need a partner origin or a wildcard, CSP is the only option. Send both: the CSP directive for current engines, the old header for the few clients that never learned it. The two traps that produce false confidence are ALLOW-FROM and a CSP that relies on default-src to cover framing, which it explicitly does not.
Framing control is two header lines in a server config, and it shows up on every serious security checklist. CheckWebSecurity checks for the framing header on every scan and reports it as a finding when it is absent, so you can see whether your site sends one at all. Run a free scan.
Related: Content Security Policy explained in plain terms · Security headers scan