{
  "id": 22090545,
  "title": "CSP basics: allow only what you mean to run, not block everything",
  "url": "https://urgent.news/2026/11/27/csp-basics-allow-only-what-you-mean-to-run-not-block-everything",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-27T01:34:52.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/masahirokurokawa/csp-basics-allow-only-what-you-mean-to-run-not-block-everything-390o"
  },
  "original_language": "en",
  "account": "CSP (Content-Security-Policy) is a security measure that allows you to control which scripts, styles, images, and other resources a web page can load. It does not block all scripts by default, but instead creates an allowlist of trusted sources. Imagine a front desk at an event with a guest list – only people on that list are allowed entry, while everyone else is denied access. Similarly, CSP specifies where scripts, styles, images, and other resources may be loaded from, and blocks everything else.\n\nPicture a malicious script being slipped into a form field on your web page. This is called an XSS (cross-site scripting) attack. If the malicious script is allowed to run, it can compromise user data and security. CSP helps prevent this by ensuring that only trusted scripts are executed on your web page.\n\nTo implement CSP, start with the default-src 'self' directive, which allows scripts only from the same origin (the same website). From there, add specific sources for scripts (script-src), styles (style-src), images (img-src), fetches (connect-src), fonts (font-src), and iframes (frame-src). It is a good practice to also add object-src 'none' and base-uri 'self' to further enhance security.\n\nAvoid using wildcards (*), http:, unsafe-inline, or unsafe-eval in your CSP policy, as these can weaken the security provided by CSP. Instead, use nonces (one-time pass) or hashes for script and style tags to allow them to run securely. You can also use 'strict-dynamic' for scripts that are loaded later by trusted scripts.\n\nBefore enforcing CSP, it is recommended to run it in report-only mode. This allows you to see potential violations without blocking scripts. Monitor the reports for a week to identify any issues that might break your site. Once you have resolved these issues, switch to enforcing mode.\n\nWhen checking your site's CSP using a tool like vuln, it will report any weaknesses found in the policy. If you see V02 indicating \"Needs work\", focus on fixing that first before proceeding. By implementing a well-configured CSP, you can significantly improve the security of your web pages and protect against various attacks.",
  "summary": "Someone told you to add CSP, so you pasted the one line default-src 'self' . What actually changed? It is easy to end up with no idea. CSP is not a way to block all scripts. It is an allowlist: you name what may run on the page, and everything else is stopped . Start from default-src 'self' and add only the sources you really use. What CSP is Picture the front desk at an event. There is a guest…",
  "key_points": [
    "CSP controls which scripts, styles, images load on a web page",
    "Avoid wildcards, http:, unsafe-inline, unsafe-eval in CSP policy",
    "Test CSP in report-only mode before enforcing security"
  ],
  "editors_take": "Adopting an allowlist approach through Content-Security-Policy shifts web defense from reactive blocking to proactive resource management, effectively neutralizing cross-site scripting attacks by restricting execution to trusted origins.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}