Welcome! Log In Create A New Profile

Advanced

How to set a conditional Content-Security-Policy?

Anonymous User
March 27, 2018 12:52PM
For my nginx server, I set a CSP header

set $CSP '';
set $CSP "${CSP}default-src 'self';";
set $CSP "${CSP}script-src 'self';";
add_header Content-Security-Policy $CSP;

For a webapp, using Symfony, the developer UI injects inline script for display of a "Debug Toolbar"

It's access-blocked by that^ server policy.

Changing

- set $CSP "${CSP}script-src 'self';";
+ set $CSP "${CSP}script-src 'self' 'unsafe-inline';";

fixes the problem -- access the debug toolbar is allowed, and it's rendered.

But, adding the 'unsafe-inline' is certainly not ideal!

Apache has the option to create/return a CSP policy depending on Request IP:

https://blog.paranoidpenguin.net/2017/12/deploy-different-content-security-policies-csps-using-the-apache-if-directive/

How would the equivalent be done in nginx config?

Iiuc, there's no if/then/else construct.

Something with maps maybe?

Hal
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to set a conditional Content-Security-Policy?

Anonymous User March 27, 2018 12:52PM

Re: How to set a conditional Content-Security-Policy?

Maxim Dounin March 27, 2018 01:28PM

Re: How to set a conditional Content-Security-Policy?

Anonymous User March 27, 2018 01:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 105
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready