Check 05 · FRAME
Framing protection
Content-Security-Policy frame-ancestors, X-Frame-Options
Framing protection decides which sites may show your pages inside a frame. Without it, any site can.
What it does
A site that can frame your page can make it invisible and place it over its own buttons. Visitors think they're clicking the other site, but they're clicking yours, while signed in to it: changing a setting, confirming a payment, granting access (clickjacking).
Two headers control framing. The frame-ancestors directive of a Content-Security-Policy is the current one and lists exactly who may frame your pages. X-Frame-Options is older and only knows DENY and SAMEORIGIN. When a policy has frame-ancestors, browsers ignore X-Frame-Options.
How we score it
| 20 | frame-ancestors with 'none', 'self' and/or explicit hosts, or (without frame-ancestors) X-Frame-Options: DENY or SAMEORIGIN. |
|---|---|
| 10 | frame-ancestors with a wildcard host such as https://*.example.com. |
| 0 | frame-ancestors with * or a scheme-only source like https:; X-Frame-Options with ALLOW-FROM, conflicting or invalid values; or nothing at all. |
An enforced frame-ancestors in a Content-Security-Policy header takes precedence, because browsers then ignore X-Frame-Options. frame-ancestors in a <meta> tag or a report-only policy never counts.
All five checks and the grade scale: How grading works.
Examples
- Content-Security-Policy: frame-ancestors 'none'
20 / 20 · Strong No site may frame your pages, not even your own.
- Content-Security-Policy: frame-ancestors 'self' https://partner.example.net
20 / 20 · Strong Your own site and one named partner.
- Content-Security-Policy: frame-ancestors https://*.example.com
10 / 20 · Partial Every subdomain of a domain, including ones that may be set up later.
- Content-Security-Policy: frame-ancestors *X-Frame-Options: DENY
0 / 20 · Weak
frame-ancestors *allows every site, and browsers ignore theDENYnext to it. - X-Frame-Options: SAMEORIGIN
20 / 20 · Strong Only your own pages may frame them.
- X-Frame-Options: ALLOW-FROM https://partner.example.net/
0 / 20 · Weak Current browsers ignore
ALLOW-FROM, so any site can frame the page. - Content-Security-Policy-Report-Only: frame-ancestors 'none'
0 / 20 · Missing Report-only: framing is reported, not blocked.
How to set it
If you already send a Content-Security-Policy, add frame-ancestors 'self' to it rather than sending a second policy. Use 'none' if your pages are never framed, not even by your own site.
Keep X-Frame-Options next to it for very old browsers. List named hosts in frame-ancestors when partners need to embed your pages.
Nginx
Put this in the server block. A location block with its own add_header lines doesn’t inherit these, so repeat them there.
add_header Content-Security-Policy "frame-ancestors 'self'" always;
add_header X-Frame-Options "SAMEORIGIN" always;Apache
In the virtual host or .htaccess. Needs mod_headers (on Debian and Ubuntu: a2enmod headers).
Header always set Content-Security-Policy "frame-ancestors 'self'"
Header always set X-Frame-Options "SAMEORIGIN"Caddy
Inside your site block in the Caddyfile.
header {
Content-Security-Policy "frame-ancestors 'self'"
X-Frame-Options "SAMEORIGIN"
}Cloudflare
Rules → Create rule → Response Header Transform Rule. Apply to all incoming requests, choose “Set static”, and enter each header below.
Header name: Content-Security-Policy
Value: frame-ancestors 'self'
Header name: X-Frame-Options
Value: SAMEORIGINCommon mistakes
- Putting
frame-ancestorsin a<meta>tag. Browsers ignore it there; it only works as a header. - Using
X-Frame-Options: ALLOW-FROMto allow a partner. Useframe-ancestorswith their host instead. - Sending
DENYandSAMEORIGINtogether. Browsers can't tell which one you mean.