-
Notifications
You must be signed in to change notification settings - Fork 4.5k
SECVULN-29092 DoS handled for kvs_endpoint.go #22916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
635cda0
14f630c
9ebb5e0
db69840
b8fa0b4
6ed93a9
ebec61b
37727e3
3a0d477
870f498
1542fbf
91475c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,19 +234,31 @@ func (s *HTTPHandlers) KVSPut(resp http.ResponseWriter, req *http.Request, args | |
| } | ||
|
|
||
| // Check the content-length | ||
| if req.ContentLength > int64(s.agent.config.KVMaxValueSize) { | ||
| maxSize := int64(s.agent.config.KVMaxValueSize) | ||
| if req.ContentLength > maxSize { | ||
| return nil, HTTPError{ | ||
| StatusCode: http.StatusRequestEntityTooLarge, | ||
| Reason: fmt.Sprintf("Request body(%d bytes) too large, max size: %d bytes. See %s.", | ||
| req.ContentLength, s.agent.config.KVMaxValueSize, "https://developer.hashicorp.com/docs/agent/config/config-files#kv_max_value_size"), | ||
| req.ContentLength, maxSize, "https://developer.hashicorp.com/docs/agent/config/config-files#kv_max_value_size"), | ||
| } | ||
| } | ||
|
|
||
| // Copy the value | ||
| buf := bytes.NewBuffer(nil) | ||
| if _, err := io.Copy(buf, req.Body); err != nil { | ||
| // LimitReader to limit copy of large requests with no Content-Length | ||
| limitedReader := io.LimitReader(req.Body, maxSize+1) | ||
| buf := new(bytes.Buffer) | ||
| copiedBytes, err := io.Copy(buf, limitedReader) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Reject request if actual read size exceeds allowed limit | ||
| if copiedBytes > maxSize { | ||
|
||
| return nil, HTTPError{ | ||
| StatusCode: http.StatusRequestEntityTooLarge, | ||
| Reason: fmt.Sprintf("Request body too large, max allowed is %d bytes.", maxSize), | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add jira tickets to oss repo prs. |
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add unit tests for this. |
||
| applyReq.DirEnt.Value = buf.Bytes() | ||
|
|
||
| // Make the RPC | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is maxSize+1 needed?