api: ensure all request body decode error return a 400 status code. (#15252)

This commit is contained in:
James Rasell 2022-11-18 17:04:33 +01:00 committed by GitHub
parent b28494ec9a
commit 3225cf77b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

3
.changelog/15252.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
api: Ensure all request body decode errors return a 400 status code
```

View File

@ -73,7 +73,7 @@ func (s *HTTPServer) aclPolicyUpdate(resp http.ResponseWriter, req *http.Request
// Parse the policy
var policy structs.ACLPolicy
if err := decodeBody(req, &policy); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
// Ensure the policy name matches
@ -244,7 +244,7 @@ func (s *HTTPServer) aclTokenUpdate(resp http.ResponseWriter, req *http.Request,
// Parse the token
var token structs.ACLToken
if err := decodeBody(req, &token); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
// Ensure the token accessor matches
@ -311,7 +311,7 @@ func (s *HTTPServer) ExchangeOneTimeToken(resp http.ResponseWriter, req *http.Re
var args structs.OneTimeTokenExchangeRequest
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
s.parseWriteRequest(req, &args.WriteRequest)

View File

@ -509,17 +509,17 @@ func (s *HTTPServer) KeyringOperationRequest(resp http.ResponseWriter, req *http
sresp, err = kmgr.ListKeys()
case "install":
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
sresp, err = kmgr.InstallKey(args.Key)
case "use":
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
sresp, err = kmgr.UseKey(args.Key)
case "remove":
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
sresp, err = kmgr.RemoveKey(args.Key)
default:

View File

@ -80,7 +80,7 @@ func (s *HTTPServer) namespaceUpdate(resp http.ResponseWriter, req *http.Request
// Parse the namespace
var namespace structs.Namespace
if err := decodeBody(req, &namespace); err != nil {
return nil, CodedError(500, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}
// Ensure the namespace name matches