`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.
- 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
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)
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)
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
- Ensure memcached is running.
- Create a memjs client.
- Call client.set with a large numeric value and an expiry.
- Observe denial of service due to buffer allocation.
- 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.