Skip to content

Commit

Permalink
[security] throw on unsafe option names
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jul 27, 2020
1 parent a3d9c9e commit 8efe421
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Expand Up @@ -2,7 +2,8 @@

const ChildProcess = require('child_process');
let vBoxManageBinary,
escapeArg;
escapeArg,
isOptionSafe;

// Host operating system
if (/^win/.test(process.platform)) {
Expand All @@ -23,12 +24,20 @@ if (/^win/.test(process.platform)) {
return '"' + arg.replace(/"/g, '"""') + '"';
};

isOptionSafe = opt => {
return !/\s|[\\"&]/.test(opt);
};

} else {
vBoxManageBinary = 'vboxmanage';

escapeArg = arg => {
return arg.replace(/([ \t\\|;&"`$*])/g, '\\$1');
};

isOptionSafe = opt => {
return !/([ \t\\|;&"`$*])/.test(opt);
};
}


Expand All @@ -54,6 +63,9 @@ VBoxManage.manage = function (command, options) {
}

for (const [option, value] of Object.entries(options)) {
if (!isOptionSafe(option))
throw new Error('An unsafe option was passed to VBoxManage.manage: ' + option);

command.push('--' + option);

if (value !== true) {
Expand Down

0 comments on commit 8efe421

Please sign in to comment.