Vendor Audit

Content Security Policy (CSP)

Content Security Policy is a header telling the browser which sources of scripts, styles, and other resources are allowed to load. If any other vulnerability allows script injection on your site, a strong CSP is what limits the damage.

How Content Security Policy works

Content Security Policy (CSP, W3C standard) is a defence-in-depth layer for cross-site scripting (XSS). It doesn't prevent XSS bugs from existing in your code — that's input validation's job — but it constrains what an injected script can actually do. A well-configured CSP can turn an exploitable XSS bug into one that does nothing, because the browser refuses to run the attacker's script.

The most important directives are script-src, object-src, base-uri, frame-ancestors, and form-action. script-src controls where JavaScript can come from — the strongest configurations use a per-request nonce or content hash with 'strict-dynamic'. object-src 'none' blocks legacy plugin content (Flash, Java applets) which has been a perennial source of CSP bypasses. base-uri restricts the <base> tag, which can otherwise rewrite all relative URLs in a page. frame-ancestors is the modern replacement for X-Frame-Options.

Common pitfalls: 'unsafe-inline' in script-src defeats most of CSP's value (it permits inline <script> blocks, which is exactly what most XSS injects). data: URLs in script-src or object-src likewise allow attacker-controlled inline payloads. Wildcard sources (*) or scheme-only sources (https:) are too permissive for production. The Google CSP Evaluator at https://csp-evaluator.withgoogle.com/ is excellent for catching these.

Roll out incrementally with Content-Security-Policy-Report-Only, which logs violations to a reporting endpoint without blocking. Watch the reports for a few weeks, identify legitimate sources you missed, refine the policy, then switch to enforcing Content-Security-Policy. Don't try to write a perfect policy on the first attempt — incremental is the only way that doesn't break the site.

How to fix it

Start with Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'none' and tighten further; avoid 'unsafe-inline'.

The 3 Content Security Policy checks Vendor Audit runs

Each check has a fixed set of results, and each result has one rating. These are the exact words the report uses.

CSP script-src safety

Standard: CSP Level 3

CSP object-src

Standard: CSP Level 3

What it checks. object-src controls what <object> and <embed> elements may load.

Why it matters. Left open, an attacker who can inject HTML can load script through them and get around script-src.

How to fix it. Add object-src 'none' to the policy.

CSP base-uri

Standard: CSP Level 3

What it checks. base-uri controls which <base> element a page may use.

Why it matters. Without it, an injected <base href> makes every relative script and link on the page load from the attacker's server, even under a nonce-based script-src.

How to fix it. Add base-uri 'none' (or 'self' if the site uses a <base> element).

Related

Security headers · Page content