Skip to content

Commit b67284e

Browse files
committed
tools: add ArrayPrototypeConcat to the list of primordials to avoid
1 parent b3f5a41 commit b67284e

File tree

10 files changed

+45
-28
lines changed

10 files changed

+45
-28
lines changed

lib/internal/bootstrap/node.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ setupPrepareStackTrace();
5656

5757
const {
5858
Array,
59-
ArrayPrototypeConcat,
6059
ArrayPrototypeFill,
60+
ArrayPrototypePushApply,
6161
FunctionPrototypeCall,
6262
JSONParse,
6363
Number,
@@ -174,11 +174,11 @@ const rawMethods = internalBinding('process_methods');
174174

175175
process.getActiveResourcesInfo = function() {
176176
const timerCounts = internalTimers.getTimerCounts();
177-
return ArrayPrototypeConcat(
178-
rawMethods._getActiveRequestsInfo(),
179-
rawMethods._getActiveHandlesInfo(),
180-
ArrayPrototypeFill(new Array(timerCounts.timeoutCount), 'Timeout'),
181-
ArrayPrototypeFill(new Array(timerCounts.immediateCount), 'Immediate'));
177+
const info = rawMethods._getActiveRequestsInfo();
178+
ArrayPrototypePushApply(info, rawMethods._getActiveHandlesInfo());
179+
ArrayPrototypePushApply(info, ArrayPrototypeFill(new Array(timerCounts.timeoutCount), 'Timeout'));
180+
ArrayPrototypePushApply(info, ArrayPrototypeFill(new Array(timerCounts.immediateCount), 'Immediate'));
181+
return info;
182182
};
183183

184184
// TODO(joyeecheung): remove these

lib/internal/debugger/inspect.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
const {
4-
ArrayPrototypeConcat,
54
ArrayPrototypeForEach,
65
ArrayPrototypeJoin,
76
ArrayPrototypeMap,
87
ArrayPrototypePop,
8+
ArrayPrototypePushApply,
99
ArrayPrototypeShift,
1010
ArrayPrototypeSlice,
1111
FunctionPrototypeBind,
@@ -85,9 +85,8 @@ const debugRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//;
8585
async function runScript(script, scriptArgs, inspectHost, inspectPort,
8686
childPrint) {
8787
await portIsFree(inspectHost, inspectPort);
88-
const args = ArrayPrototypeConcat(
89-
[`--inspect-brk=${inspectPort}`, script],
90-
scriptArgs);
88+
const args = [`--inspect-brk=${inspectPort}`, script];
89+
ArrayPrototypePushApply(args, scriptArgs);
9190
const child = spawn(process.execPath, args);
9291
child.stdout.setEncoding('utf8');
9392
child.stderr.setEncoding('utf8');

lib/internal/main/print_help.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ for (const key of ObjectKeys(types))
3131
// Environment variables are parsed ad-hoc throughout the code base,
3232
// so we gather the documentation here.
3333
const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding('config');
34+
// eslint-disable-next-line node-core/avoid-prototype-pollution
3435
const envVars = new SafeMap(ArrayPrototypeConcat([
3536
['FORCE_COLOR', { helpText: "when set to 'true', 1, 2, 3, or an empty " +
3637
'string causes NO_COLOR and NODE_DISABLE_COLORS to be ignored.' }],

lib/internal/modules/cjs/loader.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
const {
2525
ArrayIsArray,
26-
ArrayPrototypeConcat,
2726
ArrayPrototypeFilter,
2827
ArrayPrototypeIncludes,
2928
ArrayPrototypeIndexOf,
@@ -769,9 +768,12 @@ Module._resolveLookupPaths = function(request, parent) {
769768
StringPrototypeCharAt(request, 1) !== '/' &&
770769
(!isWindows || StringPrototypeCharAt(request, 1) !== '\\'))) {
771770

772-
let paths = modulePaths;
771+
let paths;
773772
if (parent?.paths?.length) {
774-
paths = ArrayPrototypeConcat(parent.paths, paths);
773+
paths = ArrayPrototypeSlice(modulePaths);
774+
ArrayPrototypeUnshiftApply(paths, parent.paths);
775+
} else {
776+
paths = modulePaths;
775777
}
776778

777779
debug('looking for %j in %j', request, paths);

lib/internal/modules/esm/resolve.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const {
44
ArrayIsArray,
5-
ArrayPrototypeConcat,
65
ArrayPrototypeJoin,
6+
ArrayPrototypePush,
77
ArrayPrototypeShift,
88
JSONStringify,
99
ObjectFreeze,
@@ -986,11 +986,11 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
986986
)
987987
)
988988
) {
989-
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, ArrayPrototypeConcat(
990-
'file',
991-
'data',
992-
experimentalNetworkImports ? ['https', 'http'] : [],
993-
));
989+
const schemes = ['file', 'data'];
990+
if (experimentalNetworkImports) {
991+
ArrayPrototypePush(schemes, 'https', 'http');
992+
}
993+
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
994994
}
995995
}
996996

lib/internal/perf/observe.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const {
99
ArrayPrototypePushApply,
1010
ArrayPrototypeSlice,
1111
ArrayPrototypeSort,
12-
ArrayPrototypeConcat,
1312
Error,
1413
MathMax,
1514
MathMin,
@@ -513,7 +512,10 @@ function filterBufferMapByNameAndType(name, type) {
513512
// Unrecognized type;
514513
return [];
515514
} else {
516-
bufferList = ArrayPrototypeConcat(markEntryBuffer, measureEntryBuffer, resourceTimingBuffer);
515+
bufferList = [];
516+
ArrayPrototypePushApply(bufferList, markEntryBuffer);
517+
ArrayPrototypePushApply(bufferList, measureEntryBuffer);
518+
ArrayPrototypePushApply(bufferList, resourceTimingBuffer);
517519
}
518520
if (name !== undefined) {
519521
bufferList = ArrayPrototypeFilter(bufferList, (buffer) => buffer.name === name);

lib/internal/util/inspector.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const {
4-
ArrayPrototypeConcat,
54
ArrayPrototypeSome,
5+
ArrayPrototypePushApply,
66
FunctionPrototypeBind,
77
ObjectDefineProperty,
88
ObjectKeys,
@@ -69,10 +69,9 @@ function installConsoleExtensions(commandLineApi) {
6969
const { makeRequireFunction } = require('internal/modules/cjs/helpers');
7070
const consoleAPIModule = new CJSModule('<inspector console>');
7171
const cwd = tryGetCwd();
72-
consoleAPIModule.paths = ArrayPrototypeConcat(
73-
CJSModule._nodeModulePaths(cwd),
74-
CJSModule.globalPaths
75-
);
72+
consoleAPIModule.paths = [];
73+
ArrayPrototypePushApply(consoleAPIModule.paths, CJSModule._nodeModulePaths(cwd));
74+
ArrayPrototypePushApply(consoleAPIModule.paths, CJSModule.globalPaths);
7675
commandLineApi.require = makeRequireFunction(consoleAPIModule);
7776
}
7877

lib/repl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
'use strict';
4444

4545
const {
46-
ArrayPrototypeConcat,
4746
ArrayPrototypeFilter,
4847
ArrayPrototypeFindIndex,
4948
ArrayPrototypeForEach,
@@ -52,6 +51,7 @@ const {
5251
ArrayPrototypeMap,
5352
ArrayPrototypePop,
5453
ArrayPrototypePush,
54+
ArrayPrototypePushApply,
5555
ArrayPrototypeReverse,
5656
ArrayPrototypeShift,
5757
ArrayPrototypeSlice,
@@ -1332,7 +1332,9 @@ function complete(line, callback) {
13321332
} else if (RegExpPrototypeExec(/^\.\.?\//, completeOn) !== null) {
13331333
paths = [process.cwd()];
13341334
} else {
1335-
paths = ArrayPrototypeConcat(module.paths, CJSModule.globalPaths);
1335+
paths = [];
1336+
ArrayPrototypePushApply(paths, module.paths);
1337+
ArrayPrototypePushApply(paths, CJSModule.globalPaths);
13361338
}
13371339

13381340
ArrayPrototypeForEach(paths, (dir) => {

test/parallel/test-eslint-avoid-prototype-pollution.js

+4
Original file line numberDiff line numberDiff line change
@@ -295,5 +295,9 @@ new RuleTester({
295295
code: 'PromiseRace([])',
296296
errors: [{ message: /\bSafePromiseRace\b/ }]
297297
},
298+
{
299+
code: 'ArrayPrototypeConcat([])',
300+
errors: [{ message: /\bisConcatSpreadable\b/ }]
301+
},
298302
]
299303
});

tools/eslint-rules/avoid-prototype-pollution.js

+8
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ module.exports = {
224224
message: `Use Safe${node.callee.name} instead of ${node.callee.name}`,
225225
});
226226
},
227+
228+
[CallExpression('ArrayPrototypeConcat')](node) {
229+
context.report({
230+
node,
231+
message: '%Array.prototype.concat% looks up `@@isConcatSpreadable` ' +
232+
'which can be subject to prototype pollution',
233+
});
234+
},
227235
};
228236
},
229237
};

0 commit comments

Comments
 (0)