Find problems in your Content Security Policy
A Content Security Policy lets you restrict what a page loads and runs. Allow too much and you can lose useful restrictions. Leave out a resource the page needs and the page can break.
Read the directives in your Content Security Policy
A directive names a rule, the values after it say what's allowed, and semicolons separate rules.
script-srccontrols scripts,style-srccontrols styles andconnect-srccontrols requests made through script interfaces.default-srcis the fallback for fetch directives you leave out.Rules such as
frame-ancestorsneed their own setting. A restrictivedefault-srcdoesn't decide who may embed your page. The policy reference explains which directives need separate settings.
Use nonces or hashes in your Content Security Policy
Use a nonce or a hash for inline scripts instead of broadly allowing
'unsafe-inline'. Create the nonce with a secure random generator on every request, and build a hash from the script's exact text, since capitalization and whitespace change it.Choose the method your rendering setup can maintain. The script directive reference explains both.
Roll out a Content Security Policy in report-only mode first
Content-Security-Policy-Report-Onlylets you see violations without enforcing that policy. Set up a reporting destination, review the violations and try the parts of the site people use before you enforce it.See the report-only header reference for reporting configuration.
Fix a "Refused to load the script" error from your Content Security Policy
- 1
Read the blocked address and the rule it violates
Read the error: it names the blocked address and the directive it violates. Confirm that the resource belongs on the page before changing the policy.
- 2
Correct the specific permission or script
Update the relevant source permission, nonce or hash. Don't replace a narrow rule with a wildcard just to silence the error.
Frequently asked questions
What happens if my site sends more than one policy?
The browser applies each policy independently. Adding a permissive policy doesn't relax the restrictions in another one.
Explore controls that work with your Content Security Policy
Website security
Catch leaked API keys and exposed files before someone uses them against you.
Security headers
Learn which response headers guide browser behavior and where to add them.
Clickjacking
Set framing rules so another site can't freely place your page behind its own controls.
Subresource Integrity
Use integrity hashes to tie an outside script or stylesheet to the contents you reviewed.
How to actually test your Content Security Policy
Test whether your Content Security Policy blocks unsafe scripts, handles third parties, and reports violations without breaking the site.