Skip to content

Commit

Permalink
fix: don't read more than max bytes from a request (#1276) (#1282)
Browse files Browse the repository at this point in the history
This is a cherry-pick of the commit from #1276 to the 2.8 (main) branch.
  • Loading branch information
kentquirk authored Aug 15, 2024
1 parent d147025 commit cde0584
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const (
numZstdDecoders = 4
traceIDShortLength = 8
traceIDLongLength = 16
GRPCMessageSizeMax int = 5000000 // 5MB
GRPCMessageSizeMax int = 5_000_000 // 5MB
HTTPMessageSizeMax = 5_000_000 // 5MB
defaultSampleRate = 1
)

Expand Down Expand Up @@ -655,7 +656,7 @@ func (r *Router) getMaybeCompressedBody(req *http.Request) (io.Reader, error) {
defer gzipReader.Close()

buf := &bytes.Buffer{}
if _, err := io.Copy(buf, gzipReader); err != nil {
if _, err := io.Copy(buf, io.LimitReader(gzipReader, HTTPMessageSizeMax)); err != nil {
return nil, err
}
reader = buf
Expand All @@ -671,7 +672,7 @@ func (r *Router) getMaybeCompressedBody(req *http.Request) (io.Reader, error) {
return nil, err
}
buf := &bytes.Buffer{}
if _, err := io.Copy(buf, zReader); err != nil {
if _, err := io.Copy(buf, io.LimitReader(zReader, HTTPMessageSizeMax)); err != nil {
return nil, err
}

Expand Down

0 comments on commit cde0584

Please sign in to comment.