Pcornel
Browse topics
Options
Recent
Favorites
Security · Technical reference

Content Security Policy

Direct answer

Content Security Policy (CSP) is a response header that restricts where scripts, styles, images and frames may load from, such as script-src 'self', which greatly limits the impact of XSS.

When to use this

Use this when restricting what a page may load to limit XSS.

First 30 seconds

1. CSP restricts sources for scripts, styles, frames.

2. Strict CSP with nonces/hashes.

3. Avoid 'unsafe-inline'/'unsafe-eval'.

4. Start with Report-Only.

5. frame-ancestors for clickjacking.

Operational verification

response CSP → browser blocks disallowed sources

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Security architecture and operations
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformSecurity architecture and operations
Scope / prerequisiteUse this when restricting what a page may load to limit XSS.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Common mistakes Narrow the fault
  • CSP with unsafe-inline everywhere.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • script-src 'self' blocks inline scripts.
  • Use nonces or hashes when inline scripts are needed.
  • Report-only mode lets you test safely.
Key checks
  • curl -sI https://<site> | grep -i content-security-policy — CSP
  • CSP report-uri/report-to — violation reports
  • Nonces/hashes instead of 'unsafe-inline' — strict CSP
ReferenceWhy it matters1 section · depth on demand

Rolling it out

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

1. Start with Content-Security-Policy-Report-Only and a report endpoint.

2. Remove inline scripts or use nonces/hashes; avoid 'unsafe-inline'.

3. Enforce once reports are clean.

A strict CSP makes most XSS non-exploitable even when an injection bug exists.

ReferenceHow it works1 section · depth on demand

In depth

Content Security Policy (CSP) is a response header that tells the browser which sources of scripts, styles, images and other content are allowed. It greatly reduces the impact of XSS: injected script will not run if it does not match the policy.

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m'; object-src 'none';
  base-uri 'self'; frame-ancestors 'none'; upgrade-insecure-requests

Documented example, not captured output.

Rollout method: start with Content-Security-Policy-Report-Only and a reporting endpoint, fix violations, then enforce. Avoid 'unsafe-inline' and 'unsafe-eval' for scripts; use nonces or hashes for necessary inline scripts. frame-ancestors replaces X-Frame-Options for clickjacking protection.

ReferenceImportant terms & boundaries1 section · depth on demand

Example policy

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m'; style-src 'self';
  img-src 'self' data:; object-src 'none'; base-uri 'self'; frame-ancestors 'none';
  report-to csp-endpoint

Documented example, not captured output. Avoid 'unsafe-inline' and 'unsafe-eval' for scripts; use nonces or hashes. Content-Security-Policy-Report-Only lets you test without blocking.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docSecurity architecture and operations current

Authoritative/upstream documentation reviewed for bounded claims in Web Security → Content Security Policy. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%
Confirmation

Confirm action

Continue?