Browser CSP Violations — Content Security Policy Error Guide
Warningsecurity
Overview
Fix Content Security Policy (CSP) violation errors including 'Refused to execute inline script', blocked resource loading, and CSP header misconfiguration.
Key Details
- CSP is an HTTP header that controls which resources a page can load and execute
- CSP violations appear in the browser console as 'Refused to...' messages
- Common directives: script-src, style-src, img-src, connect-src, font-src, frame-src
- Inline scripts and eval() are blocked by default unless explicitly allowed
- CSP report-uri or report-to sends violation reports to a specified endpoint
Common Causes
- CSP policy blocking legitimate scripts or resources (too restrictive policy)
- Inline scripts blocked by script-src not including 'unsafe-inline' or nonces
- Third-party resources (CDN, analytics, ads) not listed in the CSP
- eval() used in code but not allowed by script-src
- Browser extension injecting scripts that violate the page's CSP
Steps
- 1Read the console error — it specifies which directive blocked which resource
- 2Add the resource origin to the appropriate CSP directive (e.g., script-src https://cdn.example.com)
- 3For inline scripts: use nonces (script-src 'nonce-RANDOM') or hashes ('sha256-HASH')
- 4Test with Content-Security-Policy-Report-Only header to test without blocking
- 5Use CSP Evaluator (csp-evaluator.withgoogle.com) to check your policy for issues
Tags
browsercspcontent-security-policysecurityinline-script
More in Security
windows-defender-errorsWindows Defender Errors — Antivirus Not Working or Updating
Errorwindows-error-0x80073b01-defender-serviceWindows Error 0x80073B01 — Windows Defender Service Failed to Start
Errormac-gatekeeper-app-blockedMac Gatekeeper — App Cannot Be Opened (Unidentified Developer)
Warningmac-filevault-recovery-errorsMac FileVault Errors — Encryption, Decryption & Recovery Key Issues
Errorlinux-ssl-tls-certificate-errorsLinux SSL/TLS Certificate Errors — Expired, Self-Signed & Chain Issues
Warningbrowser-mixed-content-warningsBrowser Mixed Content Warnings — HTTP Resources on HTTPS Page
WarningFrequently Asked Questions
Avoid it if possible — it weakens CSP significantly. Use nonces or hashes instead. 'unsafe-inline' allows any inline script including injected XSS.