Skip to content

Commit

Permalink
Backport of api: ensure ACL role upsert decode error returns a 400 st…
Browse files Browse the repository at this point in the history
…atus code. into release/1.4.x (#15321)

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-nomad-core authored Nov 18, 2022
1 parent bd38820 commit 7623043
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .semgrep/http_endpoint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
rules:
- id: "http-endpoint-request-decode-error-code"
patterns:
- pattern: |
if err := decodeBody(...); err != nil {
return nil, CodedError(...)
}
- pattern-not-inside: |
if err := decodeBody(...); err != nil {
return nil, CodedError(400, ...)
}
- pattern-not-inside: |
if err := decodeBody(...); err != nil {
return nil, CodedError(http.StatusBadRequest, ...)
}
message: "HTTP endpoint request decode should return http.StatusBadRequest"
languages:
- "go"
severity: "ERROR"
paths:
include:
- "command/agent/*_endpoint.go"
2 changes: 1 addition & 1 deletion command/agent/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (s *HTTPServer) aclRoleUpsertRequest(
// Decode the ACL role.
var aclRole structs.ACLRole
if err := decodeBody(req, &aclRole); err != nil {
return nil, CodedError(http.StatusInternalServerError, err.Error())
return nil, CodedError(http.StatusBadRequest, err.Error())
}

// Ensure the request path ID matches the ACL role ID that was decoded.
Expand Down

0 comments on commit 7623043

Please sign in to comment.