Skip to content

Commit

Permalink
Also test node v6 and v8 and make v16 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
XmiliaH committed Oct 17, 2021
1 parent ab245fe commit 106657c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [10, 12, 14, 16]
node-version: [6, 8, 10, 12, 14, 16]

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions test/nodevm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('NodeVM', () => {

it('arguments attack', () => {
assert.strictEqual(vm.run('module.exports = (function() { return arguments.callee.caller.constructor === Function; })()'), true);
assert.throws(() => vm.run('module.exports = (function() { return arguments.callee.caller.caller.toString(); })()'), /Cannot read property 'toString' of null/);
assert.throws(() => vm.run('module.exports = (function() { return arguments.callee.caller.caller.toString(); })()'), /Cannot read propert.*toString/);
});

it('global attack', () => {
Expand Down Expand Up @@ -274,11 +274,11 @@ describe('modules', () => {
it('arguments attack', () => {
let vm = new NodeVM;

assert.throws(() => vm.run('module.exports = function fce(msg) { return arguments.callee.caller.toString(); }')(), /Cannot read property 'toString' of null/);
assert.throws(() => vm.run('module.exports = function fce(msg) { return arguments.callee.caller.toString(); }')(), /Cannot read propert.*toString/);

vm = new NodeVM;

assert.throws(() => vm.run('module.exports = function fce(msg) { return fce.caller.toString(); }')(), /Cannot read property 'toString' of null/);
assert.throws(() => vm.run('module.exports = function fce(msg) { return fce.caller.toString(); }')(), /Cannot read propert.*toString/);
});

it('builtin module arguments attack', done => {
Expand Down Expand Up @@ -386,7 +386,7 @@ describe('modules', () => {
assert.strictEqual(vm.run(`try {
process.listeners({toString(){return {};}});
module.exports = true;
} catch(e) {
} catch(e) {
module.exports = e.constructor.constructor === Function;
}`), true);

Expand Down
14 changes: 7 additions & 7 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('VM', () => {
assert.throws(() => vm.run('function test(){ return await Promise.resolve(); };'), err => {
assert.ok(err instanceof Error);
assert.equal(err.name, 'SyntaxError');
assert.equal(err.message, 'await is only valid in async function');
assert.match(err.message, /await is only valid in async function/);
return true;
});
}
Expand Down Expand Up @@ -681,15 +681,15 @@ describe('VM', () => {
value: new Proxy({}, {
getPrototypeOf(target) {
delete this.getPrototypeOf;
Object.defineProperty(Object.prototype, "get", {
get() {
delete Object.prototype.get;
Function.prototype.__proto__ = null;
throw f=>f.constructor("return process")();
}
});
return Object.getPrototypeOf(target);
}
})
Expand All @@ -698,7 +698,7 @@ describe('VM', () => {
process = e(() => {});
}
process.mainModule.require("child_process").execSync("whoami").toString()
`), /Cannot read property 'mainModule' of undefined/, '#3');
`), /Cannot read propert.*mainModule/, '#3');

vm2 = new VM();

Expand Down Expand Up @@ -795,7 +795,7 @@ describe('VM', () => {
}
"" in Buffer.from;
process.mainModule;
`), /Cannot read property 'mainModule' of undefined/, '#1');
`), /Cannot read propert.*mainModule/, '#1');

const vm22 = new VM();

Expand All @@ -818,7 +818,7 @@ describe('VM', () => {
var process = Buffer.from.process;
Object.create = oc;
process.mainModule
`), /Cannot read property 'mainModule' of undefined/, '#1');
`), /Cannot read propert.*mainModule/, '#1');
});

it('function returned from construct attack', () => {
Expand Down Expand Up @@ -924,7 +924,7 @@ describe('VM', () => {
const vm2 = new 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 property 'constructor' of undefined/);
assert.throws(()=>vm2.run('sst=>sst[0].getThis().constructor.constructor')(sst), /TypeError: Cannot read propert.*constructor/);
});

after(() => {
Expand Down

0 comments on commit 106657c

Please sign in to comment.