Glossary
Content Security Policy (CSP)
Definition
Content Security Policy (CSP): A browser security mechanism, specified by the W3C, in which a site sends a Content-Security-Policy header listing which scripts, styles, images, frames and connections a page may use, so injected code is blocked and the page can't be framed by untrusted sites.
Also known asCSPContent-Security-Policy headerCSP header
In short
A Content Security Policy (CSP) is a set of rules a website sends in the Content-Security-Policy header to tell the browser which scripts, styles, frames and connections a page may use. A strict policy with a fresh nonce per page load and 'strict-dynamic' stops most injected scripts from running, and frame-ancestors stops clickjacking. It backs up safe coding; it doesn't replace it.
Key takeaways
- CSP limits what a page can load, run and connect to, as a second line of defense against XSS.
- A nonce must be fresh and unguessable for every response, or the policy is easy to bypass.
- 'strict-dynamic' lets trusted scripts load their own dependencies and ignores host allowlists for scripts.
- frame-ancestors controls who may frame the page, which stops clickjacking.
- Roll out with Content-Security-Policy-Report-Only first to find what would break.
Last reviewed 4 December 2026 by Foxcolab Team
A Content Security Policy (CSP) is a set of rules a website sends in the Content-Security-Policy response header to tell the browser which scripts, styles, images, frames and connections a page may use. The W3C's CSP Level 3 draft describes it as "a mechanism by which web developers can control the resources which a particular page can fetch or execute." Its main job: when an attacker slips a script into a page through cross-site scripting, the browser refuses to run it.
A strict policy, line by line#
Content-Security-Policy: script-src 'nonce-r4nd0mV4lu3' 'strict-dynamic'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'| Directive | What it does |
|---|---|
script-src 'nonce-…' | Runs only <script> tags carrying this exact value. The server "MUST generate a unique value each time it transmits a policy" |
'strict-dynamic' | Lets those trusted scripts load their own dependencies, and makes the browser ignore host allowlists and 'self' for scripts |
object-src 'none' | Blocks plugins and embedded objects |
base-uri 'none' | Stops an injected <base> tag from redirecting the page's relative links |
frame-ancestors 'none' | Refuses to be shown in a frame, which stops clickjacking |
With that header, <script nonce="r4nd0mV4lu3" src="/app.js"> runs and an injected <script> without the nonce doesn't.
Mistakes people make#
- Reusing a nonce. A nonce baked into a cached page is one an attacker can copy. CSP3 says it's "critical" that nonces "remain unguessable."
- Allowlisting whole CDNs. If any script on an allowed host can be loaded, an attacker can load the one that helps them. Nonces with
'strict-dynamic'avoid long allowlists. - Enforcing without testing. Send
Content-Security-Policy-Report-Onlyfirst and watch what it would block. - Treating it as the fix. OWASP says CSP "should not be your primary defense mechanism." Encode output and sanitize HTML first.
In Foxcolab#
Foxcolab Drive, Docs, Sheets, Notes, Whiteboard and Forms are where your end-to-end encrypted content is decrypted, inside your browser. Each of them builds a new policy for every page request: scripts run only with that request's nonce and 'strict-dynamic', plugins are off, other sites can't frame the page (embedded forms excepted), and connect-src lets the page connect only to Foxcolab's own services and its cloud storage provider. Foxcolab Mail shows each message in a sandboxed frame with its own policy, script-src 'none'. Together with HSTS, that covers what can run in the page and how it reaches Foxcolab.
Create a free account, or read about security at Foxcolab.
Keep exploring
Related terms
- Cross-site scripting (XSS)Cross-site scripting lets an attacker run their own script inside a trusted website, in other people's browsers. Here are the three types, an example and the defenses that work.
- ClickjackingClickjacking hides a real website inside an invisible frame and lines up its buttons under your clicks. Here's how it works and the headers that stop it.
- Subresource Integrity (SRI)Subresource Integrity lets a page pin the exact contents of a script or stylesheet it loads from a CDN, so a tampered file is refused. Here's how the integrity attribute works.
- Same-origin policyThe same-origin policy stops a web page from reading data that belongs to another origin. Here's what counts as an origin, what the rule blocks, and where cookies differ.
- HSTS (HTTP Strict Transport Security)HSTS is a response header that tells browsers to reach a site only over HTTPS, for a set time, and to refuse to continue past certificate errors. It blocks downgrade attacks on the connection.
Where Foxcolab uses it

Foxcolab
Private work tools, without the ads.
Mail, files, documents, spreadsheets and meetings in one account. Files, documents and spreadsheets are end-to-end encrypted.