X-Frame-Optionsis 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
DENYunless your own site frames the page, thenSAMEORIGIN. Those are the only two valid values: browsers ignoreALLOW-FROMand treat it as no header at all. - The CSP directive
frame-ancestorsdoes the same job with more control, and overridesX-Frame-Optionswhen both are sent. Send both:frame-ancestors 'none'andX-Frame-Options: DENY. - To let a partner embed a page, list it in
frame-ancestorsand leaveX-Frame-Optionsoff that page only. - WebSec0 grades it the way browsers apply it: full 15 points for a lone
DENYorSAMEORIGIN, or for a CSP containingframe-ancestors. Conflicting values earn 7, andALLOW-FROMearns 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:
X-Frame-Options: DENYIts 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 ofdefault-src 'none'still lets any site frame the page. Setframe-ancestorsexplicitly. - Browsers ignore it in a CSP
<meta>tag. It only works in the HTTP header.
Our advice: send both, with matching values.
Content-Security-Policy: frame-ancestors 'none'
X-Frame-Options: DENYIf 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.
-
List the sites that embed the page, with their exact scheme and host.
-
On that page only, send
frame-ancestorswith your own origin and theirs:HTTP Content-Security-Policy: frame-ancestors 'self' https://partner.example -
Do not send X-Frame-Options on that page. Current browsers would ignore it because of
frame-ancestors, but aDENYleft there blocks the page in older clients. Do not replace it withALLOW-FROMeither: it is ignored. -
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
SAMEORIGINfrom the application andDENYfrom 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:
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. Useframe-ancestors. - Sending two different values. The application sends
SAMEORIGIN, the proxy addsDENY, and your own admin previews stop loading. In our test in Chrome 152,SAMEORIGINandDENYtogether blocked the page on its own origin too. - A comma-separated value.
DENY, SAMEORIGINin one header is treated the same as two headers: blocked everywhere. - Relying on a
<meta>tag. Neither X-Frame-Options norframe-ancestorsworks there. - Expecting
default-srcto cover framing.frame-ancestorshas no fallback. Without it, CSP does not restrict who frames your page. - Using
frame-srcinstead offrame-ancestors.frame-srccontrols 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
SAMEORIGINacross subdomains. Origins must match exactly; useframe-ancestorswith 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-FROMscores like a missing header, because browsers ignore it. Withframe-ancestorsin the CSP, it passes, since browsers then ignore X-Frame-Options anyway. Remove it all the same.frame-ancestorsonly needs to be present. The scanner does not grade its value, soframe-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
Apache
Guide ↗Set X-Frame-Options on Apache with Header always set, pair it with CSP frame-ancestors, keep it on errors and redirects and avoid duplicate headers. Tested configs.
Caddy
Guide ↗Set X-Frame-Options on Caddy with the header directive, pair it with CSP frame-ancestors, drop the application's copy behind reverse_proxy and allow one path. Tested.
Nginx
Guide ↗Set X-Frame-Options on Nginx with add_header and always, pair it with CSP frame-ancestors, keep it on every location and avoid duplicate headers. Tested configs.
Traefik
Guide ↗Set X-Frame-Options on Traefik with frameDeny or customFrameOptionsValue, pair it with CSP frame-ancestors and let a partner embed one path. Tested configs.
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
- X-Frame-Options headerMDN Web Docs
- CSP: frame-ancestorsMDN Web Docs
