Prevent clickjacking with X-Frame-Options / frame-ancestors
अपडेट: 1 दिस॰ 2026
यह गाइड अभी अंग्रेज़ी में है।
What it means
Your pages can be embedded inside another website in an invisible frame. An attacker can overlay buttons on top of your page and trick users into clicking things they did not intend (clickjacking).
Why it matters
Signed-in customers could be tricked into changing settings, approving payments or deleting data on your site.
How to fix it
- Send X-Frame-Options: DENY (or SAMEORIGIN if you frame your own pages).
- Also set the modern equivalent in CSP: frame-ancestors 'self'.
- If a partner legitimately embeds your page, allow only that origin via frame-ancestors.
Configuration examples
nginx
add_header X-Frame-Options "SAMEORIGIN" always;
Apache
Header always set X-Frame-Options "SAMEORIGIN"
IIS (web.config)
<add name="X-Frame-Options" value="SAMEORIGIN" />
Cloudflare
Rules -> Transform Rules -> Modify Response Header -> Set static: X-Frame-Options = SAMEORIGIN
Node.js / Express
app.use(helmet.frameguard({ action: 'sameorigin' }));
Django (settings.py)
X_FRAME_OPTIONS = 'SAMEORIGIN' # XFrameOptionsMiddleware must be enabled
Laravel / PHP
$response->headers->set('X-Frame-Options', 'SAMEORIGIN');
Any platform
X-Frame-Options: SAMEORIGIN
Check your fix
curl -sI https://YOUR_DOMAIN | grep -i -E "x-frame-options|frame-ancestors"
References
- https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Frame-Options
- https://owasp.org/www-community/attacks/Clickjacking