Giter Club home page Giter Club logo

Comments (6)

paulbartrum avatar paulbartrum commented on August 22, 2024

Clearly people are interested in this type of sandboxing functionality! I've added your wiki page. I'm not completely convinced that it's possible to robustly sandbox hostile code using threads -- I would advocate for using child processes and IPC instead. Stack overflow and out of memory exceptions are particularly hard to recover from. Sadly, creating child processes is inconvenient and not supported in all .NET environments (e.g. universal apps), so I get why people want to use threads.

from jurassic.

smoketh avatar smoketh commented on August 22, 2024

Well, for now i've switched from js to SPRAK language ( https://github.com/eriksvedang/Sprak ) , because its original interpreter has 100% controlled exectuion environment - instead of just running it you can call Start(), then Step() and do as many steps through the script as you want to before calling thread sleep. that helps immensely.

from jurassic.

kpreisser avatar kpreisser commented on August 22, 2024

@paulbartrum Great, thanks!
I see that the wiki is publicly editable, is it OK if I edit the page? E.g. make it clearer that the helper allows to run the Javascript on the same Thread instead of using a new one. I also saw that you merged the push request about limiting recursion depth, so I could add that to the page.

About sandboxing functionality, I agree that these two features are not enough (also the recursion limit might not save you if a script function generates a IL method that has lot of variables in the stack).
Another problem is (as you already said in one of the issues) that the script can still allocate arbirary amounts of memory, e.g. with

var s = 'a';
for (;;) s += s;

However, for example Firefox also runs scripts from untrusted sources in the same process where the GUI etc. runs. When Firefox runs a script with an infinite loop, the GUI will hang for some seconds, but then the user has the choice to abort the script (this similar to set a timeout as described in the wiki article). If the script runs an endless recursion, the script will receive a "too much recursion" InternalError, or if it allocates to much memory, it will receive an "allocation size overflow" InternalError (but the process continues to run in either case).

It probably is not easy to handle the case of too much allocated memory, as I assume Jurassic simply relies on the .NET GC to reclaim unreferenced JavaScript objects and e.g. uses native .Net Strings etc.
One thing that I have thought of is if the Script Engine counts each allocated entry for datatypes that can grow, e.g. a String (where for one String a new, longer String can be created) and ObjectInstances (where properties can be added), so that one could specify a maximum string length (cumulated string length of all strings that are returned or concatenated) or object key count (even without using WeakReferences to track if objects were collected by GC). However I guess that would have a huge impact on performance (so if anything, it would have to be enabled at compile time).

Thanks!

from jurassic.

kpreisser avatar kpreisser commented on August 22, 2024

Hi,
sorry to write again, but would it be OK if I edit the Wiki page (Safely executing user provided scripts)? I have updated the forked wiki page (added notes about limiting recursion depth and improved description for the helper class), and would like to update the Jurassic wiki page.
Thanks!

from jurassic.

paulbartrum avatar paulbartrum commented on August 22, 2024

I added you as a collaborator, but then I realised that anyone can edit the wiki, collaborator or no... ha. Go ahead and make the change.

from jurassic.

kpreisser avatar kpreisser commented on August 22, 2024

Cool, thank you! I have update the wiki page. (AFAIK, by default a wiki on Github is publicly editable, but this can be changed in the repo settings).

For reference, the Wiki page URL is: https://github.com/paulbartrum/jurassic/wiki/Safely-executing-user-provided-scripts

from jurassic.

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.