Skip to content

Commit fe474c0

Browse files
committed
lib: add lint rule to protect against Object.prototype.then pollution
1 parent 1f7e8d6 commit fe474c0

File tree

12 files changed

+104
-36
lines changed

12 files changed

+104
-36
lines changed

lib/internal/crypto/cfrg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
188188
privateUsages,
189189
extractable);
190190

191-
return { privateKey, publicKey };
191+
return { __proto__: null, privateKey, publicKey };
192192
}
193193

194194
function cfrgExportKey(key, format) {

lib/internal/crypto/ec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
146146
privateUsages,
147147
extractable);
148148

149-
return { publicKey, privateKey };
149+
return { __proto__: null, publicKey, privateKey };
150150
}
151151

152152
function ecExportKey(key, format) {

lib/internal/crypto/rsa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async function rsaKeyGenerate(
219219
privateUsages,
220220
extractable);
221221

222-
return { publicKey, privateKey };
222+
return { __proto__: null, publicKey, privateKey };
223223
}
224224

225225
function rsaExportKey(key, format) {

lib/internal/fs/cp/cp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async function checkPaths(src, dest, opts) {
115115
code: 'EINVAL',
116116
});
117117
}
118-
return { srcStat, destStat, skipped: false };
118+
return { __proto__: null, srcStat, destStat, skipped: false };
119119
}
120120

