Comparing version 0.0.2 to 0.0.3
@@ -9,11 +9,22 @@ /* | ||
/* | ||
* Append default path if the command does not have a full path | ||
*/ | ||
function getAbsolutePath(command, defaultPath) { | ||
if (command && command.charAt(0) !== '/') { | ||
return defaultPath + '/' + command; | ||
} | ||
return command; | ||
} | ||
/* | ||
* Returns a function which throws the exception. | ||
*/ | ||
function permissionDenied(name, originalMethod, whitelist) { | ||
function permissionDenied(name, originalMethod, whitelistPath, whitelist) { | ||
return function () { | ||
if (whitelist.indexOf(arguments[0]) >= 0) { | ||
if (whitelist && whitelist.indexOf(getAbsolutePath(arguments[0], whitelistPath)) >= 0) { | ||
return originalMethod.apply(this, arguments); | ||
} else if (arguments.length >= 2 | ||
&& whitelist.indexOf((arguments[1])[1]) >= 0) { | ||
&& whitelist && whitelist.indexOf(getAbsolutePath((arguments[1])[1],whitelistPath)) >= 0) { | ||
return originalMethod.apply(this, arguments); | ||
@@ -51,3 +62,3 @@ } else { | ||
originalMethod = child[fn]; | ||
child[fn] = permissionDenied(fn, originalMethod, whitelistAbs); | ||
child[fn] = permissionDenied(fn, originalMethod, whitelistPath, whitelistAbs); | ||
} | ||
@@ -54,0 +65,0 @@ } |
{ | ||
"name": "restrict", | ||
"description": "Restricts applications from calling certain methods on process and all methods on child_process", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Rohini Harendra <rohini.raghav@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -37,2 +37,19 @@ /* | ||
try { | ||
require('child_process').exec('ls',['-ltr']); | ||
self.callback(null, {}); | ||
} catch (e) { | ||
self.callback(null, { | ||
'error': e | ||
}); | ||
} | ||
}, | ||
'verify error': function (topic) { | ||
assert.ok(topic.error === undefined); | ||
} | ||
}, | ||
'testing restrict child_process methods whitelist absolute': { | ||
topic: function () { | ||
var self = this; | ||
try { | ||
require('child_process').exec('/bin/ls',['-ltr']); | ||
@@ -39,0 +56,0 @@ self.callback(null, {}); |
8987
190
4