Cloud & app security

What Is X-Frame-Options? How the Header Stops Clickjacking

One response header decides whether another site can embed your pages in a frame. Here is what X-Frame-Options does, which value to use, and where it falls short.

Cysoro Security TeamPublished · 7 min read
CLOUD & APP SECURITY X-Frame-Options One header stops clickjacking. attacker-site.example Claim your prize now! FRAMING BLOCKED X-Frame-Options: DENY X-Frame-Options: DENY
Quick answer

X-Frame-Options is an HTTP response header that tells a browser whether a page may be displayed inside a frame or iframe on another site. Set to DENY, it blocks all framing; set to SAMEORIGIN, it allows framing only by pages from the same site. It is the simplest defense against clickjacking, though the newer Content Security Policy frame-ancestors directive now takes precedence where both are set.

Key takeaways

  • X-Frame-Options tells browsers whether your page may be embedded in a frame, blocking clickjacking attacks.
  • Use DENY unless your own site genuinely needs to frame its pages, in which case use SAMEORIGIN.
  • CSP frame-ancestors is the modern replacement and overrides X-Frame-Options, so send both during a transition.

Your login page looks fine. But nothing stops another website from loading it inside an invisible frame, layering a fake button on top, and letting a visitor click your real "Delete account" button while thinking they clicked "Claim prize". X-Frame-Options is the header that stops that.

What is X-Frame-Options?

X-Frame-Options is an HTTP response header that tells a browser whether a web page may be displayed inside a <frame> or <iframe> on another site. Your server sends it with the page, and the browser enforces it before rendering.

It was defined in RFC 7034 in 2013, after Internet Explorer introduced it to fight clickjacking. Every modern browser supports it, and it remains the simplest framing defense you can deploy: one header, no code changes to the page itself.

The header applies per response, not per site. Your homepage can send one value while your settings page sends another, which is why you must check every page type rather than assuming one test covers the whole site.

How does X-Frame-Options stop clickjacking?

Clickjacking works by embedding your real page in a transparent frame on an attacker's page, then placing a decoy on top. The victim's click lands on your page, not the decoy, so the browser sends the real request with the victim's session.

Clickjacking, and the one header that breaks it1. Attacker pageA fake prize or videopage with a temptingbutton on top2. Hidden frameYour real settings pageloads invisibly insidean iframe, already logged in3. Stolen clickThe victim clicks the decoyand really clicks yourreal button insteadWith X-Frame-Options: DENY, the browser refuses to load the frame at allNo frame means no hidden page, so the decoy button has nothing underneath it.
How a clickjacking attack uses a hidden frame, and why blocking framing breaks the attack. Illustration by Cysoro.

Because the click happens on the genuine page, anti-CSRF tokens do not help: the token is real, the session is real, and the request looks legitimate. That is why framing controls matter even on a site with good CSRF protection, as PortSwigger's clickjacking guide explains.

With X-Frame-Options: DENY on the response, the browser refuses to render the page in any frame. The attacker's page loads, but the hidden frame stays empty, so there is nothing for the victim to click by accident.

What are the X-Frame-Options values?

There are only three values, and only two of them work in modern browsers. OWASP recommends DENY unless you have a specific, identified need for framing.

ValueWhat it doesWhen to use it
DENYBlocks framing by any site, including your ownDefault for almost every page
SAMEORIGINAllows framing only by pages from the same originYour own site frames its pages, e.g. previews
ALLOW-FROM uriMeant to allow one named site; obsoleteNever in modern browsers — use CSP instead

DENY is the strictest option. It blocks framing even by your own origin, which is what you want for login pages, account settings, admin panels and payment pages. If nothing on your own site frames the page, there is no reason to choose anything weaker.

SAMEORIGIN allows framing when the framing page shares the same scheme, host and port. It suits sites with their own preview panes, embedded dashboards or content management frames. Note that a sibling subdomain such as files.example.com is a different origin, so it cannot frame app.example.com under SAMEORIGIN.

ALLOW-FROM is obsolete. Modern browsers that see it ignore the entire header, which means the page gets no framing protection at all. If a partner needs to frame your page, use CSP frame-ancestors with that partner's origin listed instead.

