Why it matters
- A page any site may frame is open to clickjacking: another site loads it in a frame it hides over its own content, and a visitor who thinks they are clicking that site clicks a button on your page, such as buy, delete or share.
- A
frame-ancestorsdirective in aContent-Security-Policyheader says which sites may frame the page:'none'for none,'self'for your own site. It supersedesX-Frame-Options: when a response has both, browsers ignoreX-Frame-Options. X-Frame-Optionsdoes the same withDENYorSAMEORIGIN. ItsALLOW-FROMform is obsolete, and browsers ignore it.- Neither works from a
<meta>tag: browsers read both from the response's headers alone.
How to fix
Send frame-ancestors in your policy header, and X-Frame-Options for older browsers, which OWASP suggests:
http
Content-Security-Policy: frame-ancestors 'self'
X-Frame-Options: SAMEORIGIN- Apache (mod_headers):
Header always set X-Frame-Options "SAMEORIGIN", andframe-ancestors 'self'in yourContent-Security-Policy. - nginx:
add_header X-Frame-Options SAMEORIGIN always;, and the directive in your policy header. Alocationblock with anadd_headerof its own does not inherit those of theserverblock, so repeat them there. - Cloudflare: a Response Header Transform Rule that sets the headers.
- If the page already has a
Content-Security-Policy, add the directive to it, or send a second policy that holds it alone: browsers enforce every policy they receive. - Use
'none'andDENYif the page never belongs in a frame, even on your site. A page meant for other sites, such as a widget, names them:frame-ancestors https://partner.example.
How we detect
- The rule applies to HTML pages that answer 2xx on a public site. Local development hosts, such as
localhost, private addresses and names ending in.test, are left out, as for the HTTPS rule: the headers protect a public site's visitors. - The page passes with a
frame-ancestorsdirective in aContent-Security-Policyheader, read as browsers read the policy, unless its sources let any site in:*, a scheme alone such ashttps:, orhttps://*. Browsers then ignoreX-Frame-Options. AContent-Security-Policy-Report-Onlyheader and a<meta>do not count. - Otherwise we read
X-Frame-Optionsas the HTML standard says: all its values, split at commas and lowercased. A singleDENYorSAMEORIGINpasses. Different values that includeDENY,SAMEORIGINorALLOWALLmake browsers refuse every frame, so they pass too. Any other value,ALLOW-FROMamong them, is ignored. - A
<meta>that tries either one is named in the findings.