From 9b1fd7aa4ef5f2e7c0c601cb3393558c4a49ec6b Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 13 Feb 2012 20:11:51 +0000 Subject: [PATCH] use sandbox module for running untrusted code because it has a timeout --- modules/admin.js | 2 +- modules/js.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/admin.js b/modules/admin.js index 7e99ad9..ef0cfc6 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -37,7 +37,7 @@ var adminCommands = function(dbot) { 'unload': function(data, params) { if(dbot.moduleNames.include(params[1])) { - dbot.moduleNames[params[1]] = undefined; + delete dbot.moduleNames[params[1]]; dbot.reloadModules(); dbot.say(data.channel, 'Turned off module: ' + params[1]); } else { diff --git a/modules/js.js b/modules/js.js index db63e4e..6069b0c 100644 --- a/modules/js.js +++ b/modules/js.js @@ -1,12 +1,16 @@ var vm = require('vm'); +var sandbox = require('sandbox'); var js = function(dbot) { var dbot = dbot; + var s = new Sandbox(); var commands = { '~js': function(data, params) { var q = data.message.valMatch(/^~js (.*)/, 2); - dbot.say(data.channel, vm.runInNewContext(q[1])); + s.run(q[1], function(output) { + dbot.say(data.channel, output.result); + }); }, '~ajs': function(data, params) {