Refused to load the script xxxxxx because it violates the following Content Security Policy directive: "Script-src ' self ' x Xxxxxxxxxxxx "Browser security issues

Source: Internet
Author: User
Tags nginx server

Today in the company ran into a problem like this: the general problem is that I put the newly generated foreign CDN path to the page to view, and found that there will be similar to the following error message

Refused to load the script xxxxxx because it violates the following Content Security Policy directive: "Script-src ' self ' x Xxxxxxxxxxxx "

The original picture is gone, I posted this picture on the blog of Ruan Yi Peak, this problem is mainly due to the browser in order to prevent cross-domain scripting attacks, and the introduction of "Web Security Policy" (Content security Policies, abbreviated CSP),

And my nginx server opened the CSP, so the resources under another domain name cannot start the JS script.

The meaning of CSP is as follows:

#激活内容安全策略Content Security Policy (CSP), most browsers support
# tell the browser to download scripts only from this domain name and the URL you explicitly specify.

Next is to modify the Nginx configuration, understand the following concepts, I found the original Unsafe-inline point to the CDN domain name, using the wildcard * so that all the two-level domain names are compliant with Unsafe-inline

Last Access Successful!

Summary: First you have put the resource file into the server, the configuration of Nginx, can run normally, you want to make a limit to the browser, want to make a safe, do not want to let outsiders on your website inject virus script, so you add Add_header on Nginx configuration Content-security-policy, write the URL you need to access, so you can complete the CSP.

Refused to load the script xxxxxx because it violates the following Content Security Policy directive: "Script-src ' self ' x Xxxxxxxxxxxx "Browser security issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.