Skip to content

Commit

Permalink
prevent .constructor('return process') attack
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Jul 31, 2024
1 parent e43c635 commit 53c2d0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ function createBridge(otherInit, registerProxy) {
switch (key) {
case 'constructor': {
const desc = otherSafeGetOwnPropertyDescriptor(object, key);
if (desc) return thisDefaultGet(this, object, key, desc);
if (desc) {
if (desc.value && desc.value.name === 'Function') return {};
return thisDefaultGet(this, object, key, desc);
}
const proto = thisReflectGetPrototypeOf(target);
return proto === null ? undefined : proto.constructor;
}
Expand Down
10 changes: 10 additions & 0 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,16 @@ describe('VM', () => {
`), /Sandbox escape attempt blocked/);
});

it('constructor arbitrary code attack', async () => {
const vm2 = new VM();
assert.throws(()=>vm2.run(`
const g = ({}).__lookupGetter__;
const a = Buffer.apply;
const p = a.apply(g, [Buffer, ['__proto__']]);
p.call(a).constructor('return process')();
`), /constructor is not a function/);
});

after(() => {
vm = null;
});
Expand Down

0 comments on commit 53c2d0b

Please sign in to comment.