Skip to content

Commit

Permalink
feat: return validation failed error if captcha request was not json (#…
Browse files Browse the repository at this point in the history
…1815)

Returns HTTP 400 with the validation failed error code if the request
body sent to the server when CAPTCHA verification is enabled was not
JSON or couldn't be parsed into JSON.
  • Loading branch information
hf authored Oct 25, 2024
1 parent 6ac5624 commit 26d2e36
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (a *API) verifyCaptcha(w http.ResponseWriter, req *http.Request) (context.C

verificationResult, err := security.VerifyRequest(req, strings.TrimSpace(config.Security.Captcha.Secret), config.Security.Captcha.Provider)
if err != nil {
if strings.Contains(err.Error(), "request body was not JSON") {
return nil, badRequestError(ErrorCodeValidationFailed, "Request body for CAPTCHA verification was not a valid JSON object")
}

return nil, internalServerError("captcha verification process failed").WithInternalError(err)
}

Expand Down

0 comments on commit 26d2e36

Please sign in to comment.