Skip to content

Commit

Permalink
Merge pull request #445 from XmiliaH/fix-444
Browse files Browse the repository at this point in the history
Security fix for issue 444.
  • Loading branch information
XmiliaH authored Jul 5, 2022
2 parents 245da82 + c01280c commit e3e573f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/setup-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const {
AsyncGeneratorFunction
} = data;

const localWeakMapGet = LocalWeakMap.prototype.get;
const {
get: localWeakMapGet,
set: localWeakMapSet
} = LocalWeakMap.prototype;

function localUnexpected() {
return new VMError('Should not happen');
Expand Down Expand Up @@ -282,8 +285,8 @@ if (typeof OriginalCallSite === 'function') {
}
return value(error, sst);
};
wrappedPrepareStackTrace.set(value, newWrapped);
wrappedPrepareStackTrace.set(newWrapped, newWrapped);
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [value, newWrapped]);
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [newWrapped, newWrapped]);
currentPrepareStackTrace = newWrapped;
}
})) throw localUnexpected();
Expand Down
12 changes: 12 additions & 0 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,18 @@ describe('VM', () => {
const sst = vm2.run('Error.prepareStackTrace = (e,sst)=>sst;const sst = new Error().stack;Error.prepareStackTrace = undefined;sst');
assert.strictEqual(vm2.run('sst=>Object.getPrototypeOf(sst)')(sst), vm2.run('Array.prototype'));
assert.throws(()=>vm2.run('sst=>sst[0].getThis().constructor.constructor')(sst), /TypeError: Cannot read propert.*constructor/);
assert.throws(()=>vm2.run(`
const { set } = WeakMap.prototype;
WeakMap.prototype.set = function(v) {
return set.call(this, v, v);
};
Error.prepareStackTrace =
Error.prepareStackTrace =
(_, c) => c.map(c => c.getThis()).find(a => a);
const { stack } = new Error();
Error.prepareStackTrace = undefined;
stack.process
`));
});

it('Node internal prepareStackTrace attack', () => {
Expand Down

0 comments on commit e3e573f

Please sign in to comment.