Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: patriksimek/vm2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: activeledger/vm2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 8 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 20, 2023

  1. Copy the full SHA
    55e0d8b View commit details
  2. Release 3.9.20

    AdmWalker committed Sep 20, 2023
    Copy the full SHA
    99f1277 View commit details

Commits on Sep 21, 2023

  1. fix: Expand Sandbox Symbol

    AdmWalker committed Sep 21, 2023
    Copy the full SHA
    45511fd View commit details
  2. Release 3.9.21

    AdmWalker committed Sep 21, 2023
    Copy the full SHA
    88a92b9 View commit details

Commits on Oct 6, 2023

  1. Copy the full SHA
    225f441 View commit details
  2. Release 2.9.33

    AdmWalker committed Oct 6, 2023
    Copy the full SHA
    87023fe View commit details
  3. Copy the full SHA
    133d61e View commit details
  4. Copy the full SHA
    712ce5e View commit details
Showing with 186 additions and 75 deletions.
  1. +18 −0 CHANGELOG.md
  2. +67 −2 lib/vm.js
  3. +2 −2 package-lock.json
  4. +4 −4 package.json
  5. +95 −67 test/vm.js
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
v3.9.24 (2023-10-06)
--------------------
[fix] Fix Introduced Object Escapes escapes (see https://github.com/patriksimek/vm2/issues/533#issuecomment-1750328055)

v3.9.22 (2023-10-06)
--------------------
[fix] Additional Symbol / Proxy escapes (see https://github.com/patriksimek/vm2/issues/533#issuecomment-1748934984)

v3.9.21 (2023-09-21)
--------------------
[fix] Expand Sandbox Symbols

v3.9.20 (2023-09-20)
--------------------
[fix] Symbol Security fix #1 (see https://github.com/patriksimek/vm2/security/advisories/GHSA-g644-9gfx-q4q4).

[fix] Symbol Security fix #2 (see https://github.com/patriksimek/vm2/security/advisories/GHSA-cchq-frgv-rjh5).

(discontinued) (2023-07-09)
---------------------------
Discontinued do to security issues without proper fixes.
69 changes: 67 additions & 2 deletions lib/vm.js
Original file line number Diff line number Diff line change
@@ -142,6 +142,71 @@ function doWithTimeout(fn, timeout) {
}
}

/**
* Protects from Symbol based exploits by a sandbox proxy
*
* Follows the discussion of multiple forks attempting to resolve this exploit
* https://github.com/patriksimek/vm2/issues/533
*
* This solution is not for general consumption, It disables features you may require.
*
* @private
* @param {Object} sandbox - Objects that will be copied into the global object of the sandbox.
* @return {Object} Protected Symbol added to the sandbox.
*/
function hardenSandbox(sandbox) {
const customSymbol = 'nodejs.util.inspect.custom';
inspect.defaultOptions.customInspect = false;

sandbox.Symbol = () => {
return () => Symbol;
};
sandbox.Symbol.asyncIterator = Symbol.asyncIterator;
sandbox.Symbol.hasInstance = Symbol.hasInstance;
sandbox.Symbol.isConcatSpreadable = Symbol.isConcatSpreadable;
sandbox.Symbol.iterator = Symbol.iterator;
sandbox.Symbol.keyFor = Symbol.keyFor;
sandbox.Symbol.match = Symbol.match;
sandbox.Symbol.matchAll = Symbol.matchAll;
sandbox.Symbol.prototype = Symbol.prototype;
sandbox.Symbol.replace = Symbol.replace;
sandbox.Symbol.search = Symbol.search;
sandbox.Symbol.split = Symbol.split;
sandbox.Symbol.toString = Symbol.toString;
sandbox.Symbol.toPrimitive = Symbol.toPrimitive;
sandbox.Symbol.toStringTag = Symbol.toStringTag;
sandbox.Symbol.unscopables = Symbol.unscopables;

// Block Species access attacks
sandbox.Symbol.species = null;

// Block fetching custom attacks
sandbox.Symbol.for = (type) => {
if (type.toString() !== customSymbol) {
return Symbol.for(type);
}
return {};
};

// Prevent fetching Symbols
const cachedGetOwnPropertySymbols = Object.getOwnPropertySymbols;
Object.getOwnPropertySymbols = (obj) => {
const result = cachedGetOwnPropertySymbols(obj);
for (let i = result.length; i--; ) {
if (result[i].toString() === `Symbol(${customSymbol})`) {
return {};
}
}
return result;
};

sandbox.Proxy = function disableProxy() {
throw Error('Proxy Not Supported');
};

return sandbox;
}

const bridgeScript = compileScript(`${__dirname}/bridge.js`,
`(function(global) {"use strict"; const exports = {};${fs.readFileSync(`${__dirname}/bridge.js`, 'utf8')}\nreturn exports;})`);
const setupSandboxScript = compileScript(`${__dirname}/setup-sandbox.js`,
@@ -227,7 +292,7 @@ class VM extends EventEmitter {
// Read all options
const {
timeout,
sandbox,
sandbox = {},
compiler = 'javascript',
allowAsync: optAllowAsync = true
} = options;
@@ -372,7 +437,7 @@ class VM extends EventEmitter {

// prepare global sandbox
if (sandbox) {
this.setGlobals(sandbox);
this.setGlobals(hardenSandbox(sandbox));
}
}

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"name": "Patrik Simek",
"url": "https://patriksimek.cz"
},
"name": "vm2",
"name": "@activeledger/vm2",
"description": "vm2 is a sandbox that can run untrusted code with whitelisted Node's built-in modules. Securely!",
"keywords": [
"sandbox",
@@ -13,10 +13,10 @@
"alcatraz",
"contextify"
],
"version": "3.9.19",
"version": "3.9.24",
"main": "index.js",
"sideEffects": false,
"repository": "github:patriksimek/vm2",
"repository": "github:activeledger/vm2",
"license": "MIT",
"dependencies": {
"acorn": "^8.7.0",
@@ -38,4 +38,4 @@
"vm2": "./bin/vm2"
},
"types": "index.d.ts"
}
}
Loading