Comments (6)
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.
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.
@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.
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.
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.
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)
- How to catch CLR Exception? HOT 7
- System.ArgumentNullException: Value cannot be null. (Parameter 'value') after update from 3.1.0 to 3.2.2 HOT 3
- JSONObject.Parse() fails when number is in scientific notation HOT 4
- ScriptEngine.EnableDebugging HOT 3
- Template of literals is slow
- JSON.stringify([].length) errors HOT 2
- JSONObject.Parse consumes more and more memory. Possible memory leak? HOT 11
- Scoping and CompiledScript.Execute vs ScriptEngine.Evaluate HOT 5
- Catching script errors at compile time HOT 2
- Currently JSONObject.Stringify returns object instead of string after upgrading from 3.1.0 to 3.2.6 HOT 3
- ScriptEngine.GetGlobalValue HOT 1
- Bug in Evaluate: Loop and variable handling HOT 2
- PM - Customer side scripting for Channels HOT 1
- Date.UTC() doesn't interpret two-digit years correctly HOT 1
- Possibility to create 'sessions' HOT 4
- Linux compability ? HOT 4
- Is it possible to go from JS to DLL and then to C# source? HOT 2
- Automatic conversion from C# to Jurassic JavaScript HOT 2
- How to run and use the Cheerio library or jsdom HOT 1
- Global variables overwritten from function call HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jurassic.