Skip to content
Memory corruption Disclosed report Intermediate

`npmconf` (and `npm` js api) allocate and write to disk uninitialized memory content when a typed number is passed as input on Node.js 4.x

When a number is passed as the password to setCredentialsByURI, npmconf and npm allocate uninitialized Buffer instances during base64 conversion on Node.js 4.x because of missing type checks. An attacker could read sensitive data from uninitialized memory or cause a denial of service by forcing a large allocation.

chalker Follow

Originally disclosed on HackerOne

High 7.4 View original
  • Triaged in 29 days
  • Fixed in 2 months
  • Disclosed after 2 months

I would like to report a Buffer allocation issue in npmconf (and npm package js api). It allows to extract sensitive content from uninitialized memory by passing typed input to setCredentialsByURI, limited to Node.js 4.x and below.

Module

module name: npmconf version: 2.1.2 npm page: https://www.npmjs.com/package/npmconf

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

Module Description

The config thing npm uses

Module Stats

npmconf

40 292 downloads in the last day 219 837 downloads in the last week 897 947 downloads in the last month

~1 0775 364 estimated downloads per year

npmconf is deprecated, but doesn't mention security issues and is still widely used, and the usage seems to increase over time.

npm

npm download stats are not representive here, as it's mainly used as a CLI, not as JS api, but here they are (e.g. for comparison with npmconf):

141 545 downloads in the last day 1 067 194 downloads in the last week 3 701 192 downloads in the last month

~44 414 304 estimated downloads per year

Vulnerability

Vulnerability Description

When a number is passed to the password property of config.setCredentialsByURI, npmconf/npm allocate uninitialized Buffer instances during conversion to base64 (on Node.js 4.x) due to missing type checks before passing user input to the new Buffer() constructor.

Those Buffer instances could (and most likely will) contain sensitive information, see Buffer-knows-everything.md.

Node.js 4.x is stated as supported in npm.

Steps To Reproduce:

Use Node.js 4.x LTS or below.

npmconf

JavaScript
var URI = "https://registry.example.com:8661/";
require('npmconf').load({}, function (err, conf) {
  conf.setCredentialsByURI(URI, {username: 'foo', email: '[email protected]', password: 200});
  console.log(conf.getCredentialsByURI(URI)); // This just outputs the setting
  // conf.save('user', function() {}) // Warning: writes base64-encoded uninitialized buffer .npmrc
});

npm

JavaScript
var URI = "https://registry.example.com:8661/";
require('npm').load({}, function (err, npm) {
  npm.config.setCredentialsByURI(URI, {username: 'foo', email: '[email protected]', password: 200});
  console.log(npm.config.getCredentialsByURI(URI)); // This just outputs the setting
  // npm.config.save('user', function() {}) // Warning: writes base64-encoded uninitialized buffer .npmrc
});

Supporting Material/References:

  • Arch Linux
  • Node.js v4.8.7 (latest in 4.x LTS branch)
  • npm 5.6.0

Wrap up

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

I reported this initially on 2016-01-20 over email, but didn't receive any response. Probably was deemed insignificant or out-of-scope, but I still think this should be fixed and disclosed.

Impact

Read uninitialized memory, extracting sensitive information from it. Cause a DoS by large Buffer allocation and conversion to string.

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 missing type validation before passing user input to the new Buffer() constructor, which on Node.js 4.x returns uninitialized memory.

Impact

An attacker could read uninitialized memory to extract sensitive information, or cause a denial of service through a large Buffer allocation and conversion to string; the issue is limited to Node.js 4.x and below.

What the attacker needed

Node.js 4.x or below; ability to pass a number as password

How it was found

  1. Use Node.js 4.x LTS or below.
  2. Load npmconf (or npm) and call setCredentialsByURI with a URI and an object whose password is a number.
  3. Optionally call save('user') to write the base64-encoded uninitialized buffer to .npmrc.

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 Buffer is a chunk of memory used by Node.js to hold raw data. Normally it is zeroed out, but on old Node.js versions a new Buffer could contain leftover data from other parts of the program. If a number is given where a password string is expected, the code does not check the type and creates such a Buffer, which may then be encoded and saved, leaking whatever was in 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.