I've built a web application (with my favourite language Fantom!) and am in the process of locking it down from XSS and other such attacks by supplying industry standard HTTP response headers.
My question is, for which responses should the headers be set?
I could set the headers for every response, but that seems pretty wasteful given most requests will be for images, fonts, stylesheets, etc.. The Content-Security-Policy
header in particular can get quite lengthy.
As a lot of the headers relate to the owning HTML page (and the Javascript contained within), I get the feeling most of them need only be set for HTML pages.
I've looked at various resources such as:
And while they explain what the headers do, they don't explain for which resources they should be used and served for!
I've made a list below of HTTP response headers and for which Content-Types
I think they should be served with. But does anyone know if this is correct?
HTTP Response Header text/html All Content-Types
------------------------- --------- -----------------
Content-Security-Policy X
Referrer-Policy X
Strict-Transport-Security X
X-Content-Type-Options X
X-Frame-Options X
X-XSS-Protection X
(When I say text/html
I also include application/xhtml+xml
.)
Referrer-Policy
is under all content types due to CSS being able to load fonts and images.