121121
function areIdentical(srcStat, destStat) {

lib/internal/fs/promises.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ async function read(handle, bufferOrParams, offset, length, position) {
580580
length |= 0;
581581

582582
if (length === 0)
583-
return { bytesRead: length, buffer };
583+
return { __proto__: null, bytesRead: length, buffer };
584584

585585
if (buffer.byteLength === 0) {
586586
throw new ERR_INVALID_ARG_VALUE('buffer', buffer,
@@ -595,7 +595,7 @@ async function read(handle, bufferOrParams, offset, length, position) {
595595
const bytesRead = (await binding.read(handle.fd, buffer, offset, length,
596596
position, kUsePromises)) || 0;
597597

598-
return { bytesRead, buffer };
598+
return { __proto__: null, bytesRead, buffer };
599599
}
600600

601601
async function readv(handle, buffers, position) {
@@ -606,12 +606,12 @@ async function readv(handle, buffers, position) {
606606

607607
const bytesRead = (await binding.readBuffers(handle.fd, buffers, position,
608608
kUsePromises)) || 0;
609-
return { bytesRead, buffers };
609+
return { __proto__: null, bytesRead, buffers };
610610
}
611611

612612
async function write(handle, buffer, offsetOrOptions, length, position) {
613613
if (buffer?.byteLength === 0)
614-
return { bytesWritten: 0, buffer };
614+
return { __proto__: null, bytesWritten: 0, buffer };
615615

616616
let offset = offsetOrOptions;
617617
if (isArrayBufferView(buffer)) {
@@ -636,14 +636,14 @@ async function write(handle, buffer, offsetOrOptions, length, position) {
636636
const bytesWritten =
637637
(await binding.writeBuffer(handle.fd, buffer, offset,
638638
length, position, kUsePromises)) || 0;
639-
return { bytesWritten, buffer };
639+
return { __proto__: null, bytesWritten, buffer };
640640
}
641641

642642
validateStringAfterArrayBufferView(buffer, 'buffer');
643643
validateEncoding(buffer, length);
644644
const bytesWritten = (await binding.writeString(handle.fd, buffer, offset,
645645
length, kUsePromises)) || 0;
646-
return { bytesWritten, buffer };
646+
return { __proto__: null, bytesWritten, buffer };
647647
}
648648

649649
async function writev(handle, buffers, position) {
@@ -653,12 +653,12 @@ async function writev(handle, buffers, position) {
653653
position = null;
654654

655655
if (buffers.length === 0) {
656-
return { bytesWritten: 0, buffers };
656+
return { __proto__: null, bytesWritten: 0, buffers };
657657
}
658658

659659
const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
660660
kUsePromises)) || 0;
661-
return { bytesWritten, buffers };
661+
return { __proto__: null, bytesWritten, buffers };
662662
}
663663

664664
async function rename(oldPath, newPath) {

lib/internal/modules/esm/load.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function getSource(url, context) {
5959
if (policy?.manifest) {
6060
policy.manifest.assertIntegrity(parsed, source);
6161
}
62-
return { responseURL, source };
62+
return { __proto__: null, responseURL, source };
6363
}
6464

6565

@@ -93,6 +93,7 @@ async function defaultLoad(url, context) {
9393
}
9494

9595
return {
96+
__proto__: null,
9697
format,
9798
responseURL,
9899
source,

lib/internal/modules/esm/loader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ class ESMLoader {
378378
const { module } = await job.run();
379379

380380
return {
381+
__proto__: null,
381382
namespace: module.getNamespace(),
382383
};
383384
}
@@ -664,6 +665,7 @@ class ESMLoader {
664665
}
665666

666667
return {
668+
__proto__: null,
667669
format,
668670
responseURL,
669671
source,
@@ -880,6 +882,7 @@ class ESMLoader {
880882
}
881883

882884
return {
885+
__proto__: null,
883886
format,
884887
url,
885888
};

lib/internal/modules/esm/module_job.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class ModuleJob {
215215
}
216216
throw e;
217217
}
218-
return { module: this.module };
218+
return { __proto__: null, module: this.module };
219219
}
220220
}
221221
ObjectSetPrototypeOf(ModuleJob.prototype, null);

lib/internal/modules/esm/resolve.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ async function defaultResolve(specifier, context = {}) {
977977
missing = false;
978978
} else if (destination) {
979979
const href = destination.href;
980-
return { url: href };
980+
return { __proto__: null, url: href };
981981
}
982982
if (missing) {
983983
// Prevent network requests from firing if resolution would be banned.
@@ -1017,7 +1017,7 @@ async function defaultResolve(specifier, context = {}) {
10171017
)
10181018
)
10191019
) {
1020-
return { url: parsed.href };
1020+
return { __proto__: null, url: parsed.href };
10211021
}
10221022
} catch {
10231023
// Ignore exception
@@ -1035,7 +1035,7 @@ async function defaultResolve(specifier, context = {}) {
10351035
if (maybeReturn) return maybeReturn;
10361036

10371037
// This must come after checkIfDisallowedImport
1038-
if (parsed && parsed.protocol === 'node:') return { url: specifier };
1038+
if (parsed && parsed.protocol === 'node:') return { __proto__: null, url: specifier };
10391039

10401040
throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports);
10411041

@@ -1087,6 +1087,7 @@ async function defaultResolve(specifier, context = {}) {
10871087
throwIfUnsupportedURLProtocol(url);
10881088

10891089
return {
1090+
__proto__: null,
10901091
// Do NOT cast `url` to a string: that will work even when there are real
10911092
// problems, silencing them
10921093
url: url.href,

lib/internal/webstreams/readablestream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class ReadableStream {
476476

477477
async function returnSteps(value) {
478478
if (done)
479-
return { done: true, value };
479+
return { done: true, value }; // eslint-disable-line node-core/avoid-prototype-pollution
480480
done = true;
481481

482482
if (reader[kState].stream === undefined) {
@@ -488,11 +488,11 @@ class ReadableStream {
488488
const result = readableStreamReaderGenericCancel(reader, value);
489489
readableStreamReaderGenericRelease(reader);
490490
await result;
491-
return { done: true, value };
491+
return { done: true, value }; // eslint-disable-line node-core/avoid-prototype-pollution
492492
}
493493

494494
readableStreamReaderGenericRelease(reader);
495-
return { done: true, value };
495+
return { done: true, value }; // eslint-disable-line node-core/avoid-prototype-pollution
496496
}
497497

498498
// TODO(@jasnell): Explore whether an async generator

0 commit comments

Comments
 (0)