Skip to content

Commit e3e573f

Browse files
authored
Merge pull request #445 from XmiliaH/fix-444
Security fix for issue 444.
2 parents 245da82 + c01280c commit e3e573f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/setup-sandbox.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const {
5151
AsyncGeneratorFunction
5252
} = data;
5353

54-
const localWeakMapGet = LocalWeakMap.prototype.get;
54+
const {
55+
get: localWeakMapGet,
56+
set: localWeakMapSet
57+
} = LocalWeakMap.prototype;
5558

5659
function localUnexpected() {
5760
return new VMError('Should not happen');
@@ -282,8 +285,8 @@ if (typeof OriginalCallSite === 'function') {
282285
}
283286
return value(error, sst);
284287
};
285-
wrappedPrepareStackTrace.set(value, newWrapped);
286-
wrappedPrepareStackTrace.set(newWrapped, newWrapped);
288+
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [value, newWrapped]);
289+
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [newWrapped, newWrapped]);
287290
currentPrepareStackTrace = newWrapped;
288291
}
289292
})) throw localUnexpected();

test/vm.js

+12
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,18 @@ describe('VM', () => {
10581058
const sst = vm2.run('Error.prepareStackTrace = (e,sst)=>sst;const sst = new Error().stack;Error.prepareStackTrace = undefined;sst');
10591059
assert.strictEqual(vm2.run('sst=>Object.getPrototypeOf(sst)')(sst), vm2.run('Array.prototype'));
10601060
assert.throws(()=>vm2.run('sst=>sst[0].getThis().constructor.constructor')(sst), /TypeError: Cannot read propert.*constructor/);
1061+
assert.throws(()=>vm2.run(`
1062+
const { set } = WeakMap.prototype;
1063+
WeakMap.prototype.set = function(v) {
1064+
return set.call(this, v, v);
1065+
};
1066+
Error.prepareStackTrace =
1067+
Error.prepareStackTrace =
1068+
(_, c) => c.map(c => c.getThis()).find(a => a);
1069+
const { stack } = new Error();
1070+
Error.prepareStackTrace = undefined;
1071+
stack.process
1072+
`));
10611073
});
10621074

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

0 commit comments

Comments
 (0)