New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

restrict

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restrict - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

19

lib/index.js

@@ -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, {});

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc