Inadequate file size control In node-axios

Description

Axios' HTTP adapter-streamed uploads bypass maxBodyLength when maxRedirects: 0

Summary

For stream request bodies, maxBodyLength is bypassed when maxRedirects is set to 0 (native http/https transport path). Oversized streamed uploads are sent fully even when the caller sets strict body limits.

Details

Relevant flow in lib/adapters/http.js:

    556-564: maxBodyLength check applies only to buffered/non-stream data.

    681-682: maxRedirects === 0 selects native http/https transport.

    694-699: options.maxBodyLength is set, but native transport does not enforce it.

    925-945: stream is piped directly to socket (data.pipe(req)) with no Axios byte counting.

This creates a path-specific bypass for streamed uploads.

PoC

Environment:

    Axios main at commit f7a4ee2

    Node v24.2.0

Steps:

    Start an HTTP server that counts uploaded bytes and returns {received}.

    Send a 2 MiB Readable stream with:

      adapter: 'http'

      maxBodyLength: 1024

      maxRedirects: 0

Observed:

    Request succeeds; server reports received: 2097152.

Control checks:

    Same stream with default/nonzero redirects: rejected with ERR_FR_MAX_BODY_LENGTH_EXCEEDED.

    Buffered body with maxRedirects: 0: rejected with ERR_BAD_REQUEST.

Impact

Type: DoS / uncontrolled upstream upload / resource exhaustion. Impacted: Node.js services using streamed request bodies with maxBodyLength expecting hard enforcement, especially when following Axios guidance to use maxRedirects: 0 for streams.

Mitigation

Update Impact

Minimal update. May introduce new vulnerabilities or breaking changes.

Ecosystem
Package
Affected version
Patched versions