Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Config your IIS server to use the "Content-Security-Policy" header

Tags:

I need to add custom headers in IIS for "Content-Security-Policy", "X-Content-Type-Options" and "X-XSS-Protection".

I get the procedure to add these headers but i am not sure what should be the value of these keys. https://technet.microsoft.com/pl-pl/library/cc753133(v=ws.10).aspx

http://content-security-policy.com/

Please suggest. Thanks

like image 944
Gurmeet Avatar asked Jun 23 '16 12:06

Gurmeet


People also ask

How do I fix HTTP security header not detected in IIS?

Open IIS server host Manager. Go to HTTP Response Headers. Click Add and enter X-Content-Type-Options in the name entry, and nosniff in the value. Select OK to effect change.


2 Answers

From this post, it would seem that you define your Content Security Policy (and, in turn, populate those headers) directly in your IIS configuration file. The example given in the linked post,

<system.webServer>     <httpProtocol>         <customHeaders>             <add name="Content-Security-Policy" value="default-src 'self';" />         </customHeaders>     </httpProtocol> </system.webServer> 

demonstrates how to do this; in your config file, in the httpProtocol section, add an entry to the customHeaders collection containing the name (i.e. "Content-Security-Policy" and a value defining the CSP you wish to implement. In the example given, a very simple CSP is implemented, which only allows resources from the local site (self) to be loaded.

The second resource you linked lists the different options you can use in your customHeader, and examples of their valid values. The one thing to remember is that subsequent options must be ;-separated, and the string must end in a final ;.

like image 63
F. Stephen Q Avatar answered Sep 20 '22 13:09

F. Stephen Q


An old question but since google drops you here...

I found a great "builder" for CSP options:

https://report-uri.io/home/tools/

Now this does appear to be a "link only answer" but in fact, the link is a fully built CSP editor, you click the boxes, select your websites you need in your CSP and the CSP string comes back configured for you (just copy and paste the result into your header for Content-Security-Policy). I couldn't HOPE to replicate the functionality in this answer hence the link.

like image 32
AngryCarrotTop Avatar answered Sep 21 '22 13:09

AngryCarrotTop