• 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 634 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 (22.1K 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

  • Ways To Make Sure Your Online Course Outshine Others July 3, 2022
  • Will Smart Factories Become the New Assembly Line? July 2, 2022
  • The Cost of Doing Business as a Handyman July 1, 2022
  • Samsung Galaxy S22 Ultra: Long Term Review June 30, 2022
  • How to Make the Most of Your S Pen (S22 Ultra) June 29, 2022

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, July 3, 2022, https://thecustomizewindows.com/2016/09/nginx-content-security-policy-example-syntax-normal-websites/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

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

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

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