How to Fix Missing Clickjacking Protection (frame-ancestors)

Clickjacking happens when another site loads your page inside an invisible iframe and tricks visitors into clicking buttons they cannot see, such as Buy, Delete or Log in. By the end of this guide your homepage, and the rest of your site, will send an HTTP response header that tells browsers only your own domain may frame it.

By Updated ⏱ 15 minutes🎯 Beginner● Medium impactSecurity
Illustration: Clickjacking protection fix guide
SECURITY · FIX GUIDE Clickjacking protection IMPACTEFFORT TIME15 minutes LEVELBeginner

Why it matters

Without a frame-ancestors rule or X-Frame-Options header, any site can embed your login, checkout or account pages and overlay fake UI on top of them. That can lead to unwanted purchases, changed settings or stolen sessions. It can also let scraper or spam sites show your content inside their own pages.

Security scanners, procurement questionnaires and browser security audits flag this header as missing. The fix is one or two lines of server config and has no effect on rankings or page speed.

✕Beforecurl -sI https://example.com shows noX-Frame-Options header and noContent-Security-Policy containing✓Aftercurl -sI https://example.com returnscontent-security-policy:frame-ancestors 'self' and

What you need

Access to your web server config (Nginx, Apache/.htaccess), hosting dashboard, CDN or framework config
A list of any sites that legitimately embed your pages in an iframe (partners, your own subdomains, page-builder previews)
A terminal with curl, or your browser's DevTools Network tab

Step-by-step fix

1

Check which headers your homepage sends now

Request your homepage and look at the response headers. You pass if either of these is present:

  • X-Frame-Options with the value DENY or SAMEORIGIN
  • A Content-Security-Policy header that contains a frame-ancestors directive

X-Frame-Options: ALLOW-FROM does not count, and modern browsers ignore it. A Content-Security-Policy-Report-Only header does not count either. Follow redirects so you test the final URL.

text
curl -sIL https://example.com | grep -iE 'x-frame-options|content-security-policy'
Pro tip: If you already send a Content-Security-Policy header, note its full value now. You will add frame-ancestors to it rather than replace it.
2

Choose the right framing policy

Pick one value for frame-ancestors:

  • 'self' lets only pages on your own origin frame the site. This is the safe default for most sites.
  • 'none' blocks all framing, including your own.
  • 'self' https://partner.example.com allows specific trusted origins as well.

Pair it with X-Frame-Options: SAMEORIGIN (or DENY) as a fallback for very old browsers. When both headers are present, modern browsers follow frame-ancestors.

text
Content-Security-Policy: frame-ancestors 'self' https://partner.example.com
X-Frame-Options: SAMEORIGIN
Pro tip: X-Frame-Options cannot list extra domains. If you need to allow a partner, rely on frame-ancestors and use SAMEORIGIN only as the legacy fallback.
3

Add the headers on Nginx

Put these lines inside the server { } block that serves your HTTPS site, or inside a specific location { } block. The always flag makes Nginx send the headers on error and redirect responses too. One catch: if a location block has its own add_header lines, it does not inherit headers from the server block, so repeat the lines there.

Test the config and reload Nginx.

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

# then run:
# sudo nginx -t && sudo systemctl reload nginx
Pro tip: If you already have an add_header Content-Security-Policy line, append ; frame-ancestors 'self' to that value instead of adding a second CSP header.
4

Or add them on Apache / .htaccess

On Apache, mod_headers must be enabled. On Debian/Ubuntu run sudo a2enmod headers. htaccess file in your web root.

Using always also covers redirect and error responses.

apache
<IfModule mod_headers.c>
  Header always set Content-Security-Policy "frame-ancestors 'self'"
  Header always set X-Frame-Options "SAMEORIGIN"
</IfModule>
Pro tip: If a plugin or app already sets a CSP, Header set will overwrite it. In that case, edit the existing policy to include frame-ancestors.
5

Or set them in Next.js / Vercel

js. This works on any host. *).

Redeploy afterwards.

javascript
// next.config.js
module.exports = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [
          { key: 'Content-Security-Policy', value: "frame-ancestors 'self'" },
          { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
        ],
      },
    ];
  },
};
Pro tip: If you set a full CSP in middleware with nonces, add frame-ancestors 'self' to that policy string. Otherwise the middleware header may replace the one from next.config.js.
6

Don't rely on a meta tag

Browsers ignore frame-ancestors when it appears in a meta http-equiv CSP tag. They also ignore X-Frame-Options set via a meta tag. The protection only works as a real HTTP response header.

If your platform only lets you edit HTML, set the header at a CDN or proxy in front of the site, such as Cloudflare.

