• 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 » Nginx Content Security Policy Example Syntax For Normal Websites

By Abhishek Ghosh September 6, 2016 12:05 am Updated on September 6, 2016

Nginx Content Security Policy Example Syntax For Normal Websites

Advertisement

We discussed about  Content Security Policy before –  Content Security Policy for adding report-uri. Readers are complaining that many sites are proving snippets which are throwing odd errors in Nginx, like nginx: [emerg] invalid number of arguments in “add_header”, nginx: [emerg] invalid parameter “self”, nginx: [emerg] unexpected “s”. So, Here is Nginx Content Security Policy Example Syntax For Normal Websites Which Will Not Throw Any Error.

 

Before Implementing Nginx Content Security Policy Example

 

You Can Use With Nginx Content Security Policy Example on Normal Website Only the Report Only Function. Honestly, you can not use Content Security Policy with Google AdSense or any Third Party Ads. It is an impractical idea to add header to prevent XSS attack. With so many browsers and devices, except loading webpage from 1 -2 sources it is just not possible. We are giving example of both.

 

Nginx Content Security Policy Example

 

Those websites providing wrong syntax for Nginx. This is a common way to add any header on Nginx :

Advertisement

---

Vim
1
add_header 'Your-Header-Name' 'header-policy value; pass-url https://thecustomizewindows.com';

The above will give this output upon curl -I header checking :

Vim
1
Your-Header-Name: header-policy value; pass-url https://thecustomizewindows.com

In that way, this is a perfect clean Nginx Content Security Policy Example :

Vim
1
add_header 'Content-Security-Policy' 'default-src self https; report-uri https://thecustomizewindows.com/';

You will get all resources on :

Vim
1
https://report-uri.io

… just register and use the tool. Suppose the web software suggested this :

Vim
1
Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src *; style-src *; ing-src *; font-src *; connect-src *; media-src *; object-src *; child-src *; frame-src *; worker-src *; frame-ancestors *; form-action *; upgrade-insecure-requests; sandbox allow-forms allow-same-origin allow-scripts allow-top-navigation allow-popups allow-pointer-lock; reflected-css block; base-url thecustomizewindows.com:443; manifest-src *; referrer no-referrer-when-downgrade; require-sri-for script style;

You can make it to this for nginx:

Vim
1
add_header 'Content-Security-Policy' 'default-src self unsafe-inline unsafe-eval; script-src *; style-src *; ing-src *; font-src *; connect-src *; media-src *; object-src *; child-src *; frame-src *; worker-src *; frame-ancestors *; form-action *; upgrade-insecure-requests; sandbox allow-forms allow-same-origin allow-scripts allow-top-navigation allow-popups allow-pointer-lock; reflected-css block; base-url thecustomizewindows.com:443; manifest-src *; referrer no-referrer-when-downgrade; require-sri-for script style';

It will avoid this error :

Vim
1
nginx: [emerg] unexpected "s" in /etc/nginx/sites-enabled/default

However, with the above some browsers may not allow anything expect text to load. We have tested may ways to only use Nginx Content Security Policy for protecting for XSS on websites with Third Party Ads running, has CDN. It is just not possible. Safari will load webpage without CSS, Images. Even this (notice default-src * unsafe-inline unsafe-eval) :

Vim
1
add_header 'Content-Security-Policy' 'default-src * unsafe-inline unsafe-eval; script-src *; style-src *; ing-src *; font-src *; connect-src *; media-src *; object-src *; child-src *; frame-src *; worker-src *; frame-ancestors *; form-action *; upgrade-insecure-requests; sandbox allow-forms allow-same-origin allow-scripts allow-top-navigation allow-popups allow-pointer-lock; reflected-css block; base-url thecustomizewindows.com:443; manifest-src *; referrer no-referrer-when-downgrade; require-sri-for script style';

…forces not to load any Google Ads on Safari.

Nginx Content Security Policy Example Syntax For Normal Websites

 

Nginx Content Security Policy Report Only Example (This is What You Can Use)

 

