• 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
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

  • Nginx WordPress Configuration Sample File

    Here is Ready to Use Nginx Wordpress Configuration Sample File Which Can Used With Either Community Edition of Nginx or Nginx Plus & PHP5-FPM.

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Add Content Security Policy (CSP) Header in 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.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

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

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
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