fix: enforce max body size on CSP violation report endpoint (#27243)

The `/api/v2/csp/reports` endpoint is unauthenticated and CSRF-exempt,
since it's the browser's `report-uri` target, and decoded request bodies
with no size limit. This let an attacker post arbitrarily large JSON
bodies to force unbounded heap allocation and OOM the server (Cure53
CDM-02-007).

Wraps the request body in `http.MaxBytesReader` before decoding and
returns 413 when the limit is exceeded, matching the existing convention
used by `files.go`, `aitasks.go`, and `exp_chats.go`.

Fixes: https://github.com/coder/security-disclosures/issues/171
This commit is contained in:
Bobby Ho
2026-07-14 12:29:38 -07:00
committed by GitHub
parent d99ed85db8
commit 0207a9824f
5 changed files with 107 additions and 3 deletions
+6
View File
@@ -1952,6 +1952,12 @@
"responses": {
"200": {
"description": "OK"
},
"413": {
"description": "Request Entity Too Large",
"schema": {
"$ref": "#/definitions/codersdk.Response"
}
}
},
"security": [