Public: anyone can read this; the crew can change it.

CSP reports are bounded per day whatever directive they name #14987

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

CSP reports now count any directive not on the CSP list as other, so a caller can no longer push the cspviolation table past its per-day bound by making up directive names (#14962, from #14765). Why it happened: src/http/cspreport.ts accepted any well-formed name ([a-z-]{1,40}) as a directive.

Notes

shipped production is serving it deploy 9504585

opened this

CSP reports now count any directive not on the CSP list as other, so a caller can no longer push the csp_violation table past its per-day bound by making up directive names (#14962, from #14765).

Why it happened: src/http/csp_report.ts accepted any well-formed name ([a-z-]{1,40}) as a directive. Once a day had DAY_ROWS (500) rows, extra reports folded into a row keyed (directive, "(more)", ""). Because the directive was still part of that key, every invented name created a new row, and the bound did not hold.

What changed:

  • Known list: there is now a DIRECTIVES set: CSP Level 3, its drafts, and the legacy names browsers still report.
  • Fold to other: knownDirective() turns any name not in the set into other. It runs in the parser and again inside recordViolation, so callers that skip the parser are covered too.
  • No regex over long values: only the first 64 characters of a directive value are read before splitting.
  • The bound: a day holds at most DAY_ROWS named rows plus one overflow row per known directive (or other) per hour. The module comment states this.

Badly formed names (for example <script>) still get a 400. The 500-row cap, rate limits and the 30-day retention are unchanged.

Test: test/csp-report.test.ts has a new test that fills a day with 500 rows, then records 4000 reports under 2000 invented directives, half through parseCspReport and half straight to recordViolation. The table stays at 501 rows, with all 4000 counted on other's overflow row. It fails on main and passes here.

How it was checked: test/csp-report.test.ts and test/mcp-csp-violations.test.ts pass (14 tests), bun x tsc --noEmit is clean, and bun scripts/gate.ts --fix rewrapped a comment, which is committed.

Left out:

  • The test feeds reports to the parser and recorder rather than POSTing to /csp-report. The endpoint's per-client limit of 30 a minute had already been used up by the rate-limit test earlier in the file, so a POST there got a 429.
  • The bound is not strict: overflow can add up to 24 × 33 rows a day on top of the 500. Making it exactly 500 would mean dropping the directive from overflow rows, so they would no longer show what was blocked.
  • I had no keep_plan tool in this run, so the issue has no plan.

The extra empty Try: commit is there because the forge's pre-push hook requires one.

🤖 Generated with Claude Code

Closes #14962

commented

CSP reports now count any directive not on the CSP list as other, so a caller can no longer push the csp_violation table past its per-day bound by making up directive names (#14962, from #14765).

Why it happened: src/http/csp_report.ts accepted any well-formed name ([a-z-]{1,40}) as a directive. Once a day had DAY_ROWS (500) rows, extra reports folded into a row keyed (directive, "(more)", ""). Because the directive was still part of that key, every invented name created a new row, and the bound did not hold.

What changed:

  • Known list: there is now a DIRECTIVES set: CSP Level 3, its drafts, and the legacy names browsers still report.
  • Fold to other: knownDirective() turns any name not in the set into other. It runs in the parser and again inside recordViolation, so callers that skip the parser are covered too.
  • No regex over long values: only the first 64 characters of a directive value are read before splitting.
  • The bound: a day holds at most DAY_ROWS named rows plus one overflow row per known directive (or other) per hour. The module comment states this.

Badly formed names (for example <script>) still get a 400. The 500-row cap, rate limits and the 30-day retention are unchanged.

Test: test/csp-report.test.ts has a new test that fills a day with 500 rows, then records 4000 reports under 2000 invented directives, half through parseCspReport and half straight to recordViolation. The table stays at 501 rows, with all 4000 counted on other's overflow row. It fails on main and passes here.

How it was checked: test/csp-report.test.ts and test/mcp-csp-violations.test.ts pass (14 tests), bun x tsc --noEmit is clean, and bun scripts/gate.ts --fix rewrapped a comment, which is committed.

Left out:

  • The test feeds reports to the parser and recorder rather than POSTing to /csp-report. The endpoint's per-client limit of 30 a minute had already been used up by the rate-limit test earlier in the file, so a POST there got a 429.
  • The bound is not strict: overflow can add up to 24 × 33 rows a day on top of the 500. Making it exactly 500 would mean dropping the directive from overflow rows, so they would no longer show what was blocked.
  • I had no keep_plan tool in this run, so the issue has no plan.

The extra empty Try: commit is there because the forge's pre-push hook requires one.

🤖 Generated with Claude Code

Approved

Clean, small, security-positive. Unknown directives fold to other in both the parser and recordViolation, so the per-key overflow cannot be multiplied by invented names. The long-value read is capped. The test fills the day to the bound, then records 4000 reports under 2000 invented names, half through the parser and half direct, and the table stays at 501 rows. It would fail on main. The bound is 500 plus at most 24x33 overflow rows, and the module comment states it. No UI, TUI or dependency change.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs