[medium] semgrep: An HTTP handler decodes the request body as JSON without validating the Content-Type header. #111

Open
opened 2026-11-03 11:26:22 +00:00 by pruefwerk · 0 comments
Member

medium Finding

Scanner: semgrep
Severity: medium
Rule: elttam-json-decode-without-content-type-check
CWE: CWE-352

Description

An HTTP handler decodes the request body as JSON without validating the Content-Type header. Browsers send no CORS preflight for "simple" requests using text/plain or application/x-www-form-urlencoded, so a cross-site HTML form can POST a body the server parses as JSON (encoding/json also ignores trailing bytes, so a form's trailing "=" doesn't break parsing). With cookie auth this is exploitable as CSRF. Reject requests whose Content-Type is not application/json, and/or wrap handlers with http.CrossOriginProtection (Go 1.25+).
v2: handler matching widened to cover method receivers, extra parameters (e.g. ctx), and common framework handler signatures (gin, echo, chi/std) — the std-only two-arg pattern missed real handlers like func (h *T) handleWrite(w, r, ctx) found in production code.

Location

File: internal/server/helpers.go (line 53)

Code

	if err := json.NewDecoder(r.Body).Decode(dst); err != nil {

Remediation

If this helper is later used by cookie-auth HTTP handlers, enforce Content-Type: application/json or add CSRF protection.


Fingerprint: b3a9a33b61ce3c049a174ad1e533c5f5125c6eea87fb2026081f9de201404a9b
Generated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen

## medium Finding **Scanner:** semgrep **Severity:** medium **Rule:** elttam-json-decode-without-content-type-check **CWE:** CWE-352 ### Description An HTTP handler decodes the request body as JSON without validating the Content-Type header. Browsers send no CORS preflight for "simple" requests using text/plain or application/x-www-form-urlencoded, so a cross-site HTML form can POST a body the server parses as JSON (encoding/json also ignores trailing bytes, so a form's trailing "=" doesn't break parsing). With cookie auth this is exploitable as CSRF. Reject requests whose Content-Type is not application/json, and/or wrap handlers with http.CrossOriginProtection (Go 1.25+). v2: handler matching widened to cover method receivers, extra parameters (e.g. ctx), and common framework handler signatures (gin, echo, chi/std) — the std-only two-arg pattern missed real handlers like func (h *T) handleWrite(w, r, ctx) found in production code. ### Location **File:** `internal/server/helpers.go` (line 53) ### Code ``` if err := json.NewDecoder(r.Body).Decode(dst); err != nil { ``` ### Remediation If this helper is later used by cookie-auth HTTP handlers, enforce Content-Type: application/json or add CSRF protection. --- *Fingerprint:* `b3a9a33b61ce3c049a174ad1e533c5f5125c6eea87fb2026081f9de201404a9b` *Generated by compliance-scanner* [Open in Prüfwerk / In Prüfwerk öffnen](https://pruefwerk.breakpilot.com/findings?target=6ae9aa2160f5d8045fc570a9)
pruefwerk added the pruefwerkcra:annex-iseverity:medium labels 2026-11-03 11:26:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: platform/tenant-registry#111