Skip to content

Commit

Permalink
Address a nil panic when writing an empty POST request to the ocsp ha…
Browse files Browse the repository at this point in the history
…ndler (#18184)

* Address a nil panic when writing an empty POST request to the ocsp handler

 - Seems when no JSON body is sent with a POST request Vault will not
   populate the HTTPRequest member variable which caused the nil panic
   - vault write -force pki/ocsp
 - Add a check for it and the Body member variable to be nil before use.

* Add cl
  • Loading branch information
stevendpclark authored Dec 1, 2022
1 parent d6ed362 commit b268889
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/logical/pki/ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,15 @@ func fetchDerEncodedRequest(request *logical.Request, data *framework.FieldData)
return base64.StdEncoding.DecodeString(base64Req)
case logical.UpdateOperation:
// POST bodies should contain the binary form of the DER request.
// NOTE: Writing an empty update request to Vault causes a nil request.HTTPRequest, and that object
// says that it is possible for its Body element to be nil as well, so check both just in case.
if request.HTTPRequest == nil {
return nil, errors.New("no data in request")
}
rawBody := request.HTTPRequest.Body
if rawBody == nil {
return nil, errors.New("no data in request body")
}
defer rawBody.Close()

requestBytes, err := io.ReadAll(io.LimitReader(rawBody, maximumRequestSize))
Expand Down
3 changes: 3 additions & 0 deletions changelog/18184.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
secrets/pki: Address nil panic when an empty POST request is sent to the OCSP handler
```

0 comments on commit b268889

Please sign in to comment.