
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
This began as a wan attempt to reproduce/polyfill/infill the Node.JS
vm#runIn<Some?>Context() methods in browsers. It has transformed
into the present tan muscular self-assured and smiling project before you.
I'd wanted to show that shimming vm in the browser really could be done
directly, partly to avoid iframes (which
vm-browserify uses) to create and
clone globals and contexts, and partly to side-step Node.js's
contra-normative implementations of runInContext methods.
It's actually a "why didn't I think of that?" solution to problems such as -
vm methods accept functions as arguments, not just strings?eval() and Function() accept functions as arguments?eval() and Function() leak un-var'd symbols to the global scope, in
browser & node.js environments?vm#runInContext(code, context)vm#runInNewContext(code, context)vm#runInThisContext(code)vm#.createContextvm#.createScriptscript.runInThisContext()script.runInNewContext([sandbox])npm install vm-shim
git clone https://github.com/dfkaye/vm-shim.git
Starting with vm.runInContext(code, context), the Function() constructor is
at the core. The code param may be either a string or a function. The
context param is a simple object with key-value mappings. For any key on the
context, a new var for that key is prefixed to the code. The code is passed
in to Function() so that the keynames can't leak outside the new function's
scope.
Refactored [8 Nov 2013]: a lot of little things involved - biggest is that
runInThisContext now uses eval() internally, and the other two use with()
inside of Function(). Who says you can't use with()?
[10 Nov] Having discovered that eval() leaks globals (!?!) if symbols are not
var'd, all methods rely on a helper method to scrape EVERY global added by its
internal eval() (or Function()) call.
[10 Dec]: removed use of with.
The unit tests demonstrate how runInContext and runInNewContext methods work
by passing a context param containing a reference to the test's expectation
object or function.
Example runInContext test passes the expect function via context argument:
it("overrides external scope vars with context attrs", function() {
var attr = "shouldn't see this";
var context = {
attr: 'ok',
expect: expect // <-- pass expect here
};
vm.runInContext(function(){
expect(attr).toBe('ok');
expect(attr).not.toBe('should not see this');
}, context);
});
Example runInNewContext test to verify context is returned:
it('should return context object', function () {
var context = { name: 'test' };
var result = vm.runInNewContext('', context);
expect(result).toBe(context);
expect(result.name).toBe('test');
});
Example runInThisContext test to verify accidental is not placed on global scope:
it("should not leak accidental (un-var'd) globals", function() {
vm.runInThisContext(function(){
accidental = 'defined';
});
expect(global.accidental).not.toBeDefined();
});
Using Misko Hevery's jasmine-node to run command line tests on node (even though this project initially aimed at a browser shim).
The package.json file defines three test script commands to run the tests via
jasmine-node without the browsers:
npm test
# => jasmine-node --verbose ./test/suite.spec.js
npm run test-vm
# => jasmine-node --verbose ./test/vm-shim.spec.js
Using @pivotallabs' jasmine-2.0.0 for the browser suite.
The jasmine2 browser test page is viewable on rawgit.
Using Toby Ho's MAGNIFICENT testemjs to
drive tests in multiple browsers for jasmine-2.0.0 (see how to
hack testem for jasmine 2), as well
as jasmine-node. The testem.json file uses the standalone test page above,
and also uses a custom launcher for jasmine-node (v 1.3.1).
View both test types at the console by running:
testem -l j
Just noting for the record:
FAQs
VM module for the browser
The npm package browser-vm receives a total of 2 weekly downloads. As such, browser-vm popularity was classified as not popular.
We found that browser-vm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.