The W3C spec for Content-Security-Policy or Mozilla CSP docs would be the definitive source for this answer, but it does not seem covered, so I'm asking here for answers based on people's experience. If my understanding is correct, then I'll probably contact the W3C spec authors.
My understanding is that browsers have implemented their CSP engines as an extension of the page DOM; ie a CSP is associated with a page, not with a request / response.
Under my understanding, a CSP delivered in the following ways is useful:
- As an HTTP response header (or
<meta>
tag) on top-level HTML content. - As an HTTP response header (or
<meta>
tag) on nested / framed content (I assume this would fall under section 3.4: Enforcing multiple policies, and would further restrict the first CSP) - As a
<meta>
tag in addition to an HTTP response header in either of the above (I assume this would fall under section 3.4: Enforcing multiple policies, and would further restrict the first CSP).
Under my understanding, a CSP delivered in the following ways is useless; ie completely ignored by the browser and a waste of bandwidth:
- As an HTTP response header on content that is not HTML (ie on a response that is
Content-Type: text/javascript
,application/json
,text/css
,text/plain
,application/gzip
,image/jpeg
, etc).
So I guess I have two questions here:
- Does it do anything to put a CSP header responses that are not web pages (ie on REST APIs, files, javascript, etc)?
- Is this mentioned anywhere in the W3C spec (and I can't read), or would it be worth asking the authors to add a section "3.x: Applicable content types") ?