nae-sandbox

Sandbox Environment for Node App Engine.

nae-sandbox

Sandbox Environment for Node App Engine.

  • Control fs module, only read app scope file resouces: nae-fs module
  • Disable child_process module
  • Configurable Control modules, e.g.: net, http
  • Configurable C/C++ Addons: options.enableAddons = ture / false
  • SafeModule._load(request, parent, isMain)
  • SafeModule._resolveFilename(request, parent): check current user app permissions

Only allows:

/app/*.(js|json)
/app/node_modules/*
  • SandBox manager create a sandbox child process: sp
  • sp use SandboxModule load app main file, so app run in the sandbox safe environment.

app code can not rewrite the sandbox codes.

  • Create root module in a sandbox: id: "."
  • root_module.load()
  • Module._extensions['.js'] => root_module._compile()
$ npm install nae-sandbox --registry=http://registry.cnpmjs.org --disturl=http://dist.u.qiniudn.com
var SandBox = require('nae-sandbox');
var naefs = require('nae-fs');
 
var appdir = path.join(path.dirname(__dirname), 'examples', 'helloworld');
var sb = new SandBox(appdir, {
  disableModules: ['child_process'],
  modules: {
    fs: naefs.create({
      pwd: appdir,
      limitRoot: appdir,
    }),
  }
});
sb.start();

@see examples/

$ git summary
 
 project  : nae-sandbox
 repo age : 6 days
 active   : 4 days
 commits  : 11
 files    : 31
 authors  :
    10  fengmk2                 90.9%
     1  dead_horse              9.1%

(The MIT License)

Copyright(c) nae team and other contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.