diff --git a/lib/setup-sandbox.js b/lib/setup-sandbox.js index 2c80dbc..f6cbb8e 100644 --- a/lib/setup-sandbox.js +++ b/lib/setup-sandbox.js @@ -67,7 +67,8 @@ Object.defineProperties(global, { global: {value: global, writable: true, configurable: true, enumerable: true}, globalThis: {value: global, writable: true, configurable: true}, GLOBAL: {value: global, writable: true, configurable: true}, - root: {value: global, writable: true, configurable: true} + root: {value: global, writable: true, configurable: true}, + Error: {value: LocalError} }); if (!localReflectDefineProperty(global, 'VMError', { diff --git a/test/vm.js b/test/vm.js index b72265d..d4f6a9f 100644 --- a/test/vm.js +++ b/test/vm.js @@ -1070,6 +1070,13 @@ describe('VM', () => { Error.prepareStackTrace = undefined; stack.process `)); + assert.throws(()=>vm2.run(`(()=>{ + const OldError = Error; + global.Error = {prepareStackTrace: (_, c) => c.map(c => c.getThis()).find(a => a && a.process)}; + const { stack } = new OldError(); + global.Error = OldError; + return stack.process.mainModule; + })()`)); }); it('Node internal prepareStackTrace attack', () => {