Skip to content
Memory corruption Disclosed report Advanced CVE-2020-8244

[bl] Uninitialized memory exposure via negative .consume()

A negative argument to the BufferList consume() method corrupts internal state, causing slice() to return uninitialized memory. An attacker who controls the consume() argument could expose sensitive data from process memory.

chalker Follow

Originally disclosed on HackerOne

High 7.7 View original
  • Triaged in 3 days
  • Fixed in 3 days
  • Disclosed after 3 days

Module

module name: bl version: 4.0.2 npm page: https://www.npmjs.com/package/bl

Module Description

A Node.js Buffer list collector, reader and streamer thingy.

Module Stats

8 660 595 weekly downloads

Vulnerability

Vulnerability Description

If user input (even typed) ends up in consume() argument and can become negative, BufferList state can be corrupted, tricking it into exposing uninitialized memory via regular .slice() calls.

Steps To Reproduce:

const { BufferList } = require('bl')
const secret = require('crypto').randomBytes(256)
for (let i = 0; i < 1e6; i++) {
  const clone = Buffer.from(secret)
  const bl = new BufferList()
  bl.append(Buffer.from('a'))
  bl.consume(-1024)
  const buf = bl.slice(1)
  if (buf.indexOf(clone) !== -1) {
    console.error(`Match (at ${i})`, buf)
  }
}

Patch

First component (more important):

In BufferList.prototype.copy, before the last return dst:

JavaScript
  if (dst.length !== bufoff) return dst.slice(0, bufoff)

Second component:

Check .consume() argument to be a non-negative integer.

Supporting Material/References:

  • Node.js v14.8.0

Wrap up

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

Impact

In case if the argument of consume() is attacker controlled:

  1. Expose uninitialized memory, containing source code, passwords, network traffic, etc.
  2. Cause invalid data in slices (low control)
  3. Cause DoS by allocating a large buffer this way (with a large negative number before a slice/toString call is performed).

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 consume() method does not validate that its argument is a non-negative integer, and the copy() method does not correctly handle a buffer offset that exceeds the destination length.

Impact

If the consume() argument is attacker-controlled, uninitialized memory containing source code, passwords, or network traffic could be exposed; invalid data may appear in slices, and a large negative number before a slice or toString call could cause a denial of service by allocating a large buffer.

What the attacker needed

Attacker controls consume() argument

The fix

The copy() method should truncate the destination to the buffer offset, and consume() should reject negative or non-integer arguments.

How it was found

  1. Create a BufferList and append a single byte.
  2. Call consume() with a large negative number.
  3. Call slice() starting at index 1.
  4. Check whether the returned buffer contains the secret data.

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.

A library for handling buffers (chunks of binary data) has a method that can be given a negative number. This confuses the library's internal bookkeeping, so when you later ask for a slice of the data, it hands back memory that was never properly initialised, which may contain leftover secrets from other parts of the program.

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.