Skip to content

Commit b6581b4

Browse files
committed
Prepare release 3.9.7
1 parent 568934f commit b6581b4

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v3.9.7 (2022-02-10)
2+
-------------------
3+
[fix] Allow relative require from base script
4+
[fix] Fix issue with modules with exports clause in package json
5+
[fix] Added missing whitelist check before custom require
6+
[fix] Revert plain object toString behavior
7+
[fix] Root path check improved
8+
19
v3.9.6 (2022-02-08)
210
-------------------
311
[fix] Security fixes (XmiliaH)

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ vm2 ./script.js
377377
## Known Issues
378378

379379
* It is not possible to define a class that extends a proxied class.
380+
* Direct eval does not work.
381+
* Logging sandbox arrays will repeat the array part in the properties.
382+
* Source code transformations can result a different source string for a function.
380383

381384
## Deployment
382385

lib/resolver-compat.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ function resolverFromOptions(vm, options, override, compiler) {
293293
if (rootPaths) {
294294
const checkedRootPaths = (Array.isArray(rootPaths) ? rootPaths : [rootPaths]).map(f => pa.resolve(f));
295295
checkPath = (filename) => {
296-
return checkedRootPaths.some(path => filename.startsWith(path));
296+
return checkedRootPaths.some(path => {
297+
if (!filename.startsWith(path)) return false;
298+
const len = path.length;
299+
if (filename.length === len) return true;
300+
const sep = filename[len];
301+
return sep === '/' || sep === pa.sep;
302+
});
297303
};
298304
} else {
299305
checkPath = () => true;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"alcatraz",
1414
"contextify"
1515
],
16-
"version": "3.9.6",
16+
"version": "3.9.7",
1717
"main": "index.js",
1818
"sideEffects": false,
1919
"repository": "github:patriksimek/vm2",

test/nodevm.js

+22
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,28 @@ describe('modules', () => {
298298
assert.throws(() => vm.run("require('mocha')", __filename), /Cannot find module 'mocha'/);
299299
});
300300

301+
it('root path checking', () => {
302+
const vm = new NodeVM({
303+
require: {
304+
external: true,
305+
root: `${__dirname}/node_modules/module`
306+
},
307+
});
308+
309+
assert.throws(() => vm.run("require('module2')", __filename), /Cannot find module 'module2'/);
310+
});
311+
312+
it('relative require not allowed to enter node modules', () => {
313+
const vm = new NodeVM({
314+
require: {
315+
external: ['mocha'],
316+
root: `${__dirname}`
317+
},
318+
});
319+
320+
assert.throws(() => vm.run("require('./node_modules/module2')", __filename), /Cannot find module '\.\/node_modules\/module2'/);
321+
});
322+
301323
it('arguments attack', () => {
302324
let vm = new NodeVM;
303325

0 commit comments

Comments
 (0)