Skip to content
Memory corruption Disclosed report Intermediate

`stringstream` allocates uninitialized Buffers when number is passed in input stream on Node.js 4.x and below

The stringstream module allocates uninitialized buffers when a number is passed to the stream, which on Node.js 4.x and below can expose sensitive memory contents or cause a denial of service by passing a large number.

chalker Follow

Originally disclosed on HackerOne

Medium 5.2 View original
  • Triaged in 33 days
  • Fixed in 2 months
  • Disclosed after 2 months

I would like to report n uninitialized Buffer allocation issue in stringstream. It allows to extract sensitive data from uninitialized memory or to cause a DoS by passing in a large number, in setups where typed user input can be passed to the stream (e.g. from JSON), on Node.js 4.x and lower.

Module

module name: stringstream version: 0.0.5 npm page: https://www.npmjs.com/package/stringstream

Module Description

Decode streams into strings The Right Way(tm)

Module Stats

740 368 downloads in the last day 4 606 368 downloads in the last week 19 182 466 downloads in the last month

Vulnerability

Vulnerability Description

See https://github.com/mhart/StringStream/blob/v0.0.5/stringstream.js#L32

The problem arises when a number is passed in the stream. That is unlikely to be attacker-controlled in real-world setups, but still possible. The API should not propagate the already-bad Buffer issue further.

On Node.js 4.x and below (4.x is still supported), this exposes uninitialized memory, which could contain sensitive data.

On Node.js 6.x and newer, this is type-checked on Node.js side and thows an error there.

Steps To Reproduce:

JavaScript
var stringstream = require('stringstream')
var stream = stringstream('hex', 'utf8')
stream.pipe(process.stdout)
stream.write(10000);
stream.end();

Run on Node.js 4.x (or lower). hex/utf8 is irrelevant, the issue is reproducable with all encodings.

Supporting Material/References:

  • Arch Linux Current
  • Node.js 4.8.7

Wrap up

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

Impact

Sensitive uninitialized memory exposure Denail of Service This issue affects only setups using Node.js 4.x (still supported) or lower.

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

Likely the module does not validate the type of input and passes a number directly to Buffer allocation, which on older Node.js versions returns uninitialized memory.

Impact

On Node.js 4.x and below, this could expose sensitive uninitialized memory or cause a denial of service; on Node.js 6.x and newer, the issue is blocked by a type check that throws an error.

What the attacker needed

Node.js 4.x or lower; typed user input passed to the stream

The fix

The module should not pass a number through to Buffer allocation.

How it was found

  1. Require the stringstream module and create a stream with hex and utf8 encodings.
  2. Pipe the stream to standard output.
  3. Write a number (e.g., 10000) to the stream.
  4. End the stream and observe the output on Node.js 4.x or lower.

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.

When a program creates a buffer (a chunk of memory) without filling it first, it may contain leftover data from other programs. If that buffer is then turned into a string and shown to a user, private information could leak. Also, asking for a very large buffer can crash the program by using too much memory.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

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.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.