CSP2 section you refer is not normative, therefore browsers have own implementations. As tests shown, the <frame src=data:-URL
, <frame src=blob:-URL
and <frame src=javascript:-URL
inherit parent document CSP.
This way you will have 2 CSPs in the iframe: iframe's own and parent's one.
Moreover in Firefox 52.9 OSR (CSP3-browser) CSP was propagate from the iframe to the parent document.
srcdoc-frame has more specifics:
- In terms of SOP, srcdoc=, as inline HTML to embed, inherits the origin from the document that loaded such iframe.
- The content from srcdoc= is part of the parent document, so the CSP of the parent document applies, but
frame-src
directive is not applied to it.
- scripts in the
<iframe srcdoc=>
are executed in the parent context.
Demos for <iframe src=>CSP inheritance into <iframe srcdoc='some HTML'></iframe></iframe>
structute
Below is a demo for CSP inheritance into nested <iframe scrdoc>
:
<iframe src="data:text/html;charset=utf-8,<head>
<meta http-equiv='Content-Security-Policy' content="default-src 'none'; script-src 'none'; style-src 'none';"
</head>
<body>
&lt;meta CSP=default-src 'none'; script-src 'none'; style-src 'none';&gt;
<br>
<iframe srcdoc="<head></head>
<body>
content over <em>srcdoc=</em>: <span style='color:blue;'>this should be in blue</span>
<br>
some content inserted over JS: <span id='span'><font color='silver'>failed</font></span>
<script>
document.getElementById('span').innerHTML = 'Done!';
document.getElementById('span').style.color = 'green';
</script>
</body>
" width=300 height=80></iframe>
<body>
" width=400 height=150></iframe>
As you can see, inline style and inline script are blocked, the violation messages appear in the browser console.
Pls note that frame-src
directive is omitted and its fallback default-src
directive is set to 'none
' (means embedding iframes are prohibited). But <iframe srcdoc=> is successfully embedded.
Lets compare with the the same test but without <meta CSP>
:
<iframe src="data:text/html;charset=utf-8,<head>
</head>
<body>
without &lt;meta CSP&gt;
<br>
<iframe srcdoc="<head></head>
<body>
content over <em>srcdoc=</em>: <span style='color:blue;'>this should be in blue</span>
<br>
some content inserted over JS: <span id='span'><font color='silver'>failed</font></span>
<script>
document.getElementById('span').innerHTML = 'Done!';
document.getElementById('span').style.color = 'green';
</script>
</body>
" width=300 height=80></iframe>
<body>
" width=400 height=150></iframe>
As you can see, inline style is applied and inline script is executed.