How to modify Content-Security-Policy and other response headers
To change a response header such as Content-Security-Policy in Chrome or Edge, add a response header row in HeaderDial for the site you are debugging. Choose remove to drop the header, or set with a new value to replace it. The browser then behaves as if the server had sent your version, so you can test a policy change in seconds instead of redeploying.
When this helps
- "Refused to load the script… because it violates the Content Security Policy". Remove the CSP briefly to confirm the policy is the cause, then put back an edited policy that allows the source you need.
- Writing a new policy. Try it on the live site before asking for a deployment.
- Embedding in an iframe. A page refuses to load in a frame because of
X-Frame-Optionsor the CSPframe-ancestorsdirective, and you want to test the embedding on your own site before the owner changes it. - Other response headers. Test
Cache-Control,Set-Cookieattributes,Permissions-PolicyorCross-Origin-*headers the same way.
Steps
- Open the site, then click the HeaderDial icon. If the site-access banner appears, choose Only <current host> or Allow on all sites.
- Click + Response header and type
Content-Security-Policy. - To drop it, pick remove in the operation select. To replace it, keep set and paste the full new policy as the value, for example:
default-src 'self'; script-src 'self' https://cdn.example.net; img-src 'self' data: - Click + Only on <current host> under Where it applies. Changing security headers on every site you visit is never what you want.
- Hard-reload (Ctrl+Shift+R) and watch the DevTools Console: CSP violations are logged there with the directive that blocked them.
For framing problems, add two rows: remove X-Frame-Options, and remove or replace Content-Security-Policy. Modern browsers give frame-ancestors precedence over X-Frame-Options, so removing only the older header is often not enough. Response headers apply to whatever response matches the filter, so put the filter on the framed site's domain, not the parent page's. We measured each combination in Chrome and Firefox in Embed a site in an iframe while testing.
A safer way to try a stricter policy
To see what a new policy would block without breaking the page, add it as Content-Security-Policy-Report-Only instead. The browser reports violations in the Console but enforces nothing. When the console is quiet, move the policy into the real header on your server. The CSP builder writes such a policy and turns it into a Report-Only profile for one host.
Inspecting headers with curl and DevTools
# see the CSP and framing headers a page sends
curl -sI https://www.example.com/ | grep -iE 'content-security-policy|x-frame-options'
In the DevTools Network panel, select the document request and look under Response Headers. Chrome DevTools can also override response headers locally through its Overrides feature, which needs a local folder and applies only while DevTools is open (we measured where it stops in DevTools header overrides vs an extension). A header rule keeps working across tabs and without DevTools, and you can switch it on and off with the profile's Active switch.
Pitfalls
- Policies in a meta tag. A policy delivered as
<meta http-equiv="Content-Security-Policy">inside the HTML is not a header, so header rules cannot change it. If violations persist after removing the header, look in the page source. - Several policies. A server can send more than one CSP header, and the browser enforces all of them. remove drops the header by name; set replaces it with your single value.
- Service workers and cache. A response served by a service worker or from the HTTP cache may not reflect your change. In DevTools, tick "Disable cache" in the Network panel, and under Application › Service workers tick "Bypass for network".
- Request types. CSP is applied from the document response. If you have ticked request types to narrow the profile, include
main frame(andsub framefor iframes).
Add to ChromeFirefox: coming soon