Skip to content
Memory corruption Disclosed report Intermediate

`byte` allocates uninitialized buffers and reads data from them past the initialized length

The byte module allocates uninitialized buffers and its read API does not check whether the requested memory was ever written. An attacker could read leftover process memory, potentially containing sensitive information.

chalker Follow

Originally disclosed on HackerOne

Medium 5.2 View original
  • Triaged in 12 days
  • Fixed in 45 days
  • Disclosed after 45 days

I would like to report a memory exposure vulnerbaility in byte It allows to extract process memory using Buffers in some cases.

Module

module name: byte version: 1.4.0 npm page: https://www.npmjs.com/package/byte

Module Description

Input Buffer and Output Buffer, just like Java ByteBuffer.

Module Stats

705 downloads in the last day 3 836 downloads in the last week 14 813 downloads in the last month

Vulnerability

Vulnerability Description

byte allocates uninitialized buffers on all Node.js versions, even on the ones that zero-full new Buffer() by default, as it uses .allocUnsafe(). It provides an API for writing data and an API for reading data from the buffer, but the internal buffer is not zero-filled and the API for reading does not validate that the memory being read was ever initialized.

I also don't think this corresponds to behavior of the Java ByteBuffer — that one is zero-filled afaik.

Steps To Reproduce:

JavaScript
var ByteBuffer = require('byte');
for (let k = 0; k < 1e4; k++) {
  var bb = new ByteBuffer();
  for (let i = 0; i < 180; i++) {
    bb.putString('ok');
  }
  const s = bb.getString(1000);
  if (s.includes(' {')) {
    console.log(s);
    console.log('Finished at attempt: ' + k);
    break;
  }
}
JavaScript
var ByteBuffer = require('byte');
for (let k = 0; k < 1e4; k++) {
  var bb = ByteBuffer.allocate(50);
  const twos = Buffer.alloc(10, 2);
  for (let i = 0; i < 7; i++) bb.put(twos, 10);
  const s = bb.get(0, 100);
  if (s.includes(' {')) {
    console.log(s.toString('utf-8'));
    console.log('Finished at attempt: ' + k);
    break;
  }
}

Patch

Replace all Buffer(num) and Buffer.allocUnsafe(num) usage with Buffer.alloc(num) and use a polyfill, e.g. safer-buffer or buffer-alloc.

Supporting Material/References:

  • OS: Arch Linux current
  • Node.js 9.9.0
  • npm 5.8.0

Wrap up

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

Impact

Read process memory containing sensitive information.

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 module uses unsafe buffer allocation and its read methods do not enforce that the requested range was previously written.

Impact

An attacker could read process memory that may contain sensitive information.

What the attacker needed

Ability to run code using the byte module

The fix

The module should replace unsafe buffer allocations with zero-filled allocations, for example by using Buffer.alloc or a polyfill.

How it was found

  1. Create a new ByteBuffer instance.
  2. Write a string repeatedly to fill part of the buffer.
  3. Read a larger amount of data than was written.
  4. Check whether the returned string contains leftover memory content.

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 asks the computer for memory, that memory may still contain data from earlier use. If the program hands that memory back without clearing it, someone can read old passwords or other secrets. This module does exactly that: it gives out memory without clearing it and lets you read beyond what you wrote.

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.