I have a webpage (say origin=A) that has an iframe embedded in it which loads from a different domain (say B). B loads bunch scripts from different domains (various CDNs). My webpage A sets pretty strict CSP like:
default-src 'none'; script-src 'self'; frame-src B
B doesn't set any CSP headers.
Now I would expect the child frame, B, to inherit the CSP rules of A and trying to access various CDNs should be a violation of its CSP because of script-src 'self' but to my surprise, it works smoothly.
So my question is: How CSP is inherited by child iframes ? Does it depend on its parent frame's CSP if CSP for iframe is not mentioned ? If yes, how ? Is there any documentation somewhere about it, I couldn't find anything specific that would explain the situation above.
Is there a way I can debug the CSP inherited by child iframes ? From Chrome's debugger or FF's debugger - by selecting the iframe and then CSP for the iframe would show up ?
It’s not. That is, not in the common case (the “loads from a different domain” case in the question).
But there are other ways to populate
iframe
, and CSP works different in those cases (see below).No, it doesn’t for the common case (the “loads from a different domain” case given in the question).
Yes, see the Policy applicability section of the CSP2 specification, which says this:
A “globally unique identifier” is something with a
data:
URL or other kind of URL that’s not a hierarchical URL such anhttps
/http
URL.So the common case (described as “loads from a different domain” in the question) is a “embedded resource is controlled by the policy delivered with the resource” case—that is, it doesn’t inherit.
In contrast, if the
iframe
is asrcdoc
iframe, the case is very different and the spec says:That is a
srcdoc
iframe does inherit its parent’s CSP policy.