Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Refused to display in a frame because it set X-Frame-Options: what it means and the safe fix

You embed a page in an iframe and the console says: Refused to display 'https://app.example.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'. Refused to frame 'https://app.example.com/' because an anc

You embed a page in an iframe and the console says:

Refused to display 'https://app.example.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
Refused to frame 'https://app.example.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

What it means

The page you are framing tells the browser not to let other sites embed it. It does this with the X-Frame-Options header (DENY or SAMEORIGIN) or with the CSP directive frame-ancestors. This is clickjacking protection working as designed.

Why it happens

  • The site sends X-Frame-Options: DENY or SAMEORIGIN.
  • The site's CSP has frame-ancestors 'none' or 'self'.
  • Login and payment pages from third parties always refuse framing.

The fix, if you own both sites

On the site being framed, replace X-Frame-Options with an explicit allowlist of the parent origin:

Content-Security-Policy: frame-ancestors 'self' https://dashboard.example.com

Keep frame-ancestors 'none' on pages that should never be framed: login, settings, checkout.

The fix, if you do not own the framed site

You cannot override it. Link to the page, or use the provider's official embed.

What not to do

  • Do not just delete X-Frame-Options. Without frame-ancestors, any site can overlay your app and trick users into clicking.
  • Do not put frame-ancestors in a <meta> tag. Browsers ignore it there. It must be an HTTP response header.
  • If both headers are set, browsers that support frame-ancestors use it and ignore X-Frame-Options.

Check it worked

The embed loads on your allowed origin, and the page still refuses to load inside an iframe on any other site. You can look at your live headers with the free checker: https://proofforge.live/tools/security-headers-checker

Full write-up with the exact error text: https://proofforge.live/errors/refused-to-display-in-frame

If you built the app with an AI tool and want to know what else it exposes to strangers (browser keys, open tables, public files), ProofForge runs a free read-only scan on an app you own: https://proofforge.live

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.