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.
## 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)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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
Remediation
If this helper is later used by cookie-auth HTTP handlers, enforce Content-Type: application/json or add CSRF protection.
Fingerprint:
b3a9a33b61ce3c049a174ad1e533c5f5125c6eea87fb2026081f9de201404a9bGenerated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen