Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advantages over the native VM module #59

Closed
odino opened this issue Mar 2, 2017 · 4 comments
Closed

Advantages over the native VM module #59

odino opened this issue Mar 2, 2017 · 4 comments

Comments

@odino
Copy link

odino commented Mar 2, 2017

Hello there :)

Just wanted to know if there are clear advantages using vm2 over node's native VM module -- tried to look for it in the readme but couldnt find anything. I'm using vm on node 7 and was wondering if I should potentially look at vm2 if it fixes / handles specific use-cases.

Cheers!

@patriksimek
Copy link
Owner

The vm2 library doesn't fix anything, it uses internal VM as is. The reason to use vm2 is to execute a code and prevent it to access things outside the VM context.

@odino
Copy link
Author

odino commented Mar 2, 2017 via email

@patriksimek
Copy link
Owner

patriksimek commented Mar 2, 2017

You can try it yourself:

const vm = require('vm');
vm.runInNewContext('this.constructor.constructor("return process")().exit()');
console.log('Never gets executed.');

vs

const {VM} = require('vm2');
new VM().run('this.constructor.constructor("return process")().exit()');

@odino
Copy link
Author

odino commented Mar 3, 2017

Ouch :( that's nasty!

Thanks for updating the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants