Creating a customized sandbox in node.js (Can only read in a certain directory, and cannot write anywhere)

StackOverflow https://stackoverflow.com/questions/22558329

  •  18-06-2023
  •  | 
  •  

Question

I am trying to make an application that runs submitted scripts, and would like to try to sandbox the submitted scripts. The scripts need to be able to be able to read in a certain directory (and in all of its subdirectories), but shouldn't be able to write at all, and, other than being able to read, should not be able to do anything that could not be done in a browser (ie download files using http). How would I go about doing this?

Was it helpful?

Solution 2

Eventually, I decided on using the vm node module. I basically just made a namespace that the script running in the sandbox could use that would filter out malicious requests / requests that ought to be out of the bounds of the sandbox. The namebox included fs methods that would be necessary, but failed to execute any of the ones that would modify any directory other than the certain one that I wished the script to be able to modify.

OTHER TIPS

I don't think Node has this capability built in, but you should be able to run an "unsandboxed" Node on a *nix operating system as a severely restricted user (might be possible in other OSes too, I'm not sure). You might also want to look at Node's VM module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top