influxdata / influxdata/telegraf

Unbounded memory allocation in http_listener_v2 collectBody() - snappy and default encoding paths

Open Beginner friendly
#19,629 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
17.8k
Forks
5.8k
Avg merge
1d 20h
Merged PRs (30d)
161

Description

### Relevant code

```text
The collectBody() method correctly wraps the gzip path with http.MaxBytesReader to enforce max_body_size, but the Snappy and default (uncompressed) encoding paths call io.ReadAll(req.Body) directly without any size constraints.

This allows an attacker to send an arbitrarily large HTTP request body that will be fully read into memory, potentially causing OOM conditions and crashing the process.

Affected paths include:

1. Snappy path (~line 301)
2. Default path (~line 327)

While the method does check req.ContentLength > int64(h.MaxBodySize) at the top of serveWrite(), the Content-Length header is optional and can be omitted or spoofed by the client. The actual request body must be bound independently.
```

### Logs

```text
None
```

### System info

Latest version

### Docker

*No response*

### Steps to reproduce

1. Send an HTTP request to the affected endpoint without a `Content-Length` header.
2. Provide a request body larger than the configured `max_body_size`.
3. Observe that the request body is fully read into memory by the Snappy or default encoding path.

### Expected behavior

The request body should be independently bounded by `max_body_size` regardless of whether the client provides a `Content-Length` header.

### Actual behavior

The Snappy and default (uncompressed) encoding paths call `io.ReadAll(req.Body)` without applying a size limit. An attacker can therefore cause arbitrarily large request bodies to be loaded into memory, potentially resulting in OOM conditions and process crashes.

### Additional info

The gzip path already uses `http.MaxBytesReader` to enforce the configured body-size limit. The same protection should be applied to the Snappy and default encoding paths.

Contributor guide

Open the contributing guide

Research direction

Inspect collectBody() and serveWrite() in the http_listener_v2 implementation, beginning with the existing gzip path and comparing the Snappy and default branches. Confirm the affected branches enforce max_body_size for bodies without Content-Length, and verify oversized requests are rejected without unbounded memory growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.