Skip to content
AdminKit

Content-Security-Policy (CSP)

What is Content-Security-Policy (CSP)?

Content-Security-Policy (CSP) is an HTTP response header, specified by the W3C, that lets a site allowlist which sources of scripts and other resources a browser may load, mitigating cross-site scripting. AdminKit's HTTP headers tool checks whether a site sends a Content-Security-Policy header, and what it actually allows.

By AdminKit team, Netbase JSC · Updated

Content-Security-Policy (CSP) is an HTTP response header, specified by the W3C’s Content Security Policy standard, that lets a site declare which sources of scripts, styles, images and other resources a browser is allowed to load, enforced by the browser regardless of what a page’s own HTML or any injected markup requests. Its main practical use is mitigating content-injection attacks like cross-site scripting: a directive such as script-src ‘self’ gives granular control over inline script execution and dynamic code execution via eval(), stopping an injected <script> tag from running even if an attacker manages to insert one into the page. A directive is a name — script-src, default-src as the fallback for unspecified types, frame-ancestors, and others — followed by a list of allowed sources, as catalogued in MDN’s CSP reference; the specification is explicit that CSP is not a replacement for careful input validation and output encoding, only an additional layer. OWASP’s Content Security Policy Cheat Sheet calls the response header the preferred way to deliver a policy, since it supports the full CSP feature set, and describes a “strict” CSP built on nonces or hashes rather than a list of allowed hosts. A policy allowing unsafe-inline or a wildcard source is technically present but does little of that work — see evaluating HTTP security header policy strength for how to judge a CSP value’s actual strength, not just whether the header is sent.

Common CSP directives:

  • script-src — controls which sources a browser may load and execute scripts from.
  • default-src — the fallback allowlist for any resource type without its own directive.
  • frame-ancestors — controls which sites are allowed to embed this page in a frame.

CSP is commonly deployed alongside other HTTP security headers AdminKit’s glossary covers, like Referrer-Policy and Subresource Integrity (SRI), each hardening a different part of a page’s attack surface.

AdminKit groups content-Security-Policy (CSP) under its machine protocols cluster — browse the AdminKit glossary index for other related terms.

Frequently asked questions

Does CSP replace the need for input validation?

No -- the specification is explicit that CSP is not a replacement for careful input validation and output encoding, only an additional layer that stops an injected script from running even if an attacker manages to insert one into the page.

What does the script-src directive control?

It gives granular control over which sources a browser may load and execute scripts from, including inline script execution and dynamic code execution via eval(), and is enforced by the browser regardless of what the page's own HTML or any injected markup requests.

What happens if no directive is set for a resource type?

default-src acts as the fallback allowlist for any resource type that doesn't have its own specific directive, so an unlisted resource type still falls under whatever default-src permits.

Does having a CSP header mean a site is actually protected?

Not necessarily -- a policy allowing unsafe-inline or a wildcard source is technically present but does little of the mitigation work CSP is meant for. The header's presence and its actual strength are two different things to check.