-
Notifications
You must be signed in to change notification settings - Fork 298
is this secure or not? #325
Comments
It is secure isolated-vm gives you access to V8 isolates, which run on another thread. That means infinite loops won't ever block your event loop. IVM also supports memory limits You can use const {VM} = require('vm2');
const axios = require('axios').default;
const vm = new VM({
sandbox: {
axios
}
});
(async () => {
const res = await vm.run(`
axios.get('http://httpbin.org/get')
.then(x => x.data)
.then(x => x.url);
`);
console.log(res); // => http://httpbin.org/get
})(); |
Hi @y21 thank you very much for your answer and explanation.
I have an async function in my host, and I await the promise which is generated inside the sandbox. Is that fine? Something like this:
Pretty much I'm saving a promise in Is this Ok? Thanks again! |
Just keep in mind that NodeVM is not immune to infinite loops, so
I think the safest way to do this is to run vm2 in a separate process or to use worker threads. That way your main thread will never hang if someone tries to run |
Great thank you very much |
In the wiki I read:
Yet in the readme I read:
So which one is it? Can I run untrusted code and be sure that my env.variables are safe? I need only to run plain JS and
tiny-json-http
oraxios
to make API requests, nothing else.Thank you for the clarifications
The text was updated successfully, but these errors were encountered: