Skip to main content
Menu
Advisories

HTTP logging middleware buffers allow an unauthenticated denial of service

GHSA-FFC3-939V-3WPWPublished Updated GitHub

Description

Every HTTP server in MediaMTX (the HLS server, the WebRTC/WHIP-WHEP server, and, when enabled, the API, metrics, pprof and playback servers) wraps its handler chain with a logging middleware that calls httputil.DumpRequest(r, true) on every request. That call reads the whole request body into memory, and it runs before authentication, before the route handler, and regardless of the configured log level. There is no request body size limit anywhere in front of it. An unauthenticated remote attacker can send one or more requests with very large bodies (or many slow ones) to any listening HTTP port and force MediaMTX to allocate memory proportional to the data sent, exhausting host memory and crashing the process.

The HTTP server type used by all of MediaMTX's HTTP services builds its middleware chain in internal/protocols/httpp/server.go as handlerOrigin → handlerLogger → handlerExitOnPanic, with the application router (which contains the authentication middleware) sitting underneath all of it; the underlying http.Server sets ReadTimeout but has no body size cap. The logging middleware, handlerLogger in internal/protocols/httpp/handler_logger.go, calls httputil.DumpRequest(r, true), which reads the request body in full into an in-memory buffer (growing by doubling) and replaces r.Body with a copy of those bytes — before the log call even checks whether the configured log level is Debug. The per-server ReadTimeout bounds only how long a request may take to arrive, not how many bytes it may contain, and it is per-connection, so concurrent connections aggregate; any router-level body-size limiting runs later, after DumpRequest has already drained the body into memory.

This is reachable with no special setup: the HLS server (default :8888) and the WebRTC server (default :8889) are enabled by default, and the API, metrics, pprof and playback servers share the same vulnerable httpp.Server type when enabled.

The impact is uncontrolled memory allocation leading to denial of service — any party that can reach a MediaMTX HTTP port can trigger it with no authentication and no user interaction, at the cost of only bandwidth and connection count to the attacker, versus memory exhaustion up to process/host crash for the target.

The fix (PR #5858) replaces the unbounded httputil.DumpRequest(r, true) call with a bounded read (RequestForLog, in internal/protocols/httpp/request_for_log.go) that peeks at most 10 KiB of the body via io.LimitReader, truncates it, and re-attaches the remainder to r.Body for downstream handlers.

Weaknesses: CWE-770 (Allocation of Resources Without Limits or Throttling), CWE-400 (Uncontrolled Resource Consumption).

Affected versions

References

GitHub · bluenviron/mediamtx