HTTP Headers - Content Security Policy

alewisa

Ars Scholae Palatinae
779
Anyone have expertise with HTTP headers, specifically Content-Security-Policy?

I'm trying to set CSP on a couple of sites, to improve protection to a hosted application, and running into issues with Chrome and Firefox. Server is IIS 8.5. The app is written around aspx, and uses java scripts. I cannot tweak the app (eg set options in a <meta> tag).

Setting C-S-P default-src 'self' causes the browser to render incorrectly, loses page layout, and both browsers to complain that CSP prevents in-line scripts from running. setting default-src 'self' https://mydomain.com has same effect

Adding other directives to 'fine tune' the policy has much the same result (e.g. script-src, manifest-src

setting the 'unsafe-eval' flag causes Chrome to suggest using 'unsafe-inline'. But setting that causes Chrome to complain that scripts cannot be run as they are blocked by the CSP...!

Brief and sketchy as I am at home, just testing the water and hoping :)
 

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
Anyone have expertise with HTTP headers, specifically Content-Security-Policy?

I'm trying to set CSP on a couple of sites, to improve protection to a hosted application, and running into issues with Chrome and Firefox. Server is IIS 8.5. The app is written around aspx, and uses java scripts. I cannot tweak the app (eg set options in a <meta> tag).

Setting C-S-P default-src 'self' causes the browser to render incorrectly, loses page layout, and both browsers to complain that CSP prevents in-line scripts from running. setting default-src 'self' https://mydomain.com has same effect

Adding other directives to 'fine tune' the policy has much the same result (e.g. script-src, manifest-src

setting the 'unsafe-eval' flag causes Chrome to suggest using 'unsafe-inline'. But setting that causes Chrome to complain that scripts cannot be run as they are blocked by the CSP...!

Brief and sketchy as I am at home, just testing the water and hoping :)

The question you need to ask is: where does the app get it's stuff from. My guess: it is reading the css from someplace other than your server. Then you need to whitelist those domains. The line should be something like:

Code:
Content-Security-Policy: default-src self css-source-domain.com cdn.my-cdn.com; script-src wherever-it-gets-jquery.com

You might need to use wildcards in some of those places.
 

KallDrexx

Ars Tribunus Militum
2,040
CSP is a pain, I went through the same thing not too long ago. Like Lt_Storm says you'll have images, fonts, and things like that causing blockages, not just scripts. You'll pretty much need to scrutinize the Chrome dev console as it will tell you exactly what broke and what rule needs to be tweaked. It's just a matter of playing whack-a-mole from there.

If you have enough Firefox users and have good logging infrastructure then you can also try using Content-Security-Policy-Report-Only in production. That will give you violations that affect real users and allow you to tweak based on that.