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 +}