• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Add Content Security Policy (CSP) Header in Nginx With report-uri

By Abhishek Ghosh August 17, 2016 2:45 pm Updated on August 17, 2016

Add Content Security Policy (CSP) Header in Nginx With report-uri

Advertisement

In the previous guide, we talked about how to around HTTP Public Key Pinning (HPKP) Nginx With report-uri. Content Security Policy (CSP) header adds control over the resources to be loaded on modern browsers to increase security. Here is How to Add Content Security Policy Header in Nginx.

Table of Contents

  • 1 Introduction
  • 2 What is Content Security Policy (CSP) Header?
  • 3 How To Add Content Security Policy (CSP) Header in Nginx
  • 4 Content Security Policy Example

 

What is Content Security Policy (CSP) Header? Why We Need CSP?

 

As like the most current recommendations and Standards related to frontend security, Content Security Policy (CSP) is for HTTPS website. That should not be a concern anymore as Let’s Encrypt provides forever free SSL certificates and no longer inferior choice compared to the paid DV SSL certificates.

Advertisement

---

With the Content Security Policy (CSP) Header, web site administrators can use combination of directives that can be used to suit their web site’s needs. Content source is a string which indicates a possible source from which content or type allowed to be loaded. Source list is a string specifying Internet hosts by domain name (read FQDN) or IP address, URL scheme and/or port number. There is also optional report-uri used for CSP violation reports. The report-uri must be of different FQDN than that of the applied policy. Content Security Policy (CSP) specification is currently of version 2 (at the time of writing this guide) and W3C Candidate Recommendation, dated 21st July 2015.

Most of the blogging softwares like WordPress or content management system like Drupal, Joomla! needs Content Security Policy (CSP) Header as their backend is either LAMP server or LEMP server i.e. uses PHP as dynamic programming language and has a database. PHP and MySQL combination, unlike plain static HTML serving websites has vulnerabilities. It is not difficult to get access via PHP shell by the script kiddies. Technically risk increases when there is self hosted web form on a webpage. Ping, Trackback etc also increases risk. Obviously, the forum softwares also need Content Security Policy (CSP) Header. Content Security Policy (CSP) Header can decrease the chance of Javascript malware, XSS attacks to mention few of its original target.

However, Content Security Policy (CSP) Header is highly restrictive. Without proper understanding and testing, websites with Google AdSense Ads may end up getting all the Ads blocked. CORS header itself restrictive.

 

How To Add Content Security Policy (CSP) Header in Nginx With report-uri?

 

This is an example header output upon running curl -I followed by domain name :

Vim
1
Content-Security-Policy: default-src 'self' trusted.example.com;

to get the above response, we need to add the following to /etc/nginx/sites-available/default website configuration file or any modified named file in /etc/nginx/sites-available/ directory :

Vim
1
add_header Content-Security-Policy "default-src 'self' trusted.example.com;";

Note that ;"; ending. First semi-colon is for Content Security Policy (CSP), second is for Nginx. Also, website name is not enclosed inside ' '.

Reporting URI can be used with a free service like that report-uri.io as like described in our other similar topic – HTTP Public Key Pinning (HPKP) Nginx With report-uri.

Add-Content-Security-Policy-(CSP)-Header-in-Nginx-With-report-uri

 

Content Security Policy Example

 

The Content Security Policy header value is made up of one or more directives. Below are the authoritative source of Content Security Policy (CSP) directives :

Vim
1
2
3
4
5
6
7
8
# mozilla
https://developer.mozilla.org/en/docs/Web/Security/CSP/CSP_policy_directives
https://hacks.mozilla.org/2016/02/implementing-content-security-policy/
# w3c
http://www.w3.org/TR/2012/CR-CSP-20121115/
# others
http://caniuse.com/contentsecuritypolicy2
https://content-security-policy.com

The interesting directives which are holding promise for higher security on client side are –

upgrade-insecure-requests directive instructs user agents to automatically upgrade all insecure resource requests from their pages to secure variants. The URL will be rewritten before the request is made, meaning that no insecure requests will hit the network. Example :

Vim
1
Content-Security-Policy: upgrade-insecure-requests

This is a bigger topic :

Vim
1
https://w3c.github.io/webappsec/specs/upgrade/

report-uri directive instructs the user agent to report attempts to violate the Content Security Policy. These violation reports consist of JSON documents sent via an HTTP POST request to the specified URI.

‘unsafe-eval’ allows the use of eval() and similar methods for creating code from strings. This must be used after understanding the legit Javascripts. In other words we do not recommend blindly add it.

reflected-xss directive instructs the user agent to activate or deactivate any heuristics used to filter or block reflected cross-site scripting attacks with any of the values – allow, block, filter. Allow is expected for co-operation.

Vim
1
add_header Content-Security-Policy "upgrade-insecure-requests; ";

Tagged With content security policy header , nginx content security policy , Content-Security-Policy nginx , content-security-policy header , content security policy nginx , nginx csp , nginx add_header Content-Security-Policy , add_header Content-Security-Policy , csp examples drupal nginx ,  Content­Security­Policy header

This Article Has Been Shared 706 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Add Content Security Policy (CSP) Header in Nginx With report-uri

  • HHVM WordPress (Nginx Ubuntu Server) Tweaks

    Here are some special HHVM Wordpress (Nginx Ubuntu Server) Tweaks for Page Speed optimization, Compatibility of WordPress Themes and Plugins.

  • Steps To Install Nginx Plus on Ubuntu Server (HP Cloud)

    Here Are the Steps To Install Nginx Plus on Ubuntu Server Running on HP Cloud. Nginx Plus is the Paid Version of Nginx with Extra Features.

  • Zend Opcache Optimization for Nginx Ubuntu (HP Cloud)

    Here is Full Guide to Zend Opcache Optimization for Nginx PHP5-FPM for Ubuntu Server Running on HP Cloud. We Suggest to Use Zend Opcache over APC.

  • Enable Nginx PHP-FPM Status Page (Ubuntu, HP Cloud)

    Here is How To Enable Nginx PHP-FPM Status Page on Ubuntu Server Instance Running on HP Cloud. Enabling Ping Has Difference With Enabling Status.

  • Nginx WWW to No WWW & HTTP to HTTPS

    Basic, Yet Many New Users Fight With Nginx WWW to No WWW & HTTP to HTTPS Rules on Cloud Server Instance Running Debian/Ubuntu GNU/Linux.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Configuration Management February 5, 2023
  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Add Content Security Policy (CSP) Header in Nginx With report-uri," in The Customize Windows, August 17, 2016, February 6, 2023, https://thecustomizewindows.com/2016/08/add-content-security-policy-csp-header-nginx-report-uri/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT