Skip to content

Commit 36aadab

Browse files
test(worker): cover __proto__ key in entry-options-merge pollution guard
Add a computed `["__proto__"]` key to the second worker's webpackEntryOptions and assert the entrypoint options carry no `__proto__` own key and that their prototype is untouched, so the WorkerPlugin denylist is exercised for all three special keys.
1 parent 8ad7622 commit 36aadab

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

test/configCases/worker/entry-options-merge/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ it("should merge entryOptions when two async blocks share an entrypoint name", a
66
new URL("./worker.js", import.meta.url)
77
);
88
const w2 = new Worker(
9-
/* webpackEntryOptions: { name: "merged", runtime: "merged-rt", asyncChunks: false, prototype: { polluted: true }, constructor: { polluted: true } } */
9+
/* webpackEntryOptions: { name: "merged", runtime: "merged-rt", asyncChunks: false, prototype: { polluted: true }, constructor: { polluted: true }, ["__proto__"]: { polluted: true } } */
1010
new URL("./worker.js", import.meta.url)
1111
);
1212
expect({}.polluted).toBeUndefined();

test/configCases/worker/entry-options-merge/webpack.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ class AssertMergedEntryOptionsPlugin {
4040
}
4141
// Prototype-polluting keys from the magic comment must not be
4242
// gap-filled onto the entrypoint options.
43-
for (const unsafe of ["prototype", "constructor"]) {
43+
for (const unsafe of ["prototype", "constructor", "__proto__"]) {
4444
if (Object.prototype.hasOwnProperty.call(options, unsafe)) {
4545
compilation.errors.push(
4646
new Error(`entrypoint options must not carry "${unsafe}"`)
4747
);
4848
}
4949
}
50+
if (Object.getPrototypeOf(options) !== Object.prototype) {
51+
compilation.errors.push(
52+
new Error("entrypoint options prototype must be untouched")
53+
);
54+
}
5055
}
5156
);
5257
}

0 commit comments

Comments
 (0)