0

-Mac

-Apache

-PHP7

-Wordpress

I want to serve a lenient CSP to my self and another person(s), but have a strict CSP for everyone else. The code I currently use works when I just use my own IP, but I can't figure out how to add another. I'm a beginner at all of this so keep that in mind. I found them for this snippet here

And here is my code:

<IfModule mod_headers.c>
# Serve CSP based on client IP
<If "-R 'MY IP'">
  Header always set Content-Security-Policy "default-src 'self'; script-    src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src * data:; object-src 'none'; font-src 'self' data:"
</If>
JLB
  • 11
  • 4

1 Answers1

0

Instead of setting it from Server settings, output the CSP headers from your site’s code. You can then easily vary your headers based on who is logged in, or any other criteria you choose.

EDIT TO ADD: PHP can send CSP headers via the header() function --secure.php.net/manual/en/function.header.php . For example:

header( "Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src * data:; object-src 'none'; font-src 'self' data:" );

Stephen R
  • 3,512
  • 1
  • 28
  • 45