Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Merge pull request #427 from XmiliaH/skip-transformer
Browse files Browse the repository at this point in the history
Skip transformer in trivial cases
  • Loading branch information
XmiliaH authored Jul 5, 2022
2 parents e3e573f + 4392f5a commit f1167de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function transformer(args, body, isAsync, isGenerator, filename) {
let argsOffset;
if (args === null) {
code = body;
// Note: Keywords are not allows to contain u escapes
if (!/\b(?:catch|import|async)\b/.test(code)) {
return {__proto__: null, code, hasAsync: false};
}
} else {
code = isAsync ? '(async function' : '(function';
if (isGenerator) code += '*';
Expand Down
12 changes: 6 additions & 6 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ describe('VM', () => {

it('internal state attack', () => {
const vm2 = new VM();
assert.throws(() => vm2.run(`${INTERNAL_STATE_NAME}=1;`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`const ${INTERNAL_STATE_NAME} = {};`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`var ${INTERNAL_STATE_NAME} = {};`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`let ${INTERNAL_STATE_NAME} = {};`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`class ${INTERNAL_STATE_NAME} {};`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`function ${INTERNAL_STATE_NAME} () {};`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`${INTERNAL_STATE_NAME}="async";`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`const ${INTERNAL_STATE_NAME} = "async";`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`var ${INTERNAL_STATE_NAME} = "async";`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`let ${INTERNAL_STATE_NAME} = "async";`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`class ${INTERNAL_STATE_NAME} {}; // async`), /Use of internal vm2 state variable/);
assert.throws(() => vm2.run(`function ${INTERNAL_STATE_NAME} () {}; // async`), /Use of internal vm2 state variable/);
});

it('buffer attack', () => {
Expand Down

0 comments on commit f1167de

Please # to comment.