Skip to content

fix: Limit length of response body read to 4mb#2080

Open
kaylareopelle wants to merge 1 commit intoopen-telemetry:mainfrom
kaylareopelle:read-body-limit
Open

fix: Limit length of response body read to 4mb#2080
kaylareopelle wants to merge 1 commit intoopen-telemetry:mainfrom
kaylareopelle:read-body-limit

Conversation

@kaylareopelle
Copy link
Copy Markdown
Contributor

@kaylareopelle kaylareopelle commented Apr 8, 2026

Our exporters read HTTP response bodies without any limit. A misconfigured or misbehaving server could send an arbitrarily large response, causing the exporter to read it all into memory.

This implements a 4 MB response body limit also implemented by:

Based on https://cwe.mitre.org/data/definitions/789.html

Fixes #2079

Limiting the read size may help prevent memory exhaustion exploits when
the configured collector endpoint is attacker-controlled.
truncated = false

response.read_body do |chunk|
if body.bytesize + chunk.bytesize <= RESPONSE_BODY_LIMIT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before starting to read the response body, should we not first read the content-length or transfer-encoding and short circuit if the body exceeds the limit?

IIUC the Go collector will switch to using chunked responses that exceed the 2KiB default buffer size. In cases where the response is less than 2KiB or the backend supports larger buffer sizes we may get the content-length responses and exit early.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Length

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Transfer-Encoding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exporters reading response body have no size limit

2 participants