X-Frame-Options vs CSP frame-ancestors: which should you use?

CSP frame-ancestors is the modern replacement for X-Frame-Options, and when a response carries both, the browser enforces frame-ancestors and ignores X-Frame-Options. The OWASP Clickjacking Defense Cheat Sheet recommends it as the primary defense.

X-Frame-OptionsCSP frame-ancestors
StatusOlder header, still widely supportedModern standard, the recommended control
Block everyoneDENYframe-ancestors 'none'
Same site onlySAMEORIGINframe-ancestors 'self'
Allow named partnersNot possible (ALLOW-FROM is dead)frame-ancestors 'self' https://partner.example.com
Multiple originsNoYes, list as many as needed
If both are sentIgnored by the browserEnforced

The practical answer for most sites is to send both. Set X-Frame-Options: DENY and Content-Security-Policy: frame-ancestors 'none' on the same response. Modern browsers use the CSP rule; older browsers and many security scanners fall back to X-Frame-Options.

Two traps catch people out. First, frame-ancestors has no fallback: a default-src 'none' policy does not stop framing, because the directive only applies when it is explicitly set. Second, a report-only CSP does not enforce anything, so Content-Security-Policy-Report-Only with frame-ancestors 'none' only logs violations.

How do you set X-Frame-Options?

Set the header on the server or reverse proxy so it is added to every HTML response. The exact syntax depends on your stack, but the header itself is always the same one-liner.

Nginx

Add this inside the server block, then reload. The always flag makes Nginx send the header on error responses too, which matters because error pages can also carry actions.

add_header X-Frame-Options "DENY" always;

Apache

Enable mod_headers and add this to your virtual host or .htaccess file. Test on one site first if you run several virtual hosts from the same configuration.

Header always set X-Frame-Options "DENY"

Cloudflare and CDNs

If a CDN or proxy sits in front of your origin, set the header there or confirm the origin header survives the proxy. Some proxies strip or rewrite response headers, so verify the header on the public response, not just on the origin server.

Cloudflare users can add the header with a Transform Rule or a Worker. If you use another CDN, check its documentation for response header modification and apply the same DENY value.

In the application

Most frameworks can send the header from middleware, which is useful when the proxy is outside your control. In Express, the Helmet middleware sets it for you; in Django, set X_FRAME_OPTIONS = 'DENY' in settings; in Rails, the default config.action_dispatch.default_headers already includes it.

How do you test X-Frame-Options?

Test the real pages an attacker would target, not just the homepage. Framing protection is set per response, so a homepage with DENY tells you nothing about the settings page that actually holds the dangerous buttons.

Test every page that holds an action1. Fetch the headerscurl -s -D - https://example.com/settings -o /dev/null2. Read the valueWant DENY, SAMEORIGIN or frame-ancestors3. Repeat on every page typelogin, settings, admin, payment, error pages4. Try to frame it yourselfOn a test page you own — the browser must refuseUse a normal GET, not HEADSome servers answer HEAD requests with different headers than a browser's GET.
Four steps to verify framing protection on the pages that matter. Illustration by Cysoro.

Use a normal GET request for the test. Some servers answer HEAD requests with different headers than a browser's GET, so curl -I can show a header that real visitors never receive. Check the response after following redirects too, since a redirect target can carry different headers.

For a quick scan of the whole site, run our free security headers checker against your domain. It reads the headers your server actually sends and flags missing framing protection alongside other header gaps.

What are the common X-Frame-Options mistakes?

Most X-Frame-Options failures are not missing headers. They are headers set in the wrong place, on the wrong pages, or with a value that silently does nothing.

  • Only the homepage is protected. Attackers target the settings, billing and admin pages, which are the responses most often left without the header.
  • ALLOW-FROM is still in the config. Modern browsers ignore the whole header when they see this value, leaving the page unprotected.
  • It is set in a meta tag. A <meta http-equiv> tag cannot set X-Frame-Options. It must be a real response header.
  • A proxy strips it. A CDN or load balancer can drop the header between your origin and the visitor. Always verify the public response.
  • Error pages are unprotected. A 404 or 500 page served without the header can still be framed if it contains a form or a link that matters.
  • DENY breaks a legitimate embed. Rolling DENY out without checking your own previews and partner widgets can take a working feature down.

