Skip to content
DoS Disclosed report Intermediate CVE-2018-3767

`memjs` allocates and stores buffers on typed input, resulting in DoS and uninitialized memory usage

The memjs library passes the value option directly to the Buffer constructor without sanitisation, so typed input such as a number causes a huge buffer allocation leading to denial of service, and on older Node.js versions stores uninitialised memory that could later be read back.

chalker Follow

Originally disclosed on HackerOne

Critical 10.0 View original
  • Triaged in 12 days
  • Fixed in 4 months
  • Disclosed after 4 months

I would like to report a Buffer allocation vulnerability in memjs.

In cases when the attacker is able to pass typed input (e.g. via JSON) to the storage, it allows to cause DoS (on all Node.js versions) and to store (and potentially later extract) chunks of uninitialized server memory containing sensitive data.

Module

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

Module Description

MemJS is a pure Node.js client library for using memcache, in particular, the MemCachier service. It uses the binary protocol and support SASL authentication.

Module Stats

186 downloads in the last day 2 903 downloads in the last week 12 037 downloads in the last month

~144 444 estimated downloads per year (yay, a pretty number)

Vulnerability

Vulnerability Description

memjs passes value option to the Buffer constructor without proper sanitization, resulting in DoS and uninitialized memory leak in setups where an attacker could submit typed input to the 'value' parameter (e.g. JSON).

Steps To Reproduce:

memcached should be up and running.

DoS

JavaScript
var client = require('memjs').Client.create()
function tick() {
  var value = 2e9;
  client.set('key', value, {expires: 600 }, () => {});
}
setInterval(tick, 200);

Uninitialized memory exposed (when running on Node.js below 8.0)

JavaScript
var client = require('memjs').Client.create()
var value = 100;
client.set('key', value, {expires: 600 }, () => {});
client.get('key', (err, val) => console.log(val));

Supporting Material/References:

  • OS: Arch Linux current
  • Node.js 9.5.0
  • npm 5.6.0
  • memcached 1.5.5

Wrap up

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

Impact

Denial of service Sensitive data leak (on Node.js < 8.x)

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 does not validate the type of the value option before passing it to the Buffer constructor, so a number is interpreted as a buffer length.

Impact

An attacker could cause denial of service on all Node.js versions and, on Node.js below 8.0, leak sensitive uninitialised server memory.

What the attacker needed

Attacker can submit typed input to value; memcached running; Node.js below 8.0 for memory leak

The fix

The library should validate and sanitise the value option before passing it to the Buffer constructor.

How it was found

  1. Ensure memcached is running.
  2. Create a memjs client.
  3. Call client.set with a large numeric value and an expiry.
  4. Observe denial of service due to buffer allocation.
  5. On Node.js below 8.0, call client.get to retrieve uninitialised memory.

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 you store a value in a cache, the library should treat it as data, not as a size. Here, if an attacker sends a number instead of text, the library tries to create a buffer of that many bytes, which can crash the server or expose leftover memory.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.