Securing NGINX - Fedora/RedHat

Step 3g - Content Security Policies - Highly Highly Recommended!!

Create/Enable Content Security Policies (CSP)

Content security policies are enacted by most of the larger content providers to minimize the amount of reloading of information. When if fact, it really is a great security measure to ensure that only our site is providing clients with content from our own sources and not someone else injecting code, malware and a vast array of other possibilities to perform against a site/server/client. It should be noted that less than one percent (1%) of the Internet has such policies and makes it easy to put my own source code in the middle of a communication stream. It is not mandatory since there are situations in which you do not wish to use CSP's at the server level. Unless you are an admin that understands those methods and implementations, use this procedure until you move the CSP to another area.

Scott Helme developed some nifty tools to help you generate a policy, analyses your policy or generate a hash of JS or CSS for your CSP

Change the HTTPS Web site config file <--Add the sections in blue to the file

nano /etc/nginx/conf.d/EXAMPLE_com_ssl.conf

server {
        etag off;
        add_header X-Content-Type-Options nosniff always;
        add_header X-XSS-Protection "1; mode=block; report=<uri>" always;
        proxy_cookie_path / "/; HTTPOnly:Secure" always;
        add_header Referrer-Policy no-referrer-when-downgrade always;
        add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'" always;
        add_header NEL "{\"Report-To\":\"default\",\"max_age\":31536000,\"include_subdomains\":true}" always;
        add_header X-Frame-Options DENY always;
        add_header Cache-Control "public, max-age=31536000" always;
        add_header MyHeader "Feel safe zombiesecured headers in use!!! It took %D microseconds for Zombiesecured to serve this request on %t";
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
        add_header Expect-CT enforce, max-age=30, report-uri="url" always;
        add_header Content-Security-Policy "Policy" always; <--- Put your policy parameters between the quotes - remove any redundancies

Close and exit the file

ctrl + o   (Save)
ctrl + x   (Exit)

Restart NGINX

systemctl restart nginx

Zombie Secured Headers in use:

Header always set Content-Security-Policy: "script-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; connect-src 'self'; media-src 'self'; object-src 'self'; frame-ancestors 'none'; form-action 'self'" always;

Zombie Content Security Policy Test Results

Zombie Content Policy