Skip to content
Memory corruption Disclosed report Intermediate

`base64-url` below 2.0 allocates uninitialized Buffers when number is passed in input

The base64-url library, when given a number instead of a string, allocates an uninitialized Buffer. On Node.js 6.x and below this can leak sensitive memory contents, and on any Node.js version a large number can cause a denial of service by consuming memory.

chalker Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 9 days
  • Fixed in 2 months
  • Disclosed after 2 months

I would like to report an uninitialized Buffer allocation issue in base64-url. 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 (e.g. from JSON).

Module

module name: base64-url version: 1.3.3 npm page: https://www.npmjs.com/package/base64-url

Module Description

Base64 encode, decode, escape and unescape for URL applications.

Module Stats

48 047 downloads in the last day 311 047 downloads in the last week 1 374 420 downloads in the last month

Vulnerability

Vulnerability Description

The problem arises when a number is passed in, e.g. from user-submitted JSON-encoded data. The API should not propagate the already-bad Buffer issue further.

On Node.js 6.x and below, this exposes uninitialized memory, which could contain sensitive data.

This can be also used to cause a DoS on any Node.js version by consuming the memory when large numbers are passed on input.

Steps To Reproduce:

console.log(require('base64-url').encode(1000)) (Node.js 6.x and lower — note uninitialized memory in output)

require('base64-url').encode(1e8) (any Node.js verision — note memory usage and time)

Supporting Material/References:

  • OS: Arch Linux current
  • Node.js 6.13.0
  • Node.js 9.5.0

Wrap up

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

I contacted the author on 2017-03-02. I did not receive a reply, but on 2017-08-17 a semver-major version 2.0.0 was released with a fix.

I want a CVE assigned to this issue, also I would prefer the fix to be backported to 1.x branch — a lot of modules still depend 1.x as of 2018-02-26.

Top-10 apps @latest versions of which install affected base64-url@1 through their deps chains:

664945  react-native
346288  metro-bundler
83764   hubot
81089   sails
51724   phonegap
45522   csrf-tokens
28326   hubot-mock-adapter
25778   mock-hubot
23712   connect-phonegap
18808   nodedata

In total, there are about 2460 such apps in the npm registry, to my knowledge.

Impact

Sensitive uninitialized memory exposure on Node.js 6.x or lower Denail of Service on any Node.js version

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 library passed the input directly to Buffer allocation without validating that it was a string, so a number was interpreted as a buffer length and the buffer was not zero-filled.

Impact

On Node.js 6.x and below, sensitive data from uninitialized memory could be exposed; on any Node.js version, a large number could cause a denial of service by consuming memory.

What the attacker needed

Application passes user-controlled number to library; Node.js 6.x or lower for memory exposure; any Node.js version for DoS

The fix

The issue was fixed in a semver-major version 2.0.0 released on 2017-08-17, though the reporter would prefer the fix backported to the 1.x branch.

How it was found

  1. Call the encode function with a small number on Node.js 6.x or lower and observe uninitialized memory in the output.
  2. Call the encode function with a very large number on any Node.js version and observe memory usage and time.

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 that encodes and decodes base64 text was not checking the type of its input. If a program passed it a number (for example, from user-supplied JSON), the library treated that number as a size and created a chunk of computer memory without clearing it first. On older versions of Node.js, that memory could still hold private data from other parts of the program, and a very large number could use up all the memory and crash the process.

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.