Created
February 3, 2011 07:38
-
-
Save FND/809174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
securely running untrusted code in Node.js | |
Usage: | |
$ node sandbox.js | |
based on LintServer by Jakob Kruse: | |
https://github.com/jkruse/LintServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var vm; | |
try { | |
vm = require("vm"); | |
} catch(exc) { // Node.js v0.2 | |
vm = process.binding("evals").Script; | |
} | |
var filename = "untrusted.js"; | |
var source = fs.readFileSync("./" + filename, "utf8"); | |
var sandbox = {}; | |
vm.runInNewContext(source, sandbox, filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var text = fs.readFileSync("./dispatch.js", "utf8"); | |
console.log(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment