{"id":50901680,"url":"https://github.com/didrod205/csp-doctor","last_synced_at":"2026-06-16T03:04:40.198Z","repository":{"id":362591358,"uuid":"1259894468","full_name":"didrod205/csp-doctor","owner":"didrod205","description":"Lint a Content-Security-Policy for XSS holes locally — 'unsafe-inline', wildcards, missing directives, and allowlisted hosts that bypass CSP (JSONP/AngularJS). Nonce/strict-dynamic aware. Deterministic CLI, JSON/MD reports, no website.","archived":false,"fork":false,"pushed_at":"2026-06-05T01:32:18.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-05T03:11:00.251Z","etag":null,"topics":["appsec","cli","content-security-policy","csp","csp-evaluator","devsecops","linter","security","security-headers","strict-dynamic","typescript","web-security","xss","zero-dependency"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/didrod205.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-05T01:03:05.000Z","updated_at":"2026-06-05T01:49:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/didrod205/csp-doctor","commit_stats":null,"previous_names":["didrod205/csp-doctor"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/didrod205/csp-doctor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didrod205%2Fcsp-doctor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didrod205%2Fcsp-doctor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didrod205%2Fcsp-doctor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didrod205%2Fcsp-doctor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/didrod205","download_url":"https://codeload.github.com/didrod205/csp-doctor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didrod205%2Fcsp-doctor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34388681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appsec","cli","content-security-policy","csp","csp-evaluator","devsecops","linter","security","security-headers","strict-dynamic","typescript","web-security","xss","zero-dependency"],"created_at":"2026-06-16T03:04:40.133Z","updated_at":"2026-06-16T03:04:40.187Z","avatar_url":"https://github.com/didrod205.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# 🛡️ csp-doctor\n\n### Lint your Content-Security-Policy for XSS holes — locally, no website to paste into.\n\n[![npm version](https://img.shields.io/npm/v/csp-doctor.svg?color=success)](https://www.npmjs.com/package/csp-doctor)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/csp-doctor?label=core%20gzip)](https://bundlephobia.com/package/csp-doctor)\n[![CI](https://github.com/didrod205/csp-doctor/actions/workflows/ci.yml/badge.svg)](https://github.com/didrod205/csp-doctor/actions/workflows/ci.yml)\n[![types](https://img.shields.io/npm/types/csp-doctor.svg)](https://www.npmjs.com/package/csp-doctor)\n[![license](https://img.shields.io/npm/l/csp-doctor.svg)](./LICENSE)\n\n**[🌐 Try the browser playground →](https://didrod205.github.io/csp-doctor/)** \u0026nbsp;·\u0026nbsp; paste a CSP, see its XSS holes ranked. Nothing is uploaded — it all runs client-side.\n\n\u003c/div\u003e\n\nYou added a `Content-Security-Policy` to stop XSS. But a single `'unsafe-inline'`\nin `script-src` silently turns the whole thing off, a wildcard or bare `https:`\nlets any host serve scripts, and allowlisting a CDN like `ajax.googleapis.com`\nopens a JSONP/AngularJS bypass — so an attacker runs scripts *despite* your policy.\nThe only good analyzer, Google's CSP Evaluator, is **a website you paste into** —\nnot something you can run in CI.\n\n**csp-doctor lints a CSP for these holes locally and deterministically** — from a\nstring, an HTML `\u003cmeta\u003e`, or a headers file — and it's **nonce / hash /\nstrict-dynamic aware**, so it won't cry wolf about an `'unsafe-inline'` that\nmodern browsers already ignore.\n\n```bash\nnpx csp-doctor scan -p \"default-src 'self'; script-src 'self' 'unsafe-inline' ajax.googleapis.com\"\n```\n\n```\npolicy  57/100 (F)\n  ✗ 'unsafe-inline' in script-src defeats XSS protection            [script-src]\n  ⚠ Allowlisted host enables a CSP bypass: ajax.googleapis.com      [script-src]\n  ⚠ No base-uri                                                     [base-uri]\n  ⚠ No frame-ancestors                                              [frame-ancestors]\n```\n\n---\n\n## Why csp-doctor?\n\n- 🎯 **It knows the bypasses.** The built-in list of hosts that undermine an\n  allowlist (JSONP endpoints, hosted AngularJS) is the core insight behind Google's\n  CSP Evaluator — baked in for offline use.\n- 🧠 **Nonce / hash / strict-dynamic aware.** It understands that a nonce makes\n  `'unsafe-inline'` a harmless fallback, and that `'strict-dynamic'` ignores host\n  allowlists — so it grades a *modern* CSP correctly instead of flagging everything.\n- 🔒 **Local \u0026 deterministic.** No website, no API key, runs offline and in CI.\n  Same policy → same result. Fail the PR that ships `'unsafe-inline'`.\n- 🧩 **Reads it from anywhere.** A raw policy, an HTML `\u003cmeta http-equiv\u003e`, an\n  `_headers` file, nginx `add_header`, Apache `Header set`, or `vercel.json`.\n\nWhy not paste it into an LLM? The bypassable-host list and directive-fallback rules\n(`script-src` → `default-src`, `base-uri` doesn't fall back) are exact, evolving\nfacts a chatbot gets wrong — and you need this gating *every* CSP change, not once.\n\n## Install\n\n```bash\n# run it now\nnpx csp-doctor scan -p \"\u003cyour CSP\u003e\"\n\n# or add it\nnpm install -g csp-doctor      # global CLI\nnpm install -D csp-doctor      # CI dependency\n```\n\nNode ≥ 18. The core is dependency-free and browser-safe (ready for a web playground).\n\n## Quick start\n\n```bash\ncsp-doctor scan -p \"default-src 'self'; script-src 'self' 'nonce-abc'\"   # a string\ncsp-doctor scan index.html                                               # from \u003cmeta\u003e\ncsp-doctor scan _headers vercel.json                                     # from configs\ncurl -sI https://example.com | csp-doctor scan                           # from live headers\ncsp-doctor scan -p \"\u003ccsp\u003e\" --min-score 80                                # CI gate\ncsp-doctor init                                                          # write a config\n```\n\nSee [`examples/sample-report.md`](./examples/sample-report.md), and\n[`examples/strong.csp.txt`](./examples/strong.csp.txt) for a policy that scores 100.\n\n## What it checks\n\n| Group | Examples |\n| ----- | -------- |\n| **XSS exposure** | `'unsafe-inline'` (error — or info when a nonce/hash makes it moot), `'unsafe-eval'`, wildcard `*`, bare `https:`/`http:`, `data:` in `script-src` |\n| **Allowlist bypass** | hosts known to break a CSP allowlist (JSONP / hosted AngularJS), unless `'strict-dynamic'` neutralizes the allowlist |\n| **Missing directives** | no `object-src 'none'`, no `base-uri`, no `frame-ancestors`, no `default-src` fallback |\n| **Hardening \u0026 meta** | `'strict-dynamic'` without a nonce, deprecated `report-uri`, and Report-Only policies (which **block nothing**) |\n\nEach finding is a weighted error / warning / info; the policy rolls up to a 0–100\nscore and an A–F grade you can gate in CI.\n\n## Real scenarios\n\n**1. Gate your CSP in CI.** A PR that adds `'unsafe-inline'` or a bypassable CDN to\nyour policy fails the build:\n\n```yaml\n# .github/workflows/ci.yml\n- run: npx csp-doctor scan next.config.js --min-score 85   # or your _headers / meta\n```\n\n**2. Audit a policy before you ship it.** Paste the header you're about to deploy\nand see the holes — locally, without sending your config to a third-party site.\n\n**3. Triage a security finding.** A scanner said \"weak CSP\" — `csp-doctor scan` tells\nyou *which* directive and *why*, with the exact fix.\n\n## Configuration\n\n`csp-doctor init` writes `csp-doctor.config.json`:\n\n```jsonc\n{\n  \"ignore\": [],          // rule ids to skip, e.g. [\"missing-default-src\"]\n  \"bypassHosts\": [],     // extra hosts to treat as bypass-prone\n  \"allowHosts\": [],      // hosts you've audited and accept (suppress the finding)\n  \"minScore\": 0          // CI gate threshold\n}\n```\n\n## Library API\n\n```ts\nimport { analyzeCsp, DEFAULT_CONFIG } from \"csp-doctor\";\n\nconst [report] = analyzeCsp(\"inline\", \"script-src 'self' 'unsafe-inline'\", DEFAULT_CONFIG);\nfor (const f of report.findings) console.log(f.severity, f.rule, f.directive);\n```\n\nAlso exported: `analyzePolicy`, `parsePolicies`, `extractPolicies`, `findBypass`,\n`BYPASS_HOSTS`, and types. The core has zero runtime dependencies.\n\n## Roadmap\n\n- 🤖 **Optional `--ai` layer (bring-your-own key)** to draft a hardened\n  replacement policy for your app. The core stays 100% offline and deterministic.\n- `require-trusted-types-for` / Trusted Types scoring.\n- `style-src` and `connect-src` specific checks (CSS exfiltration, beacon hosts).\n- Suggest the migration to a nonce + `'strict-dynamic'` policy automatically.\n- ✅ **A browser playground** — paste a policy, see the audit, nothing uploaded.\n  [Live here](https://didrod205.github.io/csp-doctor/).\n\n## 💖 Sponsor\n\ncsp-doctor is free and MIT-licensed, built and maintained in spare time. If it caught\na hole in your CSP, please consider supporting it:\n\n- ⭐ **Star this repo** — the simplest free way to help others find it.\n- 🍋 **[Sponsor via Lemon Squeezy](https://elab-studio.lemonsqueezy.com/checkout/buy/5d059b89-51d0-456b-b33a-ed56994f7010)** — one-time or recurring.\n\n\u003e The bypassable-host insight is owed to the research behind\n\u003e [Google's CSP Evaluator](https://csp-evaluator.withgoogle.com). csp-doctor is an\n\u003e independent, offline implementation and is not affiliated with it.\n\n## License\n\n[MIT](./LICENSE) © csp-doctor contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidrod205%2Fcsp-doctor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdidrod205%2Fcsp-doctor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidrod205%2Fcsp-doctor/lists"}