We are using this :

Vim
1
add_header 'Content-Security-Policy-Report-Only' 'default-src self https:; report-uri https://abhishekghosh.report-uri.io/r/default/csp/reportOnly';

If you run :

Vim
1
curl -I -s https://thecustomizewindows.com | grep "Content-Security-Policy-Report-Only"

You will get :

Vim
1
Content-Security-Policy-Report-Only: default-src self https:; report-uri https://abhishekghosh.report-uri.io/r/default/csp/reportOnly

The above is safe for your website as webmaster to apply on whole website. Except reporting it has no action. That method of reporting is not exactly easy though.

 

Use Content Security Policy Dynamically, Not One Rule For Whole Website

 

Checkout pages, payment pages needs more security. You can inject the restricted header on the must be under microscope webpages. WordPress /wp-login.php is one such webpage, if you have PHPMyAdmin, that is important to filter. You can use PHP to pass the header.

Tagged With nginx content-security-policy , content security polict nginx , Content-Security-Policy-Report-Only nginx , nginx content security policy best way , nginx add_header content-security-policy frame-ancestors , nginx add header content-security policy frame-ancesters , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1835 oH9IJTRwLmWnwbMESyDo2ftWJAuk5s_PSRyQnmzcfmFGzgwCtetkGzU7PwjDterr 9103a4d3891f6a1a9dba2d78a4141560feab13f8&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1831 qjKmgFZWeNahZ_oLTuO80XsSKiUOm7vm7wgXSQFU3pE_safil_PNcrpLu15UKrmf 8bbe99c8cbf34aaec66a24ffc7bb6cd8f4d90615&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1826 XfnuOHCDkh9XVhAYJLilY1F_5g95G9vN7ZpMmMVpYJa5y2HHp57joQEtDkx2mVO6 b100c4cca353da21bcb801221d604fb24351fa57&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , Content Security Policy report-uri webforms

This Article Has Been Shared 433 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 Nginx Content Security Policy Example Syntax For Normal Websites

  • SELinux and Security in the Context of Cloud Servers

    SELinux Was Developed By United States National Security Agency (NSA). SELinux and Security in the Context of Cloud Servers Can Be Questionable.

  • Security Concerns of Server Virtualization and Solutions

    Recent discovery of VENOM and related critical bugs in the Xen, KVM, and native QEMU virtual machine platforms again brought the topic Security Concerns of Server Virtualization in to lime light. VENOM was unknown, from Heartbleed, what we have learned is quite clear – frankly there is nothing to do with the unknown, undiscovered bugs […]

  • Logjam by NSA Threatens the Security of HTTPS

    Logjam, which allows man-in-the-middle attacker to downgrade the vulnerable TLS connections, apparently created by NSA Threatens the Security of HTTPS.

  • How to Add DMARC, DKIM, SFP to Avoid Email Spoofing

    Commonly, Transactional Email Services Like Mandrill is used With Google Apps. Here is How to Add DMARC, DKIM, SFP to Avoid Email Spoofing.

  • Fix Nginx OCSP ERROR : OCSP Response Expired

    Here is How to Fix Nginx OCSP ERROR – OCSP Response Expired After Enabling OCSP Stapling on Nginx. Error is Due to Certain Criterion of RFC.

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 Online Casinos Have No Deposit Bonus in Australia March 30, 2023
  • Four Foolproof Tips To Never Run Out Of Blog Ideas For Your Website March 28, 2023
  • The Interactive Entertainment Serving as a Tech Proving Ground March 28, 2023
  • Is it Good to Run Apache Web server and MySQL Database on Separate Cloud Servers? March 27, 2023
  • Advantages of Cloud Server Over Dedicated Server for Hosting WordPress March 26, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Nginx Content Security Policy Example Syntax For Normal Websites," in The Customize Windows, September 6, 2016, March 31, 2023, https://thecustomizewindows.com/2016/09/nginx-content-security-policy-example-syntax-normal-websites/.

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