html
<!-- This does NOT work for frame-ancestors -->
<meta http-equiv="Content-Security-Policy" content="frame-ancestors 'self'">
7

Purge caches and verify the result

Clear any page cache, plugin cache or CDN cache so the new headers are actually served. Then run curl against the homepage again and confirm at least one passing header appears. Finally, check that your own iframes still work, such as embedded widgets, page-builder previews and partner embeds.

text
curl -sI https://example.com | grep -iE 'x-frame-options|content-security-policy'
# expected:
# content-security-policy: frame-ancestors 'self'
# x-frame-options: SAMEORIGIN
Pro tip: Check in DevTools too: Network tab > click the document request > Headers > Response Headers.

Platform-specific notes

WordPress

WordPress core sends X-Frame-Options: SAMEORIGIN only on wp-login.php and wp-admin, not on public pages. Add the headers in Nginx or .htaccess, in a security plugin's headers setting, or with a send_headers hook in a small plugin: add_action('send_headers', function () { header("Content-Security-Policy: frame-ancestors 'self'"); header('X-Frame-Options: SAMEORIGIN'); }); Caching plugins that serve static HTML through .htaccess or Nginx skip PHP, so PHP-set headers can disappear on cached hits. Server-level headers avoid this.

Shopify

You cannot edit server headers on Shopify. Storefronts normally already send a frame-ancestors rule and/or X-Frame-Options themselves. If the check fails, test the exact domain with curl. A proxy or CDN in front of the store, or a custom domain pointing elsewhere, may be stripping the headers, and that is where you fix it.

Cloudflare

For hosts that don't allow custom headers, go to Rules > Transform Rules > Modify Response Header > Create rule. Match the hostname example.com, then add two Set static headers: Content-Security-Policy = frame-ancestors 'self' and X-Frame-Options = SAMEORIGIN. If the origin already sends a CSP, a Set operation replaces it, so copy the full existing policy into the new value.

Netlify

Add a _headers file to your publish directory with the line /* followed by indented lines: Content-Security-Policy: frame-ancestors 'self' and X-Frame-Options: SAMEORIGIN. A [[headers]] block in netlify.toml also works. Redeploy for it to take effect.

Wix / Webflow / Squarespace

These hosted builders do not let you set arbitrary response headers on standard plans. First check with curl whether the platform already sends X-Frame-Options or frame-ancestors. If it does not, the only option is a reverse proxy or CDN layer you control, or an enterprise plan with custom header support.

Check that it worked

✅ How to verify

  • Run curl -sIL https://example.com | grep -iE 'x-frame-options|content-security-policy' and confirm X-Frame-Options shows DENY/SAMEORIGIN or the CSP includes frame-ancestors.
  • In Chrome DevTools, go to Network, reload, select the main document and check Response Headers for the same values.
  • Create a test page on a different domain containing <iframe src="https://example.com"></iframe>. The console should report that framing was refused because of frame-ancestors or X-Frame-Options.
  • Re-run the audit and confirm the clickjacking protection check passes.

⚠️ Common mistakes

  • Setting frame-ancestors in a meta tag or in Content-Security-Policy-Report-Only, both of which leave the site unprotected.
  • Using X-Frame-Options: ALLOW-FROM, which modern browsers ignore and which does not pass the check. Use frame-ancestors with a list of origins instead.
  • Adding add_header in the Nginx server block when a location block has its own add_header lines, which silently drops the new headers for that location.
  • Overwriting an existing CSP at the CDN or .htaccess level and breaking script or style rules, instead of appending frame-ancestors to the current policy.

Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.

Check my site free

FAQ

Should I use X-Frame-Options or CSP frame-ancestors?

Use frame-ancestors as your main control. It is the current standard and supports multiple allowed origins. Add X-Frame-Options: SAMEORIGIN as a fallback for old browsers. When both are present, modern browsers follow frame-ancestors.

Will frame-ancestors break YouTube embeds or other iframes on my site?

No. frame-ancestors controls who can frame your pages, not which iframes your pages can load. Embedding YouTube, maps or forms is governed by frame-src/child-src, which this change does not touch.

What is the difference between frame-ancestors 'self' and 'none'?

'self' allows your own origin to frame the page, which some admin tools, previews and lightboxes need. 'none' blocks every site, including yours. Both pass the check. 'self' is the safer default unless you know nothing on your domain uses iframes of your own pages.

Do I need the header on every page or just the homepage?

The audit tests the homepage, but attackers target login, checkout and account pages. Apply the header site-wide, for example with Nginx server-level add_header, Apache Header always set, or a source of /(.*) in Next.js.