Giter Site home page Giter Site logo

Locking up the host about vm2 HOT 8 CLOSED

patriksimek avatar patriksimek commented on May 23, 2024
Locking up the host

from vm2.

Comments (8)

patriksimek avatar patriksimek commented on May 23, 2024

Unfortunately, this is how node's VM works and there is nothing I can change about that.

from vm2.

derhuerst avatar derhuerst commented on May 23, 2024

Hey! I wrote a module that makes really simple async code sync. I'm interested in expanding it to other stuff like Promises.

Let's join forces on this!

from vm2.

nanowizard avatar nanowizard commented on May 23, 2024

Would using Promise: null in the sandbox options guarantee that the script cannot add any callbacks to the event loop (assuming, of course, that no other async functionality was added to the sandbox scope)?

If not, is there another way to force the code to be only synchronous?

from vm2.

derhuerst avatar derhuerst commented on May 23, 2024

Btw i moved to lolex for all timer-related code (e.g. setTimeout). Rewriting async code like I linked above is still possible but tedious.

For Promises, they usually resolve on next tick, so it would be possible to mock them so that we can control this next tick.

from vm2.

jtokoph avatar jtokoph commented on May 23, 2024

Is there a way to disable promises in the VM?

Using sandbox: { Promise: null } causes issues with contextify.

VM = require('vm2').VM;
new VM({
  sandbox: {
    Promise: null,
  }
}).run('class Foo {}; new Foo();');
TypeError: Right-hand side of 'instanceof' is not an object
    at Object.value (/Users/jtokoph/tmp/node_modules/vm2/lib/contextify.js:232:22)
    at VM.run (/Users/jtokoph/tmp/node_modules/vm2/lib/main.js:207:39)

Using sandbox: { Promise: function() } causes the process to hang with this simple example:

VM = require('vm2').VM;
new VM({
  sandbox: {
    Promise: function() {},
  }
}).run('class Foo {}; new Foo();');

from vm2.

patriksimek avatar patriksimek commented on May 23, 2024

@jtokoph Please open a separate ticket for this.

from vm2.

jeandat avatar jeandat commented on May 23, 2024

Even if we can't prevent while(true) loops, setting a memory cap would help. An infinite loop will consume a lot of memory. By adding the possibility to set a threshold for a script, we could mitigate their impact.

Not being able to detect and/or block infinite loops is a BIG issue because the only thing you can do when that happens is to restart your server which is not really a solution.

Do you think that would be possible?

from vm2.

stale avatar stale commented on May 23, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from vm2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.