Skip to content

Commit e2a74f3

Browse files
tniessenrichardlau
authored andcommittedJan 7, 2022
console: fix prototype pollution via console.table
CVE-ID: CVE-2022-21824 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 9f2c526 commit e2a74f3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

β€Žlib/internal/console/constructor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515
MathFloor,
1616
Number,
1717
NumberPrototypeToFixed,
18+
ObjectCreate,
1819
ObjectDefineProperties,
1920
ObjectDefineProperty,
2021
ObjectKeys,
@@ -555,7 +556,7 @@ const consoleMethods = {
555556
return final([iterKey, valuesKey], [getIndexArray(length), values]);
556557
}
557558

558-
const map = {};
559+
const map = ObjectCreate(null);
559560
let hasPrimitives = false;
560561
const valuesKeyArray = [];
561562
const indexKeyArray = ObjectKeys(tabularData);

β€Žtest/parallel/test-console-table.js

+15
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)
Please sign in to comment.