I need to run code supplied by an unknown source which validates or sorts something.
How can I do this safely in Node.js?
Python has RestrictedPython, anything similar?
There is also ADsafe for the browser, but is it usable in Node.js?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Node has an excellent tool for this, the node.vm. Basically you can run a script in its own context, effectively sandboxing it.
Of course, since Node runs on a single thread, a harmful script can always shut down your server just by doing:
To be completely safe, you need to spawn a new process and use message passing for communication.