Content Seguridad Policy (CSP) Referencia
Referencia para CSP directives, sources, y nonce/hash-based script allowlisting.
Directives and Sources
CSP directives control resource loading: default-src (fallback), script-src, style-src, img-src, connect-src, font-src, frame-src, object-src, media-src. Source values include * (any), none, self (same origin), data:, blob:, specific URLs, nonces (nonce-xxx), and hashes (sha256-xxx). The report-uri directive sends violation reports. CSP prevents XSS by restricting script sources. A strict policy uses nonces or hashes instead of unsafe-inline.
- script-src
- Script sources
- nonce
- Per-request random
- report-uri
- Violation reports
most critical nonce-abc123 monitoring Best Practices
Start with Content-Security-Policy-Report-Only to monitor violations before enforcement. Use nonces for scripts that cannot be externalized. Avoid unsafe-inline and unsafe-eval which weaken protection. Set base-uri to prevent base tag hijacking. Use frame-ancestors to prevent clickjacking (replaces X-Frame-Options). Strict CSP: default-src none; script-src nonce; style-src nonce; connect-src self. CSP Level 3 adds strict-dynamic for trust propagation.
- Report-Only
- Monitor before enforce
- strict-dynamic
- Trust propagation
- frame-ancestors
- Clickjacking prevention
no blocking CSP Level 3 replaces XFO