Content Security Policy
An HTTP header that tells the browser which sources of script, style, and other content a page is allowed to load.
Content Security Policy is an HTTP response header (Content-Security-Policy) that lets a page declare, in advance, which origins it trusts for scripts, styles, images, fonts, and other resources. The browser enforces the list; anything not on it — an inline script an attacker managed to inject, a <script src> pointing at a domain that isn't allowlisted — simply fails to execute or load, regardless of how it got into the page's HTML.
Its primary target is Cross-Site Scripting: even if an attacker successfully injects markup into a page — through an unescaped comment field, a URL parameter reflected into the DOM — a strict CSP means the injected <script> tag never runs, because its source isn't on the allowlist and, under a strict policy, inline scripts are blocked outright regardless of source. This is defense in depth: CSP doesn't fix the underlying injection vulnerability, it limits what an attacker can do once they've found one.
The directive that does the real work is script-src, and the strongest configurations avoid 'unsafe-inline' and 'unsafe-eval' entirely, instead using a per-request nonce or hash that legitimate inline scripts carry and injected ones can't guess. A policy that includes 'unsafe-inline' for convenience gives up most of the protection, since that's exactly what lets an injected inline script run too.
CSP composes with, but is distinct from, Cross-Origin Resource Sharing: CORS governs whether your page's script can read a response from another origin; CSP governs which origins your page is permitted to load resources from at all. A page can have a tight CSP and a permissive CORS setup, or the reverse — they answer different questions about trust.
See also4
Referrer Policy
The rules for when a browser tells a site which page a visitor came from, a header misspelled in the 1990s that leaked private addresses for decades until browsers began trimming it by default.
Web Platform12 connections
Hotlinking
Displaying an image or file on your page straight from someone else's server, so they pay for the traffic, which sites block by checking where requests come from and which courts have treated differently from copying.
Web Platform13 connections
Same-Origin Policy
The browser rule isolating documents by scheme, host, and port, and the mechanisms for relaxing it.
Web Platform30 connections
HTTP Caching
The set of headers that let a browser or intermediary reuse a previous response instead of re-fetching it.
Web Platform18 connections
Related6
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from10
- Browser ExtensionWeb Platform
Small programs that modify the browser and the pages it shows, from bookmarklets and userscripts to ad blockers, with access broad enough to make them a standing security risk.
- ClickjackingWeb Platform
Tricking a user into clicking something on another site by loading it invisibly in a frame beneath a decoy, and the headers that stop a page from being framed.
- Cross-Origin Resource SharingWeb Platform
The mechanism by which a server opts in to letting scripts on other origins read its responses.
- Cross-Site ScriptingWeb Platform
Injecting attacker-controlled script into a page that a victim's browser then executes with the victim's own privileges.
- Data URIWeb Platform
A URL that carries its content inside the address itself, used to embed small images in pages and stylesheets without a separate request, and abused for phishing until browsers restricted it.
- IframeWeb Platform
A whole web page embedded inside another, the web's main isolation boundary for ads, payments, and widgets, and the messaging and sandboxing rules that govern it.
- JSON Web TokenWeb Platform
A signed, self-contained token that carries claims a server can verify without a database lookup.
- MIME TypeWeb Platform
The short type/subtype label, born in email, that tells a browser how to treat a response, and why browsers that guess when it's missing turned a convenience into a security hole.
- OAuthWeb Platform
A protocol for granting one application limited access to a user's data on another, without handing over the user's password.
- Referrer PolicyWeb Platform
The rules for when a browser tells a site which page a visitor came from, a header misspelled in the 1990s that leaked private addresses for decades until browsers began trimming it by default.