Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Content Security Policy?

Content Security Policy is an HTTP response header that tells the browser which scripts, styles, and other resources a page may load, limiting the damage an injected script can do.

Illustration for the cybersecurity term Content Security Policy
Home / Blog / Cybersecurity Terms / What Is Content Security Policy?
17 November 2026

What Is Content Security Policy?

What Is Content Security Policy?

Content Security Policy (CSP) is an HTTP response header through which a site declares where the browser may load scripts, styles, images, frames, and connections from. If a payload is injected into the page, the browser still refuses to execute it unless it satisfies the policy. CSP does not prevent injection; it is a containment control that turns a working cross-site scripting bug into a blocked console message.

Reading a Policy

A policy is a list of directives, each naming a resource type and the sources allowed for it. A minimal example:

Content-Security-Policy: default-src 'self'; script-src 'nonce-r4nd0m' 'strict-dynamic'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'

The directives that carry the most weight are script-src, which governs executable code; object-src, which should almost always be 'none' because plugins bypass other restrictions; base-uri, which stops an injected <base> tag redirecting every relative script URL; and frame-ancestors, which replaces the older X-Frame-Options header and defends against clickjacking.

Why Allow-Lists of Domains Fail

The first generation of policies listed trusted hostnames. In 2016 a Google study that examined over a billion hostnames found that 94.72% of the policies it collected could be bypassed, usually because an allowed CDN also hosted a JSONP endpoint or an old copy of AngularJS that could be coaxed into running attacker-supplied code. Listing a large content delivery network is close to listing the whole internet.

The modern answer is a nonce-based policy. The server generates an unpredictable value for every response, places it on each legitimate <script> tag, and names it in the header. Injected markup cannot guess the value, so it never runs. Adding 'strict-dynamic' lets a trusted script load its own dependencies without the policy having to enumerate them, which is what makes the approach practical for applications that use tag managers or module loaders.

Deploying Without Breaking the Site

  1. Start in report-only mode. Content-Security-Policy-Report-Only is evaluated and reported but never enforced, so you can measure the impact on real traffic.
  2. Collect violations with report-to and a reporting endpoint, and expect noise: browser extensions and injected ISP content generate reports you did not cause.
  3. Remove inline handlers. onclick attributes and javascript: URLs cannot be covered by a nonce, so they have to move into script files before the policy can tighten.
  4. Drop 'unsafe-inline' and 'unsafe-eval' last, and treat their removal as the point at which the policy starts providing value.
  5. Enforce, then keep measuring. A policy that is never reviewed drifts as the application changes.

Avoid the common shortcut of generating one static nonce at build time. A nonce that does not change per response is simply a password the attacker can read from the page source.

What CSP Is Good At Beyond Script Control

Payment pages are the clearest case. In the British Airways compromise disclosed on 6 September 2018, a modified script on the booking pages skimmed the card details of hundreds of thousands of customers; the ICO issued a £20 million penalty on 16 October 2020. A policy restricting script-src and connect-src would have blocked the exfiltration call even after the script was altered. PCI DSS v4.0 requirements 6.4.3 and 11.6.1 now require payment page scripts to be authorised and monitored for change, and CSP together with Subresource Integrity is the usual way of meeting them.

Policies are also used to force secure transport with upgrade-insecure-requests, to limit where forms may submit with form-action, and to isolate a document from cross-origin windows alongside the Cross-Origin-Opener-Policy header. CSP sits alongside the other HTTP security headers rather than replacing them. If you want the policy reviewed against your actual page behaviour, our web application security testing includes header and bypass analysis.

FAQ – Frequently Asked Questions

Does CSP Replace Fixing Cross-Site Scripting?

No. CSP limits what an injected script can do; it does not stop the injection. Policies can be bypassed through allowed origins, DOM clobbering, or dangling markup, and a browser that does not support a directive ignores it. Treat the policy as a second line of defence behind context-aware output encoding and framework auto-escaping, not as a substitute for them.

Should I Use a Nonce or a Hash?

Use a nonce when the server renders the page and can emit a fresh random value per response. Use hashes when the script content is fixed and the page is served statically from a cache or CDN, where a per-response value is impossible. Hashes break whenever the script text changes by a single byte, so they suit small, stable inline blocks best.

Why Are We Receiving Violation Reports We Cannot Explain?

Most unexplained reports come from the client side rather than your code: browser extensions injecting scripts, antivirus products rewriting pages, in-app browsers, and occasionally content injected on public networks. Filter by document URL and blocked URI before investigating, and expect a baseline of noise that never fully disappears on a high-traffic site.

Can a CSP Be Delivered in a Meta Tag?

It can, using a meta element with http-equiv set to Content-Security-Policy, which is useful when you cannot change server configuration. The limitations matter though: frame-ancestors, sandbox, and report-uri are ignored in meta form, and any markup before the tag is already parsed. A response header is the reliable delivery mechanism.

Related Terms

You May Be Interested In These

What Is Water and Wastewater System Security?

Cybersecurity Terms

17 November 2026

What Is Water and Wastewater System Security?

Read More
What Is TACACS+?

Cybersecurity Terms

17 November 2026

What Is TACACS+?

Read More
What Is File Carving?

Cybersecurity Terms

17 November 2026

What Is File Carving?

Read More