Does Content-Security-Policy
ignore X-Frame-Options
, returned by a server, or is X-Frame-Options
still primary?
Assuming that I have:
- a website http://a.com with
X-Frame-Options: DENY
- and a website http://b.com with
Content-Security-Policy: frame-src a.com
will browser load this frame?
It is unclear.
On the one hand, http://a.com explicitly denies framing.
On the other hand, http://b.com explicitly allows framing for http://a.com.
The
frame-src
CSP directive (which is deprecated and replaced bychild-src
) determines what sources can be used in a frame on a page.The
X-Frame-Options
response header, on the other hand, determines what other pages can use that page in an iframe.In your case,
http://a.com
withX-Frame-Options: DENY
indicates that no other page can use it in a frame. It does not matter whathttp://b.com
has in its CSP -- no page can usehttp://a.com
in a frame.The place where
X-Frame-Options
intersects with CSP is via theframe-ancestors
directive. From the CSP specificiation (emphasis mine):An older question indicated this did not work in Firefox at that time but hopefully things have changed now.
UPDATE April 2018:
Looks like
child-src
is now the deprecated one andframe-src
is back.None of your hypotheses are universally true.
X-Frame-Options
.frame-ancestors
.frame-ancestors
directive, but prioritizeX-Frame-Options
if both are specified.The answer was found by testing in practice.
I have created two web-sites and reproduced the described situation.
It seems like X-Frame-Options is primary.
If target server denies framing, then client website cannot display this page in
iframe
whichever values ofContent-Security-Policy
are set.However, I haven't found any confirmations in documentation.
Tested on Chrome 54 and IE 11.