Skip to content

Commit

Permalink
throw when sandbox escape attempt is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Oct 6, 2023
1 parent 5b2e81f commit 748082d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/setup-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PromiseCtor = Promise;
const speciesSymbol = Symbol.species;
const localReflectApply = (target, thisArg, args) => {
if (thisArg instanceof PromiseCtor && thisArg.constructor[speciesSymbol] !== PromiseCtor) {
Object.defineProperty(thisArg.constructor, speciesSymbol, { value: PromiseCtor });
throw new Error('Sandbox escape attempt blocked');
}
return apply(target, thisArg, args);
};
Expand Down
5 changes: 2 additions & 3 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ describe('VM', () => {

it('[Symbol.species] attack', async () => {
const vm2 = new VM();
const promise = vm2.run(`
assert.throws(()=> vm2.run(`
class WrappedPromise extends Promise {
constructor(executor) {
super((resolve) => resolve(42));
Expand All @@ -1172,8 +1172,7 @@ describe('VM', () => {
const promise = new Promise((resolve, reject) => resolve(41));
promise.constructor = { [Symbol.species]: WrappedPromise };
promise.then();
`);
assert.strictEqual(await promise, 41);
`), /Sandbox escape attempt blocked/);
});

after(() => {
Expand Down

0 comments on commit 748082d

Please sign in to comment.