Skip to content

Commit 26d2e36

Browse files
authored
feat: return validation failed error if captcha request was not json (#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.
1 parent 6ac5624 commit 26d2e36

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/api/middleware.go

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func (a *API) verifyCaptcha(w http.ResponseWriter, req *http.Request) (context.C
118118

119119
verificationResult, err := security.VerifyRequest(req, strings.TrimSpace(config.Security.Captcha.Secret), config.Security.Captcha.Provider)
120120
if err != nil {
121+
if strings.Contains(err.Error(), "request body was not JSON") {
122+
return nil, badRequestError(ErrorCodeValidationFailed, "Request body for CAPTCHA verification was not a valid JSON object")
123+
}
124+
121125
return nil, internalServerError("captcha verification process failed").WithInternalError(err)
122126
}
123127

0 commit comments

Comments
 (0)