Each of these is easy to catch with a scan of every route, which is why a one-off homepage check is never enough. Our guide to securing your Wi-Fi covers a similar lesson for home networks: check every entry point, not just the obvious one.

What does X-Frame-Options not protect against?

X-Frame-Options stops frame-based clickjacking only. It does not stop attacks that open your page in a separate top-level window instead of a frame, sometimes called DoubleClickjacking, which needs confirmation steps for sensitive actions instead.

It also does nothing against phishing pages that merely imitate your design, against a compromised account, or against an attacker who tricks a user into visiting a malicious site directly. Framing controls are one layer; they sit alongside authentication, CSRF tokens and SameSite cookies.

SameSite cookies help here too. A session cookie marked SameSite=Lax is not sent with most cross-site iframe requests, so the framed page often arrives logged out. That is a useful second layer, but it is not a substitute: same-site subdomains still share cookies, and not every browser behaves the same way.

Finally, remember that X-Frame-Options only applies to HTML pages rendered by browsers. It has no effect on APIs, mobile apps or non-browser clients, which need their own authorization checks.

The bottom line

X-Frame-Options is one of the cheapest security wins on the web: a single header that stops other sites from embedding your pages. Send DENY everywhere by default, switch to SAMEORIGIN only where your own site frames its pages, and add CSP frame-ancestors as the modern primary control.

Then verify it on every page type, not just the homepage, and keep it in your deployment checklist so a new route or proxy change cannot silently drop it. You can confirm your headers in seconds with the free security headers checker.

Frequently asked questions

What is X-Frame-Options in simple terms?

It is a header your web server sends with a page that tells the visitor's browser whether another website is allowed to show that page inside a frame. If framing is blocked, an attacker cannot hide your real page under a fake one to steal clicks.

Should I use DENY or SAMEORIGIN?

Use DENY unless your own site needs to frame its own pages, for example in a preview or an embedded widget. SAMEORIGIN allows framing only by pages from your own site. DENY is the safer default and is what OWASP recommends unless a specific need for framing exists.

What happened to ALLOW-FROM?

ALLOW-FROM was meant to let one named site frame your page, but it was never supported consistently and modern browsers ignore it. If you see it in old configuration, replace it with a CSP frame-ancestors directive listing the allowed origins.

Is X-Frame-Options still needed if I have a CSP?

If your Content Security Policy includes frame-ancestors, browsers enforce that and ignore X-Frame-Options. Many sites still send both, because older browsers and some scanners only understand X-Frame-Options, and the extra header costs nothing.

Does X-Frame-Options work in a meta tag?

No. X-Frame-Options only works as a real HTTP response header sent by the server. Putting it in a meta element in the HTML has no effect, and neither does a CSP frame-ancestors directive in a meta tag.

Can X-Frame-Options break my site?

Yes, if your own pages or a trusted partner legitimately frame your content. A DENY policy will stop your own preview panes, embedded dashboards and some payment or widget integrations from loading. Test with SAMEORIGIN or an allowlist in CSP before rolling DENY out everywhere.

Does X-Frame-Options protect APIs?

Not really. The header only matters to browsers rendering HTML pages in frames. API responses are not framed, so the header has no effect there. APIs need authentication, CORS controls and anti-CSRF tokens instead.

How do I check my X-Frame-Options header?

Fetch any page with curl and look at the response headers, or run a free security headers scan. Check every page type, not just the homepage, because headers are set per response and login or settings pages are often missed.

Sources

  1. OWASP — Clickjacking Defense Cheat Sheet
  2. MDN — X-Frame-Options
  3. OWASP Secure Headers Project — Response Headers
  4. IETF — RFC 7034: HTTP Header Field X-Frame-Options
  5. PortSwigger — Clickjacking
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against OWASP's Clickjacking Defense Cheat Sheet, MDN's X-Frame-Options reference and RFC 7034.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free