Skip to content
Prototype pollution Disclosed report Intermediate CVE-2022-21824

Prototype pollution via console.table properties

The console.table function in Node.js allows prototype pollution when an attacker controls the second properties parameter and a plain object is passed as the first parameter. This can assign empty strings to numerical keys of the object prototype, potentially causing denial of service or, in rare cases, bypassing authorization.

rugvip Follow

Originally disclosed on HackerOne

  • Triaged in 34 hours
  • Fixed in 22 days
  • Disclosed after 23 days

Summary:

Attacker control of the second properties parameter of console.table may lead to prototype pollution.

Description:

Due to the formatting logic of the console.table function it is not safe to allow user controlled input to be passed to the properties parameter while simultaneously passing a plain object with at least one property as the first parameter.

The prototype pollution has very limited control, in that it only allows an empty string to be assigned numerical keys of the object prototype.

Steps To Reproduce:

The vulnerability can be reproduced in the Node.js REPL, tested with version v16.7.0:

  1. Run the following: console.table({foo: 'bar'}, ['__proto__'])
  2. Verify that the object prototype has been polluted: Object.prototype[0] === ''

The pollution will vary depending on the number of properties on the object passed as the first parameter, with each additional property assigning another incrementing index of the object prototype. This means that if the first parameter is also controlled by the attacker, it is possible to assign empty strings from 0..n to the object prototype, for any n:

> console.table({a: 1, b: 1, c: 1}, ['__proto__'])
Uncaught TypeError: Cannot create property '0' on string ''

> Object.prototype
[Object: null prototype] { '0': '', '1': '', '2': '' }

The vulnerable assignment can be found here in the Node.js console.table implementation.

A suggested remediation is to ignore properties named '__proto__', or to use a different data structure to store the computed table fields. For example:

Diff
 const keys = properties || ObjectKeys(item);
 for (const key of keys) {
+  if (key === '__proto__') {
+    continue
+  }
   if (map[key] === undefined)
     map[key] = [];

Impact:

Users of console.table have no reason to expect the danger of passing on user input to the second properties array, and may therefore do so without sanitation. In the even that for example a web server is exposed to this vulnerability, it is likely to be a very effective denial of service attack. In extremely rare cases the prototype pollution can lead to more severe attack vectors such as bypassing authorization mechanisms, although due to limited control of the pollution this is unlikely.

Supporting Material/References:

Impact

Users of console.table have no reason to expect the danger of passing on user input to the second properties array, and may therefore do so without sanitation. In the even that for example a web server is exposed to this vulnerability, it is likely to be a very effective denial of service attack. In extremely rare cases the prototype pollution can lead to more severe attack vectors such as bypassing authorization mechanisms, although due to limited control of the pollution this is unlikely.

The original report as published on HackerOne, by rugvip. 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 console.table implementation does not filter out the special key '__proto__' when processing the properties array, allowing assignment to the object prototype.

Impact

If a web server exposes this vulnerability, it is likely to be a very effective denial of service attack; in extremely rare cases it could lead to bypassing authorization mechanisms, though this is unlikely due to limited control.

What the attacker needed

Attacker controls properties parameter; first parameter is a plain object

The fix

The fix should ignore properties named '__proto__' or use a different data structure to store the computed table fields.

How it was found

  1. Run console.table with a plain object and an array containing '__proto__' as the properties parameter.
  2. Check that Object.prototype[0] is now an empty string.

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.

Prototype pollution is a bug where an attacker can add or change properties on a base object that many other objects inherit from. In this case, the console.table function in Node.js can be tricked into adding empty strings to the prototype of all objects. This might break things or, in rare cases, let an attacker bypass security checks.

What is Prototype pollution?

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Prototype pollution

The lesson behind this report.

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.