From c21f2747769e7bc179d64f503e903d8c32e80830 Mon Sep 17 00:00:00 2001 From: kk10 Date: Tue, 20 Oct 2026 23:03:39 +0300 Subject: [PATCH] fix(auth): reject request body on session creation --- internal/handler/auth.go | 4 ++++ internal/httpx/request.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/internal/handler/auth.go b/internal/handler/auth.go index 07e2d68..7e62e60 100644 --- a/internal/handler/auth.go +++ b/internal/handler/auth.go @@ -27,6 +27,10 @@ func (h *AuthHandler) CreateSession(w http.ResponseWriter, r *http.Request) { return } + if !httpx.RejectBody(w, r, requestID) { + return + } + session, err := h.service.Login(r.Context(), username, plain) if errors.Is(err, service.ErrInvalidCredentials) { httpx.WriteUnauthorized(w, httpx.BasicChallenge, requestID) diff --git a/internal/httpx/request.go b/internal/httpx/request.go index 58f32b8..4a84eba 100644 --- a/internal/httpx/request.go +++ b/internal/httpx/request.go @@ -34,3 +34,16 @@ func DecodeJSONBody(w http.ResponseWriter, r *http.Request, requestID string, ds return true } + +func RejectBody(w http.ResponseWriter, r *http.Request, requestID string) bool { + if r.Body == nil || r.Body == http.NoBody { + return true + } + + var b [1]byte + if n, _ := r.Body.Read(b[:]); n > 0 { + WriteError(w, http.StatusBadRequest, dto.ErrorCodeInvalidRequest, "invalid request body", requestID) + return false + } + return true +}