8000 console: fix prototype pollution via console.table · nodejs/node@be69403 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit be69403

Browse files
tniessenrichardlau
authored andcommitted
console: fix prototype pollution via console.table
CVE-ID: CVE-2022-21824 Backport-PR-URL: nodejs-private/node-private#308 PR-URL: nodejs-private/node-private#307 Refs: https://hackerone.com/reports/1431042 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent ff9ac7d commit be69403

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/internal/console/constructor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
Boolean,
1010
Error,
1111
Map,
12+
ObjectCreate,
1213
ObjectDefineProperties,
1314
ObjectDefineProperty,
1415
ObjectKeys,
@@ -532,7 +533,7 @@ const consoleMethods = {
532533
return final([iterKey, valuesKey], [getIndexArray(length), values]);
533534
}
534535

535-
const map = {};
536+
const map = ObjectCreate(null);
536537
let hasPrimitives = false;
537538
const valuesKeyArray = [];
538539
const indexKeyArray = ObjectKeys(tabularData);

test/parallel/test-console-table.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,18 @@ test({ foo: '你好', bar: 'hello' }, `
276276
│ bar │ 'hello' │
277277
└─────────┴─────────┘
278278
`);
279+
280+
// Regression test for prototype pollution via console.table. Earlier versions
281+
// of Node.js created an object with a non-null prototype within console.table
282+
// and then wrote to object[column][index], which lead to an error as well as
283+
// modifications to Object.prototype.
284+
test([{ foo: 10 }, { foo: 20 }], ['__proto__'], `
285+
┌─────────┬───────────┐
286+
│ (index) │ __proto__ │
287+
├─────────┼───────────┤
288+
│ 0 │ │
289+
│ 1 │ │
290+
└─────────┴───────────┘
291+
`);
292+
assert.strictEqual('0' in Object.prototype, false);
293+
assert.strictEqual('1' in Object.prototype, false);

0 commit comments

Comments
 (0)
0