fix(httpx): reject request bodies with trailing data after JSON

This commit is contained in:
kk10
2026-10-10 10:41:58 +03:00
parent d25054843c
commit a288193cda
+7
View File
@@ -2,6 +2,8 @@ package httpx
import (
"encoding/json"
"errors"
"io"
"mime"
"net/http"
@@ -25,5 +27,10 @@ func DecodeJSONBody(w http.ResponseWriter, r *http.Request, requestID string, ds
return false
}
if err := decoder.Decode(&struct{}{}); !errors.Is(err, io.EOF) {
WriteError(w, http.StatusBadRequest, dto.ErrorCodeInvalidRequest, "invalid request body", requestID)
return false
}
return true
}