Repository: bcoe/sandcastle
Branch: master
Commit: c398815c04cf
Files: 26
Total size: 44.5 KB
Directory structure:
gitextract_oqlrruqn/
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── bin/
│ └── sandcastle.js
├── examples/
│ ├── api-example.js
│ ├── api.js
│ ├── benchmark.js
│ ├── contextObjectApi.js
│ ├── error.js
│ ├── example.txt
│ ├── hello.js
│ ├── multiple-functions.js
│ ├── pool.js
│ └── timeout.js
├── lib/
│ ├── index.js
│ ├── pool.js
│ ├── sandbox.js
│ ├── sandcastle.js
│ └── script.js
├── package.json
└── test/
├── exploits-test.js
├── fixtures/
│ ├── exploit-callee.txt
│ └── exploit-getter.txt
├── pool-test.js
└── sandcastle-test.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
node_modules
.DS_store
test.sh
test.js
nohup.out
out.txt
/coverage.html
================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
- "0.10"
- "0.12"
- "iojs"
================================================
FILE: LICENSE.txt
================================================
Copyright (c) 2012 Benjamin Coe
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.
================================================
FILE: README.md
================================================
SandCastle
==========
[](https://travis-ci.org/bcoe/sandcastle)
A simple and powerful sandbox for running untrusted JavaScript.
The Impetus
-----------
For a project I'm working on, I needed the ability to run untrusted JavaScript code.
I had a couple specific requirements:
* I wanted the ability to whitelist an API for inclusion within the sandbox.
* I wanted to be able to run multiple untrusted scripts in the same sandboxed subprocess.
* I wanted good error reporting and stack-traces, when a sandboxed script failed.
I could not find a library that met all these requirements, enter SandCastle.
What Makes SandCastle Different?
---------------------
* It allows you to queue up multiple scripts for execution within a single sandbox.
* This better suits Node's evented architecture.
* It provides reasonable stack traces when the execution of a sandboxed script fails.
* It allows an API to be provided to the sandboxed script being executed.
* It provides all this in a simple, well-tested, API.
Installation
------------
```bash
npm install sandcastle
```
Creating and Executing a Script
----------------------
```javascript
var SandCastle = require('sandcastle').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
exit('Hey ' + name + ' Hello World!');\
}\
");
script.on('exit', function(err, output) {
console.log(output); // Hello World!
});
script.run({name: 'Ben'});// we can pass variables into run.
```
__Outputs__
```bash
Hey Ben Hello World!
```
* __exit(output):__ from within untrusted code, causes a sandboxed script to return.
* Any JSON serializable data passed into __exit()__ will be passed to the output parameter of an __exit__ event.
* __on('exit'):__ this event is called when an untrusted script finishes execution.
* __run()__ starts the execution of an untrusted script.
SandCastle Options
----------------------
The following options may be passed to the SandCastle constructor:
* `timeout` — number of milliseconds to allow script to run (defaults to 5000 ms)
* `memoryLimitMB` — maximum amount of memory that a script may consume (defaults to 0)
* `useStrictMode` — boolean; when true script runs in strict mode (defaults to false)
* `api` — path to file that defines the API accessible to script
* `cwd` — path to the current working directory that the script will be run in (defaults to `process.cwd()`)
* `spawnExecPath` — path to a external node binary to run the sandbox with. (defaults to `process.execPath`) _This is a [temporary workaround](https://github.com/rogerwang/node-webkit/issues/213) which allows you to run the sandbox within [node-webkit](https://github.com/rogerwang/node-webkit)_
* `refreshTimeoutOnTask` — boolean; refreshes the timeout whenever an answer to a task will be sent to the script
Executing Scripts on Pool of SandCastles
----------------------
A pool consists of several SandCastle child-processes, which will handle the script execution. Pool-object is a drop-in replacement of single Sandcastle instance. Only difference is, when creating the Pool-instance.
You can specify the amount of child-processes with parameter named numberOfInstances (default = 1).
```javascript
var Pool = require('sandcastle').Pool;
var poolOfSandcastles = new Pool( { numberOfInstances: 3 }, { timeout: 6000 } );
var script = poolOfSandcastles.createScript("\
exports.main = function() {\
exit('Hello World!');\
}\
");
script.on('exit', function(err, output) {
console.log(output);
});
script.run();
```
Handling Timeouts
-----------------------
If a script takes too long to execute, a timeout event will be fired:
```javascript
var SandCastle = require('sandcastle').SandCastle;
var sandcastle = new SandCastle({ timeout: 6000 });
var script = sandcastle.createScript("\
exports.main = function() {\
while(true) {};\
}\
");
script.on('exit', function(err, output) {
console.log('this will never happen.');
});
script.on('timeout', function() {
console.log('I timed out, oh what a silly script I am!');
});
script.run();
```
__Outputs__
```bash
I timed out, oh what a silly script I am!
```
Handling Errors
-----------------------
If an exception occurs while executing a script, it will be returned as the first parameter in an __on(exit)__ event.
```bash
var SandCastle = require('sandcastle').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\n\
require('fs');\n\
}\
");
script.on('exit', function(err, output) {
console.log(err.message);
console.log(err.stack);
});
script.run();
```
__Outputs__
```bash
require is not defined
ReferenceError: require is not defined
at Object.main ([object Context]:2:5)
at [object Context]:4:9
at Sandbox.executeScript (/Users/bcoe/hacking/open-source/sandcastle/lib/sandbox.js:58:8)
at Socket.<anonymous> (/Users/bcoe/hacking/open-source/sandcastle/lib/sandbox.js:16:13)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:678:14)
at IOWatcher.onReadable [as callback] (net.js:177:10)
```
Providing an API
------------------------
When creating an instance of SandCastle, you can provide an API. Functions within this API will be available inside of the untrustred scripts being executed.
__An Example of an API:__
```javascript
var fs = require('fs');
exports.api = {
getFact: function(callback) {
fs.readFile('./examples/example.txt', function (err, data) {
if (err) throw err;
callback(data.toString());
});
},
setTimeout: function(callback, timeout) {
setTimeout(callback, timeout);
}
}
```
__A Script Using the API:__
```javascript
var SandCastle = require('sandcastle').SandCastle;
var sandcastle = new SandCastle({
api: './examples/api.js'
});
var script = sandcastle.createScript("\
exports.main = function() {\
getFact(function(fact) {\
exit(fact);\
});\
}\
");
script.on('exit', function(err, result) {
equal(result, 'The rain in spain falls mostly on the plain.', prefix);
sandcastle.kill();
finished();
});
script.run();
```
Exporting Multiple Functions
------------------------
Rather than main, you create a script file that exports multiple methods.
_Notice that one extra parameter `methodName` is available within the callback functions._
```javascript
var SandCastle = require('sandcastle').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports = {\
foo: function() {\
exit('Hello Foo!');\
},\
bar: function() {\
exit('Hello Bar!');\
},\
hello: function() {\
exit('Hey ' + name + ' Hello World!');\
}\
}\
");
script.on('timeout', function(methodName) {
console.log(methodName);
});
script.on('exit', function(err, output, methodName) {
console.log(methodName); // foo, bar, hello
});
// take note that a single script should only be
// executing a single method at a time.
var cb = null;
async.eachLimit(['foo', 'bar', 'hello'], 1, function(item, _cb) {
cb = _cb;
script.run(item, {name: 'Ben'});
});
```
Providing Tasks
------------------------
In contrast to the [API](#providing-an-api) which runs trusted code __inside__ the sandbox, the script can request that a task (a snippet of code) is executed in another process.
To run a task call `runTask(taskName, options = {})` and provide a `onTask(taskName, data)` method within the script file. Alternatively you can create a task specific function `on{TaskName}Task`, to receive data for an individual task.
```javascript
var script = sandcastle.createScript("\
exports = {\
onGetContentTask: function (data) {\
// received content. do something here...
},\
main: function() {\
runTask('getContent', {url: 'http://foo.bar'});\
}\
}\
");
script.on('task', function (err, taskName, options, methodName, callback) {
if (whitelistedUrls.indexOf(options.url) !== -1) {
http.get(options.url, function(res) {
callback(res);
}).on('error', function(e) {
callback(null);
});
}
});
```
`refreshTimeoutOnTask` can be used to control the timeout behavior of the script executing the task. If set to true, the script will have its timeout reset when the task is completed.
Debugging
---------
Make debugging a little easier by ensuring the DEBUG environment variable includes `sandcastle`.
Contributing
---------
SandCastle will be an ongoing project, please be liberal with your feedback, criticism, and contributions.
* send pull requests, for creative exploits that you find find for the SandBox. Sandboxing JavaScript is hard, it's unlikely that this library will ever be 100% bullet-proof.
* write unit tests for your contributions!
Copyright
---------
Copyright (c) 2012 Benjamin Coe. See LICENSE.txt for further details.
================================================
FILE: bin/sandcastle.js
================================================
#!/usr/bin/env node
var sandcastle = require('../lib'),
argv = require('optimist').argv,
mode = argv._.shift();
switch (mode) {
case 'sandbox':
(new sandcastle.Sandbox({
socket: (argv.socket || '/tmp/sandcastle.sock')
})).start();
break;
default:
console.log('Usage sandcastle <command>\n\n\
\t<sandbox>\tstart a sandbox server\n\
\t\t--socket=[path to socket file]\n\
')
}
================================================
FILE: examples/api-example.js
================================================
// example of using an external API. In this case
// we pul lin lodash's extend.
var SandCastle = require('../lib').SandCastle;
var sandcastle = new SandCastle({
api: './examples/api.js', // We provide an API with the setTimeout function.,
});
var script = sandcastle.createScript("\
exports.main = function() {\
var o1 = {a: 2};\
var o2 = {b: 3};\
extend(o1, o2);\
exit(JSON.stringify(o1));\
}\
");
script.on('exit', function(err, output) {
console.log(output); // Hello World!
process.exit(0);
});
script.run();
================================================
FILE: examples/api.js
================================================
var fs = require('fs');
var lodash = require('lodash')
exports.api = {
extend: function () {
lodash.extend.apply(this, arguments)
},
getFact: function(callback) {
fs.readFile('./examples/example.txt', function (err, data) {
if (err) throw err;
callback(data.toString());
});
},
setTimeout: function(callback, timeout) {
setTimeout(callback, timeout);
},
callAdditional: function(callback) {
anotherFunction(callback)
},
cwd: function() {
return process.cwd();
}
}
================================================
FILE: examples/benchmark.js
================================================
var SandCastle = require('../lib').SandCastle,
equal = require('assert').equal;
var sandcastle = new SandCastle({
api: './examples/api.js', // We provide an API with the setTimeout function.,
timeout: 2000
});
(function execute(n) {
if (!n) {
process.exit(0);
return;
}
// Keep track of execution stats.
var stats = {
script1: 0,
script2: 0,
script3: 0
};
// A non-malicious script with a timeout.
var script1 = sandcastle.createScript("\
exports.main = function() {\
setTimeout(function() {\
exit('script1')\
}, 10)\
}\
");
script1.on('exit', function(err, output) {
stats[output] += 1;
});
script1.on('timeout', function() {
// reschedule script1 when it times out.
script1.run();
});
// a malicious script that loops infinitely.
var script2 = sandcastle.createScript("\
exports.main = function() {\
while('script2') {};\
}\
");
script2.on('exit', function(err, output) {
stats[output] += 1;
});
// A non-malicious script with a timeout.
var script3 = sandcastle.createScript("\
exports.main = function() {\
setTimeout(function() {\
exit('script3')\
}, 1000)\
}\
");
script3.on('exit', function(err, output) {
stats[output] += 1;
});
script3.on('timeout', function() {
// reschedule script3 when it times out.
script3.removeAllListeners('exit');
script3.on('exit', function(err, output) {
stats.script3 += 1;
// Make sure the scripts were
// executed the appropriate # of times.
equal(stats.script1, 2);
equal(stats.script2, 0);
equal(stats.script3, 2);
console.log('scripts executed the correct # of times', stats)
setTimeout(function() {
execute(n - 1);
}, 0);
});
script3.run();
});
// Running script 1 and 3 will take.
// about 2 seconds to complete.
script1.run();
script3.run();
var id = setInterval(function() {
if (script1.exited && script3.exited) {
clearInterval(id);
// both script1 and script 2 exited after their first execution.
// next we will schedule them with a malicious script.
script3.run();
script1.run();
// script2 is malicious and will cause the sandbox to shutdown
// script1 and script3's timeout methods however cause them to be
// rescheduled.
script2.run();
}
}, 1000);
})(1000);
================================================
FILE: examples/contextObjectApi.js
================================================
var StateManager = function(){
var state = contextObject.state;
delete contextObject.state;
this.getState=function(){
return state;
};
};
exports.api = {
stateManager: new StateManager()
};
================================================
FILE: examples/error.js
================================================
var SandCastle = require('../').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\n\
require('fs');\n\
}\
");
script.on('exit', function(err, output) {
console.log(err.message);
console.log(err.stack);
});
script.run();
================================================
FILE: examples/example.txt
================================================
The rain in spain falls mostly on the plain.
================================================
FILE: examples/hello.js
================================================
var SandCastle = require('../lib').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
exit('Hello World!');\
}\
");
script.on('exit', function(err, output) {
console.log(output); // Hello World!
process.exit(0);
});
script.run();
================================================
FILE: examples/multiple-functions.js
================================================
var async = require('async'),
SandCastle = require('../lib').SandCastle,
sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports = {\
foo: function() {\
exit('Hello Foo!');\
},\
bar: function() {\
exit('Hello Bar!');\
},\
hello: function() {\
exit('Hey ' + name + ' Hello World!');\
}\
}\
");
script.on('timeout', function(methodName) {
console.log(methodName);
});
script.on('exit', function(err, output, methodName) {
console.log(methodName, output); // foo, bar, hello
return cb();
});
var cb = null;
async.eachLimit(['foo', 'bar', 'hello'], 1, function(item, _cb) {
cb = _cb;
script.run(item, {name: 'Ben'});
});
================================================
FILE: examples/pool.js
================================================
var Pool = require('../lib').Pool;
// You can give options for SandCastle instances with second parameter.
var poolOfSandcastles = new Pool( { numberOfInstances: 3 }, { useStrictMode: true } );
var script = poolOfSandcastles.createScript("\
exports.main = function() {\
exit('Hello World!');\
}\
");
script.on('exit', function(err, output) {
console.log(output);
});
var script2 = poolOfSandcastles.createScript("\
exports.main = function() {\
exit('Hello World again!');\
}\
");
script2.on('exit', function(err, output) {
console.log(output);
});
script.run();
script2.run();
================================================
FILE: examples/timeout.js
================================================
var SandCastle = require('../lib').SandCastle;
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
while(true) {};\
}\
");
script.on('exit', function(err, output) {
console.log('this will never happen.');
});
script.on('timeout', function() {
console.log('I timed out, oh what a silly script I am!');
});
script.run();
================================================
FILE: lib/index.js
================================================
exports.Pool = require('./pool').Pool;
exports.SandCastle = require('./sandcastle').SandCastle;
exports.Sandbox = require('./sandbox').Sandbox;
================================================
FILE: lib/pool.js
================================================
var _ = require('lodash'),
SandCastle = require("./sandcastle").SandCastle;
function Pool(opts, sandCastleCreationOpts) {
_.extend(this, {
numberOfInstances: 1
}, opts);
if(this.numberOfInstances < 1) {
throw "Can't create a pool with zero instances";
}
this.sandcastles = [];
this.runQueue = [];
this.consumerSleeping = true;
for(var i = 0; i < this.numberOfInstances; ++i) {
var sandCastleOptions = {}
_.extend( sandCastleOptions,
sandCastleCreationOpts,
{ socket: '/tmp/sandcastle_' + i.toString() + '.sock' }
);
this.sandcastles.push({
castle: new SandCastle(sandCastleOptions),
running: false
});
}
};
Pool.prototype.kill = function() {
this.sandcastles.forEach(function(sandcastleData) {
sandcastleData.castle.kill();
});
}
Pool.prototype.consumeScript = function() {
if(this.runQueue && this.runQueue.length > 0) {
for(var i = 0; i < this.sandcastles.length; ++i) {
var sandcastleData = this.sandcastles[i];
if(!sandcastleData.running && sandcastleData.castle.isInitialized()) {
var nextScript = this.runQueue.splice(0,1)[0];
if(nextScript && nextScript.script) {
this.runOnSandCastle(nextScript.script, nextScript.globals, sandcastleData);
} else {
// No scripts on queue.
break;
}
}
}
setImmediate(function() {
this.consumeScript()
}.bind(this));
this.consumerSleeping = false;
} else {
this.consumerSleeping = true;
}
}
Pool.prototype.runOnSandCastle = function(nextScript, scriptGlobals, sandcastleData) {
var _this = this;
sandcastleData.running = true;
nextScript.on('exit', function() {
sandcastleData.running = false;
});
nextScript.on('timeout', function() {
sandcastleData.running = false;
});
nextScript.setSandCastle(sandcastleData.castle);
nextScript.super_run(scriptGlobals);
}
Pool.prototype.requestRun = function(script, scriptGlobals) {
this.runQueue.push({script: script, globals: scriptGlobals});
if(this.consumerSleeping) {
this.consumeScript();
}
};
Pool.prototype.createScript = function(source, opts) {
var _this = this;
// All scripts are created from first sandbox, but the
// final target-sandbox is decided just before running.
var newScript = this.sandcastles[0].castle.createScript(source, opts);
// Override run-function, but keep the run function of superclass in
// super_run. This allows drop in placement of Pool in place of SandCastle.
newScript.super_run = newScript.run;
newScript.run = function (globals) {
_this.requestRun(newScript, globals);
}
return newScript;
}
exports.Pool = Pool;
================================================
FILE: lib/sandbox.js
================================================
var _ = require('lodash'),
net = require('net'),
vm = require('vm'),
BufferStream = require('bufferstream'),
clone = require('clone');
function Sandbox(opts) {
_.extend(this, {
socket: '/tmp/sandcastle.sock'
}, opts);
}
Sandbox.prototype.start = function() {
var _this = this;
var data = '';
this.server = net.createServer(function(c) {
var stream = new BufferStream({size:'flexible'});
// script begin
stream.split('\u0000\u0000', function(chunk) {
_this.executeScript(c, chunk);
});
// recieved answer
stream.split('\u0000', function (chunk) {
_this.answerTask(c, chunk);
});
c.on('data', stream.write);
});
this.server.listen(this.socket, function() {
console.log('sandbox server created'); // emit data so that sandcastle knows sandbox is created
});
this.server.on('error', function() {
setTimeout(function() {
_this.start();
}, 500);
});
};
Sandbox.prototype._sendError = function (connection, e, replaceStack) {
connection.write(JSON.stringify({
error: {
message: e.message,
stack: !replaceStack ? e.stack : e.stack.replace()
}
}) + '\u0000\u0000'); // exit/start separator
};
Sandbox.prototype.answerTask = function(connection, data) {
var _this = this;
try {
var taskData = JSON.parse(data.toString()),
taskName = taskData.task,
onAnswerName = 'on' + taskName.charAt(0).toUpperCase() + taskName.slice(1) + 'Task';
if (this._ctx.exports[onAnswerName]) {
this._ctx.exports[onAnswerName](taskData.data);
}
else if (this._ctx.exports.onTask) {
this._ctx.exports.onTask(taskName, taskData.data);
}
}
catch (e) {
_this._sendError(connection, e);
}
};
Sandbox.prototype.executeScript = function(connection, data) {
var contextObject = {
runTask: function (taskName, options) {
options = options || {};
try {
connection.write(JSON.stringify({
task: taskName,
options: options
}) + '\u0000'); // task seperator
} catch(e) {
this._sendError(connection, e, false);
}
},
exit: function(output) {
try {
connection.write(JSON.stringify(output) + '\u0000\u0000'); // exit/start separator
} catch(e) {
_this._sendError(connection, e, true);
}
}
};
try {
var script = JSON.parse(data);
// The trusted global variables.
if (script.globals) {
var globals = JSON.parse(script.globals);
Object.keys(globals).forEach(function(key) {
contextObject[key] = globals[key];
});
}
// The trusted API.
if (script.sourceAPI) {
var api = eval(script.sourceAPI);
Object.keys(api).forEach(function(key) {
contextObject[key] = api[key];
});
}
// recursively clone contextObject without prototype,
// to prevent exploits using __defineGetter__, __defineSetter__.
// https://github.com/bcoe/sandcastle/pull/21
contextObject = clone(contextObject, true, Infinity, null);
this._ctx = vm.createContext(contextObject);
vm.runInNewContext( this.wrapForExecution(script.source, script.methodName), this._ctx);
} catch (e) {
this._sendError(connection, e, false);
}
};
Sandbox.prototype.wrapForExecution = function(source, methodName) {
return "var exports = Object.create(null);" + source + "\nexports." + methodName + "();";
};
exports.Sandbox = Sandbox;
================================================
FILE: lib/sandcastle.js
================================================
var _ = require('lodash'),
Script = require('./script').Script,
path = require('path'),
fs = require('fs'),
os = require('os'),
debug = require('debug')('sandcastle'),
spawn = require( 'child_process' ).spawn;
var SIGHUP = os.platform()=='win32' ? 'SIGTERM' : 'SIGHUP';
function SandCastle(opts) {
var _this = this;
_.extend(this, {
client: null,
api: null,
timeout: 5000,
sandbox: null,
lastHeartbeat: (new Date()).getTime(),
socket: '/tmp/sandcastle.sock',
useStrictMode: true,
memoryLimitMB: 0,
cwd: process.cwd(),
spawnExecPath: process.execPath,
refreshTimeoutOnTask: false
}, opts);
if (this.api) {
if (this.api.indexOf('{') !== -1) {
// allow the API to be passed in as a blob of source-code.
this.sourceAPI = this.api;
} else {
// otherwise, load the API from a file.
// expanding ./ to current working directory.
if (this.api.indexOf('.') === 0) this.api = path.join(this.cwd, this.api);
this.sourceAPI = fs.readFileSync(this.api, 'utf-8');
}
}
this.spawnSandbox();
this.startHeartbeat();
// Shutdown the sandbox subprocess.
// when the sandcastle process is terminated.
process.on('exit', function() {
_this.sandbox.kill(SIGHUP);
});
}
SandCastle.prototype.sandboxReady = function(callback) {
var _this = this;
if (this.sandboxInitialized) {
callback();
} else {
setTimeout(function() {
_this.sandboxReady(callback);
}, 500);
}
};
SandCastle.prototype.kickOverSandCastle = function() {
if(this.sandboxInitialized) {
this.sandboxInitialized = false;
this.sandbox.kill(SIGHUP);
}
};
SandCastle.prototype.spawnSandbox = function() {
var _this = this;
// attempt to unlink the old socket.
try {fs.unlinkSync(this.socket)} catch (e) {};
this.sandbox = spawn(this.spawnExecPath, [
_this.useStrictMode ? "--use_strict" : "--nouse_strict",
"--max_old_space_size=" + _this.memoryLimitMB.toString(),
__dirname + '/../bin/sandcastle.js',
'sandbox',
'--socket=' + this.socket
], {cwd: _this.cwd});
// Assume that the sandbox is created once
// data is emitted on stdout.
this.sandbox.stdout.on('data', function(data) {
debug("Sandbox output: " + data.toString());
_this.waitingOnHeartbeat = false; // Used to keep only one heartbeat on the wire at a time.
_this.sandboxInitialized = true;
});
this.sandbox.stderr.on('data', function(data) {
debug("Sandbox error: " + data.toString());
_this.waitingOnHeartbeat = false;
});
this.sandbox.on('exit', function (code) {
_this.spawnSandbox();
});
};
SandCastle.prototype.kill = function() {
clearInterval(this.heartbeatId);
this.sandbox.removeAllListeners('exit');
this.sandbox.kill(SIGHUP);
process.removeAllListeners('exit');
};
SandCastle.prototype.startHeartbeat = function() {
var _this = this;
_this.heartbeatId = setInterval(function() {
var now = (new Date()).getTime();
_this.runHeartbeatScript();
if ( (now - _this.lastHeartbeat) > _this.timeout) {
_this.lastHeartbeat = (new Date()).getTime();
_this.kickOverSandCastle();
}
}, 500);
};
SandCastle.prototype.runHeartbeatScript = function() {
// Only wait for one heartbeat script
// to execute at a time.
if (this.waitingOnHeartbeat) return;
this.waitingOnHeartbeat = true;
var _this = this,
script = this.createScript("exports.main = function() {exit(true)}");
script.on("exit", function(err, output) {
if (output) {
_this.lastHeartbeat = (new Date()).getTime();
_this.waitingOnHeartbeat = false;
}
});
script.run('main');
};
SandCastle.prototype.createScript = function(source, opts) {
var sourceAPI = this.sourceAPI || '';
if (opts && opts.extraAPI) sourceAPI += ";\n" + opts.extraAPI
return new Script({
source: source,
sourceAPI: sourceAPI,
timeout: this.timeout,
socket: this.socket,
sandcastle: this
});
};
SandCastle.prototype.isInitialized = function() {
return this.sandboxInitialized;
}
SandCastle.prototype.getSocket = function() {
return this.socket;
}
exports.SandCastle = SandCastle;
================================================
FILE: lib/script.js
================================================
var _ = require('lodash'),
net = require('net'),
events = require('events'),
util = require('util'),
BufferStream = require('bufferstream'),
Buffer = require('buffer').Buffer;
function Script(opts) {
events.EventEmitter.call(this);
_.extend(this, {
source: '',
socket: '/tmp/sandcastle.sock',
timeout: 5000,
exited: false,
sandcastle: null // the parent sandcastle executing this script.
}, opts);
};
util.inherits(Script, events.EventEmitter);
Script.prototype.run = function(methodName, globals) {
var _this = this;
// passed in methodName argument is the globals object
if (globals === undefined && typeof methodName === 'object') {
globals = methodName;
methodName = null;
}
// we default to executing 'main'
methodName = methodName ? methodName : 'main';
this.reset();
this.createTimeout(methodName);
this.createClient(methodName, globals);
};
Script.prototype.createTimeout = function(methodName) {
var _this = this;
if (this.timeoutId) clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(function() {
if (_this.exited) return;
_this.exited = true;
_this.sandcastle.kickOverSandCastle();
_this.emit('timeout', methodName);
}, this.timeout);
};
Script.prototype.reset = function() {
if (this.timeoutId) clearTimeout(this.timeoutId);
this.exited = false;
};
Script.prototype.createClient = function(methodName, globals) {
var _this = this;
this.sandcastle.sandboxReady(function() {
if (_this.exited) return;
var client = net.createConnection(_this.sandcastle.getSocket(), function() {
client.write(JSON.stringify({
source: _this.source,// the untrusted JS.
sourceAPI: _this.sourceAPI,// the trusted API.
globals: JSON.stringify(globals), // trusted global variables.
methodName: methodName
}) + '\u0000\u0000'); // the chunk separator
});
client.on('close', function() {
if (!_this.dataReceived) {
setTimeout(function() {
_this.createClient(methodName, globals);
}, 500);
}
});
client.on('error', function(err) {
setTimeout(function() {
_this.createClient(methodName, globals);
}, 500);
});
var stream = new BufferStream({size:'flexible'});
stream.split('\u0000\u0000', function(chunk) {
client.end();
_this.onExit(methodName, chunk);
});
stream.split('\u0000', function (chunk) {
_this.onTask(client, methodName, chunk); // handling the task
});
client.on('data', function(chunk) {
_this.dataReceived = true;
stream.write(chunk);
});
});
};
Script.prototype._parseChunk = function(data) {
var output = null,
error = null;
try {
if (data.toString() !== 'undefined') {
output = JSON.parse(data);
if (output !== null && output.error) {
error = new Error(output.error.message);
error.stack = output.error.stack;
output = null;
}
}
} catch (e) {
error = e;
}
return {
output: output,
error: error
};
};
Script.prototype.onExit = function(methodName, data) {
var _this = this,
parsed = {
output: null,
error: null
};
if (this.exited) return;
this.exited = true;
parsed = _this._parseChunk(data);
this.emit('exit', parsed.error, parsed.output, methodName);
};
Script.prototype.onTask = function(client, methodName, data) {
var _this = this,
parsed = _this._parseChunk(data);
if (this.exited) return;
parsed.output = parsed.output || {};
parsed.output.options = parsed.output.options || {};
this.emit('task', parsed.error, parsed.output.task, parsed.output.options, methodName, function (answerData) {
if (_this.refreshTimeoutOnTask) _this.createTimeout(methodName);
client.write(JSON.stringify({ task: parsed.output.task, data: answerData }) + '\u0000');
});
};
Script.prototype.setSandCastle = function(sandcastle) {
this.sandcastle = sandcastle;
};
exports.Script = Script;
================================================
FILE: package.json
================================================
{
"name": "sandcastle",
"directories": {
"lib": "./lib",
"bin": "./bin"
},
"main": "./lib/index.js",
"bin": "./bin/sandcastle.js",
"version": "1.3.3",
"author": "Ben Coe <bencoe@gmail.com>",
"engines": [
"node"
],
"description": "A simple and powerful sandbox for running untrusted JavaScript.",
"keywords": [
"sandbox"
],
"repository": {
"type": "git",
"url": "git://github.com/bcoe/sandcastle.git"
},
"scripts": {
"coverage": "./node_modules/.bin/mocha test/* --require blanket --colors --timeout=10000 -R html-cov > coverage.html",
"test": "mocha --timeout=10000 --check-leaks --ui exports --require patched-blanket -R mocoverage"
},
"config": {
"blanket": {
"pattern": "lib",
"data-cover-never": [
"node_modules",
"test"
],
"output-reporter": "spec"
}
},
"dependencies": {
"bufferstream": "^0.6.2",
"clone": "^0.1.18",
"debug": "^2.1.2",
"lodash": "^2.4.1",
"optimist": "^0.3.4"
},
"devDependencies": {
"async": "^0.9.0",
"mocha": "2.1.0",
"mocoverage": "^1.0.0",
"patched-blanket": "^1.0.1"
}
}
================================================
FILE: test/exploits-test.js
================================================
var assert = require('assert'),
SandCastle = require('../lib').SandCastle,
fs = require('fs');
describe('__defineGetter__-exploit', function () {
it('should not execute untrusted code as a result of __defineGetter_ exploit', function (finished) {
// fix for exploit: https://github.com/bcoe/sandcastle/pull/21
var sandcastle = new SandCastle(),
script = sandcastle.createScript(fs.readFileSync("./test/fixtures/exploit-getter.txt").toString());
script.on('exit', function(err, output) {
setTimeout(function() {
sandcastle.kill();
assert.equal(fs.existsSync('./owned.txt'), false);
finished();
}, 2000);
});
script.run({parameters: {string: 'hello!'}});
});
});
describe('arguments.callee-exploit', function() {
it('should not execute untrusted code as a result of walking the arguments.callee chain', function(finished) {
// fix for exploit: https://github.com/bcoe/sandcastle/pull/21
var sandcastle = new SandCastle(),
script = sandcastle.createScript(fs.readFileSync("./test/fixtures/exploit-callee.txt").toString());
setTimeout(function() {
sandcastle.kill();
assert.equal(fs.existsSync('./owned.txt'), false);
finished();
}, 2000);
script.run({parameters: {string: 'hello!'}});
});
});
================================================
FILE: test/fixtures/exploit-callee.txt
================================================
exports.main = function() {
var payload = "var fs = require('fs');fs.writeFileSync('owned.txt', 'You could have been owned now\\n');exports.api = {};";
var jsonPayload = JSON.stringify({source:";exports.main = function(){exit('ok')};", sourceAPI:payload});
var retVal =
{
f: {}
};
retVal.__defineGetter__("f", function() {
throw {
stack:
{
replace: function() {
var a = {};
a.__defineGetter__("stack", function() {
// calls Sandbox.executeScript(connection, data)
arguments.callee.caller(null, jsonPayload);
});
throw a;
}
}
};
});
exit(retVal);
}
================================================
FILE: test/fixtures/exploit-getter.txt
================================================
exports.main = function() {
var origSubstr = parameters.string.__proto__.substr;
var payload = "var fs = require('fs');fs.writeFileSync('owned.txt', 'You could have been owned now\\n');";
var jsonPayload = JSON.stringify({source:";exports.main = function(){exit('ok')};", sourceAPI:payload});
var defineGetter = parameters.__defineGetter__;
var defineSetter = parameters.__defineSetter__;
defineSetter.call(parameters.__proto__, 'data', function(val) {
this.__hidden_data = val;
});
defineGetter.call(parameters.__proto__, 'data', function() {
var chained = this.__hidden_data;
if (typeof chained != "function")
return chained;
return function(data) {
return chained.call(this, jsonPayload + '\u0000');
};
});
exit('ok');
}
================================================
FILE: test/pool-test.js
================================================
var equal = require('assert').equal,
notEqual = require('assert').notEqual,
Pool = require('../lib').Pool;
describe('Pool', function () {
it('should run multiple scripts', function (finished) {
var pool = new Pool({numberOfInstances: 5});
var scriptsExited = 0;
for (var i = 0; i < 20; ++i) {
var script = pool.createScript("\
exports.main = function() {\n\
exit(testGlobal);\n\
}\n\
"
);
script.on('exit', function (err, result) {
scriptsExited++;
if (scriptsExited == 10) {
pool.kill();
equal(10, result);
finished();
}
});
script.run({testGlobal: 10});
}
});
it('should run scripts on non blocking instances', function (finished) {
var pool = new Pool({numberOfInstances: 2});
var exited = false;
// Create blocking script.
var script = pool.createScript("\
exports.main = function() {\n\
while(true);\
}\n\
"
);
script.run();
var scriptsExited = 0;
for (var i = 0; i < 10; ++i) {
var script2 = pool.createScript("\
exports.main = function() {\n\
exit(10);\n\
}\n\
"
);
script2.on('exit', function (err, result) {
scriptsExited++;
if (scriptsExited == 10) {
pool.kill();
equal(10, result);
exited = true;
finished();
}
});
script2.run();
}
setTimeout(function () {
if (!exited) {
equal(false, true);
}
}, 3000);
});
it('should not be created if there are zero or negative amount of specified instances', function (finished) {
var pool = null;
try {
pool = new Pool({numberOfInstances: 0});
equal(false, true);
} catch (error) {
notEqual(-1, error.indexOf("Can't create a pool with zero instances"));
finished();
}
});
});
================================================
FILE: test/sandcastle-test.js
================================================
var equal = require('assert').equal,
assert = require('assert'),
notEqual = require('assert').notEqual,
SandCastle = require('../lib').SandCastle,
Pool = require('../lib').Pool,
path = require('path');
describe('SandCastle', function () {
it('should fire on("exit") when a sandboxed script calls the exit method', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
var result = 1 + 1;\
exit({\
results: [result]\
});\
}\
");
script.on('exit', function (err, result, methodName) {
sandcastle.kill();
equal(result.results[0], 2);
equal('main', methodName);
finished();
});
script.run();
});
it('should pass global variables to run()', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
exit(foo);\
}\
");
script.on('exit', function (err, result, methodName) {
sandcastle.kill();
equal('bar', result);
equal('main', methodName);
finished();
});
script.run({foo: 'bar'});
});
it('should run the specified function and pass global variables correctly', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports = {\
foo: function () {\
exit(foo);\
}\
};\
");
script.on('exit', function (err, result, methodName) {
sandcastle.kill();
equal('bar', result);
equal('foo', methodName);
finished();
});
script.run('foo', {foo: 'bar'});
});
it('should not allow require() to be called', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
var net = require('net');\
}\
");
script.on('exit', function (err, result) {
sandcastle.kill();
assert(err.message.match(/require is not defined/));
finished();
});
script.run();
});
it('should able to exit(null)', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\
exit(null);\
}\
");
script.on('exit', function (err, result) {
sandcastle.kill();
equal(result,null);
finished();
});
script.run();
});
it('should provide an API', function (finished) {
var sandcastle = new SandCastle({
api: './examples/api.js'
});
var script = sandcastle.createScript("\
exports.main = function() {\
getFact(function(fact) {\
exit(fact);\
});\
}\
");
script.on('exit', function (err, result) {
sandcastle.kill();
equal(result, 'The rain in spain falls mostly on the plain.');
finished();
});
script.run();
});
it('should allow API to be passed in as string', function(finished) {
var sandcastle = new SandCastle({
api: "_ = require('lodash');\
exports.api = {\
map: function(values, cb) {\
return _.map(values, cb);\
}\
}"
});
var script = sandcastle.createScript("\
exports.main = function() {\
exit(map([{a: 1}, {a: 2}, {a: 3}], function(obj) {\
return obj.a;\
}))\
}\
");
script.on('exit', function (err, result) {
sandcastle.kill();
equal(JSON.stringify(result), JSON.stringify([1, 2, 3]));
finished();
});
script.run();
});
it('should provide an API and a per-script API', function (finished) {
var sandcastle = new SandCastle({
api: './examples/api.js'
});
var script = sandcastle.createScript("\
exports.main = function() {\
callAdditional(function(fact) {\
exit(fact);\
});\
}\
", {extraAPI: "function anotherFunction(cb) { cb('The reign in spane falls mostly on the plain') }" });
script.on('exit', function (err, result) {
sandcastle.kill();
equal(result, 'The reign in spane falls mostly on the plain');
finished();
});
script.run();
});
it('should timeout and respawn when looping script runs', function (finished) {
this.timeout(10000);
var sandcastle = new SandCastle({
api: './examples/api.js',
timeout: 2000
});
var loopingScript = sandcastle.createScript("\
exports.main = function() {\
while(true) {};\
}\
");
var safeScript = sandcastle.createScript("\
exports.main = function() {\
exit('banana');\
}\
");
safeScript.on('exit', function (err, result) {
sandcastle.kill();
equal(result, 'banana');
finished();
});
loopingScript.on('timeout', function (methodName) {
equal(methodName, 'main');
safeScript.run();
});
loopingScript.run();
});
it('should return a human readable stacktrace', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports.main = function() {\n\
var net = require('net');\n\
}\n\
"
);
script.on('exit', function (err, result) {
sandcastle.kill();
equal(err.stack.indexOf('2:21') > -1, true);
finished();
});
script.run();
});
it('should enforce memory limit', function (finished) {
this.timeout(10000);
var sandcastle = new SandCastle({memoryLimitMB: 10});
var script = sandcastle.createScript("\
exports.main = function() {\n\
var test = []; \
for(var i = 0; i < 5000000; ++i) { \
test[i] = 'a'; \
} \
exit(1); \
}\n\
"
);
script.on('exit', function (err, result) {
// Should not go here.
equal(false, true);
});
script.on('timeout', function (err, result) {
sandcastle.kill();
finished();
});
script.run();
});
it('sets cwd, when running scripts', function(finished) {
var cwd = process.cwd() + '/test';
var sandcastle = new SandCastle({
api: '../examples/api.js',
cwd: cwd
});
var script = sandcastle.createScript("\
exports.main = function() {\
exit({ cwd: cwd() });\
}\
");
script.on('exit', function(err, result) {
equal(cwd, result.cwd);
sandcastle.kill();
finished();
});
script.run();
});
it('should allow api to see globals',function(finished){
var sandcastle = new SandCastle({
api: './examples/contextObjectApi.js'
});
var script = sandcastle.createScript("\
exports.main = function() {\n\
var globalState = {};\n\
if(typeof state === \"undefined\"){\n\
globalState = 'none';\n\
}\n\
else{\n\
globalState = state;\n\
}\n\
exit({\n\
globalState:globalState,\n\
apiState:stateManager.getState()\n\
});\n\
}\n");
script.on('exit', function(err, result) {
equal(result.globalState, 'none');
equal(result.apiState.key, 'val');
sandcastle.kill();
finished();
});
script.run({state:{key:'val'}});
});
it('should correctly run the "test" task and and return the result', function (finished) {
var sandcastle = new SandCastle();
var script = sandcastle.createScript("\
exports = {\
onTestTask: function (data) {\
if (data.count > 1) {\
exit(data);\
}\
else {\
runTask('test', data);\
}\
},\
main: function() {\
runTask('test', {count: 0});\
}\
}\
");
script.on('task', function (err, taskName, options, methodName, callback) {
options.count++;
equal(taskName, 'test');
equal(methodName, 'main');
return callback(options);
});
script.on('exit', function (err, result) {
equal(result.count, 2);
sandcastle.kill();
finished();
});
script.run();
});
});
gitextract_oqlrruqn/
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── bin/
│ └── sandcastle.js
├── examples/
│ ├── api-example.js
│ ├── api.js
│ ├── benchmark.js
│ ├── contextObjectApi.js
│ ├── error.js
│ ├── example.txt
│ ├── hello.js
│ ├── multiple-functions.js
│ ├── pool.js
│ └── timeout.js
├── lib/
│ ├── index.js
│ ├── pool.js
│ ├── sandbox.js
│ ├── sandcastle.js
│ └── script.js
├── package.json
└── test/
├── exploits-test.js
├── fixtures/
│ ├── exploit-callee.txt
│ └── exploit-getter.txt
├── pool-test.js
└── sandcastle-test.js
SYMBOL INDEX (4 symbols across 4 files)
FILE: lib/pool.js
function Pool (line 4) | function Pool(opts, sandCastleCreationOpts) {
FILE: lib/sandbox.js
function Sandbox (line 7) | function Sandbox(opts) {
FILE: lib/sandcastle.js
function SandCastle (line 11) | function SandCastle(opts) {
FILE: lib/script.js
function Script (line 8) | function Script(opts) {
Condensed preview — 26 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (49K chars).
[
{
"path": ".gitignore",
"chars": 72,
"preview": "node_modules\n.DS_store\ntest.sh\ntest.js\nnohup.out\nout.txt\n\n/coverage.html"
},
{
"path": ".travis.yml",
"chars": 60,
"preview": "language: node_js\nnode_js:\n - \"0.10\"\n - \"0.12\"\n - \"iojs\"\n"
},
{
"path": "LICENSE.txt",
"chars": 1055,
"preview": "Copyright (c) 2012 Benjamin Coe\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this so"
},
{
"path": "README.md",
"chars": 9000,
"preview": "SandCastle\n==========\n\n[](https://travis-ci.org/bcoe/sandcastl"
},
{
"path": "bin/sandcastle.js",
"chars": 423,
"preview": "#!/usr/bin/env node\n\nvar sandcastle = require('../lib'),\n argv = require('optimist').argv,\n mode = argv._.shift();\n\nsw"
},
{
"path": "examples/api-example.js",
"chars": 548,
"preview": "// example of using an external API. In this case\n// we pul lin lodash's extend.\nvar SandCastle = require('../lib').Sand"
},
{
"path": "examples/api.js",
"chars": 521,
"preview": "var fs = require('fs');\nvar lodash = require('lodash')\n\nexports.api = {\n extend: function () {\n lodash.extend.apply("
},
{
"path": "examples/benchmark.js",
"chars": 2457,
"preview": "var SandCastle = require('../lib').SandCastle,\n equal = require('assert').equal;\n\nvar sandcastle = new SandCastle({\n a"
},
{
"path": "examples/contextObjectApi.js",
"chars": 200,
"preview": "\nvar StateManager = function(){\n\tvar state = contextObject.state;\n\n\tdelete contextObject.state;\n\n\tthis.getState=function"
},
{
"path": "examples/error.js",
"chars": 304,
"preview": "var SandCastle = require('../').SandCastle;\n\nvar sandcastle = new SandCastle();\n\nvar script = sandcastle.createScript(\"\\"
},
{
"path": "examples/example.txt",
"chars": 44,
"preview": "The rain in spain falls mostly on the plain."
},
{
"path": "examples/hello.js",
"chars": 315,
"preview": "var SandCastle = require('../lib').SandCastle;\n\nvar sandcastle = new SandCastle();\n\nvar script = sandcastle.createScript"
},
{
"path": "examples/multiple-functions.js",
"chars": 705,
"preview": "var async = require('async'),\n SandCastle = require('../lib').SandCastle,\n sandcastle = new SandCastle();\n\nvar script "
},
{
"path": "examples/pool.js",
"chars": 606,
"preview": "var Pool = require('../lib').Pool;\n\n// You can give options for SandCastle instances with second parameter.\nvar poolOfSa"
},
{
"path": "examples/timeout.js",
"chars": 392,
"preview": "var SandCastle = require('../lib').SandCastle;\n\nvar sandcastle = new SandCastle();\n\nvar script = sandcastle.createScript"
},
{
"path": "lib/index.js",
"chars": 143,
"preview": "exports.Pool = require('./pool').Pool;\nexports.SandCastle = require('./sandcastle').SandCastle;\nexports.Sandbox = requir"
},
{
"path": "lib/pool.js",
"chars": 2733,
"preview": "var _ = require('lodash'),\n SandCastle = require(\"./sandcastle\").SandCastle;\n\nfunction Pool(opts, sandCastleCreationOpt"
},
{
"path": "lib/sandbox.js",
"chars": 3511,
"preview": "var _ = require('lodash'),\n net = require('net'),\n vm = require('vm'),\n BufferStream = require('bufferstream'),\n clo"
},
{
"path": "lib/sandcastle.js",
"chars": 4185,
"preview": "var _ = require('lodash'),\n Script = require('./script').Script,\n path = require('path'),\n fs = require('fs'),\n os ="
},
{
"path": "lib/script.js",
"chars": 4057,
"preview": "var _ = require('lodash'),\n net = require('net'),\n events = require('events'),\n util = require('util'),\n BufferStrea"
},
{
"path": "package.json",
"chars": 1160,
"preview": "{\n \"name\": \"sandcastle\",\n \"directories\": {\n \"lib\": \"./lib\",\n \"bin\": \"./bin\"\n },\n \"main\": \"./lib/index.js\",\n \""
},
{
"path": "test/exploits-test.js",
"chars": 1314,
"preview": "var assert = require('assert'),\n SandCastle = require('../lib').SandCastle,\n fs = require('fs');\n\ndescribe('__defineGe"
},
{
"path": "test/fixtures/exploit-callee.txt",
"chars": 891,
"preview": "exports.main = function() {\n var payload = \"var fs = require('fs');fs.writeFileSync('owned.txt', 'You could have "
},
{
"path": "test/fixtures/exploit-getter.txt",
"chars": 778,
"preview": "exports.main = function() {\n var origSubstr = parameters.string.__proto__.substr;\n var payload = \"var fs = require('fs"
},
{
"path": "test/pool-test.js",
"chars": 1957,
"preview": "var equal = require('assert').equal,\n notEqual = require('assert').notEqual,\n Pool = require('../lib').Pool;\n\ndescribe"
},
{
"path": "test/sandcastle-test.js",
"chars": 8184,
"preview": "var equal = require('assert').equal,\n assert = require('assert'),\n notEqual = require('assert').notEqual,\n SandCastle"
}
]
About this extraction
This page contains the full source code of the bcoe/sandcastle GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 26 files (44.5 KB), approximately 11.8k tokens, and a symbol index with 4 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.