Header guide · X-Frame-Options

X-Frame-Options: DENY vs SAMEORIGIN and the move to frame-ancestors

X-Frame-Options stops other sites from framing your pages, the main defence against clickjacking. DENY vs SAMEORIGIN, and why CSP frame-ancestors replaces it.

evil.example loads your page in an invisible frame over its own button. Your response carries X-Frame-Options: DENY and frame-ancestors 'none', so the browser does not render the frame and the click cannot reach your page.OTHER SITEYOUR RESPONSEevil.exampleClaim prizeiframe · your-site.exampleyour "Delete account" buttonHTTP/2 200x-frame-optionsDENYframe-ancestors'none'
Framed by another site: the browser refuses to render your page.
In short5 points
  • X-Frame-Options is an HTTP response header that tells the browser whether your page may be shown inside a frame. It is the classic defence against clickjacking.
  • Use DENY unless your own site frames the page, then SAMEORIGIN. Those are the only two valid values: browsers ignore ALLOW-FROM and treat it as no header at all.
  • The CSP directive frame-ancestors does the same job with more control, and overrides X-Frame-Options when both are sent. Send both: frame-ancestors 'none' and X-Frame-Options: DENY.
  • To let a partner embed a page, list it in frame-ancestors and leave X-Frame-Options off that page only.
  • WebSec0 grades it the way browsers apply it: full 15 points for a lone DENY or SAMEORIGIN, or for a CSP containing frame-ancestors. Conflicting values earn 7, and ALLOW-FROM earns nothing.

What is X-Frame-Options?

X-Frame-Options is an HTTP response header that tells the browser whether your page may be displayed inside a frame on another page. With DENY, the browser refuses to render the page in any <iframe>, <frame>, <embed> or <object>. With SAMEORIGIN, only pages from your own origin may frame it. Without the header, any site can.

A typical header looks like this:

HTTP
X-Frame-Options: DENY

Its purpose is to stop clickjacking. The modern replacement is the frame-ancestors directive of the Content-Security-Policy header, which browsers apply first when both are present. Most sites should send both.

X-Frame-Options is one of the most widely deployed security headers. In Scott Helme’s June 2026 crawl, 327,918 of the 819,002 top sites that responded sent it (about 40%). Only 77,873 sites set frame-ancestors in a CSP.

What is clickjacking?

Clickjacking is a UI redressing attack. An attacker’s page loads your page in an invisible iframe and places it over a decoy, such as a “Claim prize” button. The victim thinks they click the decoy, but the click lands on your page, where they are logged in. One click can confirm a payment, change an account setting, grant a permission or delete data.

Attack What the attacker gets Stopped by refusing to be framed?
Invisible frame over a decoy button One authenticated click on your page Yes
Several clicks or drag and drop guided by the decoy A multi-step action, or text dragged out of your page Yes
Prefilled form inside the frame A form submitted with the attacker’s values Yes
Your page opened in a pop-up, then covered A click on a page that is not framed No: framing headers only cover frames

X-Frame-Options does not stop cross-site request forgery or scripts injected into your own page. It only decides who may put your page in a frame.

DENY or SAMEORIGIN?

The HTML Standard defines two valid values. Values are case-insensitive.

Value Valid What the browser does
DENY Yes Blocks the page in every frame, even on your own site.
SAMEORIGIN Yes Allows the page only if every frame ancestor has the same origin as the page.
ALLOW-FROM https://… No Ignored. The page can be framed by any site.
ALLOWALL or any other value No Ignored. The page can be framed by any site.

Pick DENY unless your site frames its own pages, for example an admin panel that shows previews in an iframe. Then use SAMEORIGIN. It means the exact scheme, host and port: app.example.com cannot frame www.example.com under SAMEORIGIN.

ALLOW-FROM was defined in RFC 7034 to name one allowed site, but the HTML Standard says it is not to be implemented. A page sending it is as open as a page sending nothing. Use frame-ancestors for that case.

X-Frame-Options vs CSP frame-ancestors

frame-ancestors is the CSP directive that replaces X-Frame-Options. Its 'none' is equivalent to DENY and its 'self' to SAMEORIGIN, but it also accepts a list of origins.

X-Frame-Options CSP frame-ancestors
Block all framing DENY frame-ancestors 'none'
Allow your own origin SAMEORIGIN frame-ancestors 'self'
Allow specific sites Not possible frame-ancestors 'self' https://partner.example
Allow a scheme or wildcard subdomains Not possible frame-ancestors https://*.example.com
Checks every ancestor, not just the parent Yes Yes
Report violations No Yes, with report-to
Works in a <meta> tag No No

When a response carries an enforced CSP with frame-ancestors, browsers ignore X-Frame-Options entirely. A Content-Security-Policy-Report-Only header does not have that effect: in our test in Chrome 152, a page with X-Frame-Options: DENY and a report-only frame-ancestors 'self' stayed blocked everywhere.

Two traps when moving to frame-ancestors:

  • It does not fall back to default-src. A policy of default-src 'none' still lets any site frame the page. Set frame-ancestors explicitly.
  • Browsers ignore it in a CSP <meta> tag. It only works in the HTTP header.

Our advice: send both, with matching values.

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

If you already have a full CSP, add frame-ancestors 'none' to it rather than sending a second CSP header.

How to allow a partner to embed a page

Some pages are meant to be framed: a payment widget, a video player, a support chat. Handle them one by one, and keep everything else at DENY.

  1. List the sites that embed the page, with their exact scheme and host.

  2. On that page only, send frame-ancestors with your own origin and theirs:

    HTTP
    Content-Security-Policy: frame-ancestors 'self' https://partner.example
  3. Do not send X-Frame-Options on that page. Current browsers would ignore it because of frame-ancestors, but a DENY left there blocks the page in older clients. Do not replace it with ALLOW-FROM either: it is ignored.

  4. Keep the page free of sensitive actions that a framing site could trick users into, or require a confirmation step outside the frame.

Where to send the header

  • On every HTML response, including error pages and login, account and admin pages. Those are the pages an attacker wants to frame. Sending it on images, scripts and API responses is harmless and simpler than targeting HTML.
  • As an HTTP header. Browsers ignore X-Frame-Options in a <meta> tag.
  • Once per response. Two different values, such as SAMEORIGIN from the application and DENY from the web server, make browsers block the page in every frame, including your own. Two identical values behave like one.
  • With one owner. Decide whether the application or the web server sets the header, and remove it from the other.

You can check what a page sends with curl:

Shell
curl -sI https://example.com/ | grep -iE "^x-frame-options|^content-security-policy"

Common mistakes

  • Using ALLOW-FROM. Current browsers ignore the whole header, so the page can be framed by anyone. Use frame-ancestors.
  • Sending two different values. The application sends SAMEORIGIN, the proxy adds DENY, and your own admin previews stop loading. In our test in Chrome 152, SAMEORIGIN and DENY together blocked the page on its own origin too.
  • A comma-separated value. DENY, SAMEORIGIN in one header is treated the same as two headers: blocked everywhere.
  • Relying on a <meta> tag. Neither X-Frame-Options nor frame-ancestors works there.
  • Expecting default-src to cover framing. frame-ancestors has no fallback. Without it, CSP does not restrict who frames your page.
  • Using frame-src instead of frame-ancestors. frame-src controls which pages you embed, not who embeds you.
  • Forgetting error pages and secondary apps. A login page served by another application, or a 404 from the web server, often misses the header.
  • Counting on SAMEORIGIN across subdomains. Origins must match exactly; use frame-ancestors with the subdomain listed.

How WebSec0 grades X-Frame-Options

X-Frame-Options is worth 15 of the 100 points in the WebSec0 headers grade. The scanner fetches your page and follows the browser’s rules from the HTML Standard. It first looks for frame-ancestors in every Content-Security-Policy header, then reads every X-Frame-Options value, whether sent as separate headers or as a comma-separated list:

What WebSec0 sees Status Points
A CSP containing frame-ancestors, whatever X-Frame-Options says Pass 15 / 15
DENY or SAMEORIGIN alone, in any case, even repeated Pass 15 / 15
Conflicting values, such as SAMEORIGIN and DENY Warning 7 / 15
A lone invalid value, such as ALLOW-FROM or ALLOWALL Fail 0 / 15
No X-Frame-Options and no frame-ancestors Fail 0 / 15

A few details follow from how the check works:

  • Conflicting values are a warning, not a pass. Browsers block the page in every frame, so it is protected, but your own iframes break too. Send one header with one value.
  • ALLOW-FROM scores like a missing header, because browsers ignore it. With frame-ancestors in the CSP, it passes, since browsers then ignore X-Frame-Options anyway. Remove it all the same.
  • frame-ancestors only needs to be present. The scanner does not grade its value, so frame-ancestors * passes. It is your job to keep it at 'none', 'self' or a short list.
  • Report-only and <meta> policies do not count, as for browsers.

The CSP itself is graded separately, for 25 points, and frame-ancestors plays no part in that grade.

Step by step

Configure it on your server

Setting up every header at once? Read all security headers on Apache, all security headers on Caddy, all security headers on Nginx, all security headers on Traefik.

Questions

Frequently asked questions

What does the X-Frame-Options header do?

It tells the browser whether a page may be loaded inside a <frame>, <iframe>, <embed> or <object>. With DENY, no site can frame it. With SAMEORIGIN, only pages from the same origin can. Without the header, any site can.

Should I use DENY or SAMEORIGIN?

DENY if nothing on your site frames its own pages. SAMEORIGIN if it does, for example an admin panel that shows previews in an iframe. SAMEORIGIN only allows the exact same scheme, host and port, not your subdomains.

Is X-Frame-Options deprecated?

No. The HTML Standard still defines it and every current browser enforces it. The ALLOW-FROM value is obsolete, and CSP frame-ancestors is the more flexible replacement, which takes precedence when both are present.

Do I still need X-Frame-Options if my CSP has frame-ancestors?

Current browsers ignore X-Frame-Options when an enforced CSP contains frame-ancestors, and WebSec0 grades that CSP as a pass. Sending both costs one line and covers clients that predate CSP Level 2.

How do I allow one specific site to frame my page?

Use Content-Security-Policy: frame-ancestors 'self' https://partner.example, and do not send X-Frame-Options on that page. ALLOW-FROM is ignored by current browsers, which leaves the page open to every site.

Can I set X-Frame-Options in a meta tag?

No. Browsers ignore <meta http-equiv="X-Frame-Options">, and they also ignore frame-ancestors in a CSP <meta> tag. Both only work as HTTP response headers.

What happens if a response has two X-Frame-Options headers?

If the values differ, such as SAMEORIGIN and DENY, browsers block the page in every frame, including your own. Two identical values behave like one. Duplicates usually come from the application and the web server both adding the header.

Does X-Frame-Options affect images, scripts or API responses?

No. It only matters on responses that a browser loads as a document inside a frame. Sending it on every response is harmless and simpler than targeting HTML pages.

References

Sources

About the author

Portrait of Joshua Martinelle

Security engineer at Tenable

Security engineer at Tenable and web security researcher. He has disclosed more than 60 CVEs since 2020 and builds WebSec0.

Verify the change

Deployed it? Check it.

WebSec0 grades your TLS setup and security headers, including X-Frame-Options, in a few seconds. Free, no account.

Scan your site