Skip to content

Commit 3e585f0

Browse files
authored
Merge pull request #8 from 418sec/master
huntr - Command Injection Fix
2 parents 6890460 + 987c79e commit 3e585f0

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

lib/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const _ = require("lodash");
55
//import nodeify from '../node_modules/nodeify-ts/lib/';
66
const nodeify_ts_1 = require("nodeify-ts");
77
const child_process = require("child_process");
8-
const exec = child_process.exec;
8+
const execFile = child_process.execFile;
99
const extractResult = (result) => {
1010
try {
1111
result.object = JSON.parse(result.raw);
@@ -25,9 +25,7 @@ class Aws {
2525
}
2626
command(command, callback) {
2727
let aws = this;
28-
let execCommand = 'aws ' + command;
2928
const promise = Promise.resolve().then(function () {
30-
//console.log('execCommand =', execCommand);
3129
const env_vars = ('HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
3230
'AWS_SESSION_TOKEN AWS_DEFAULT_REGION ' +
3331
'AWS_DEFAULT_PROFILE AWS_CONFIG_FILE').split(' ');
@@ -54,7 +52,7 @@ class Aws {
5452
};
5553
//console.log('exec options =', execOptions);
5654
return new Promise((resolve, reject) => {
57-
exec(execCommand, execOptions, (error, stdout, stderr) => {
55+
execFile('aws', [...command.split(' ')], execOptions, (error, stdout, stderr) => {
5856
if (error) {
5957
const message = `error: '${error}' stdout = '${stdout}' stderr = '${stderr}'`;
6058
console.error(message);
@@ -66,7 +64,7 @@ class Aws {
6664
});
6765
}).then((data) => {
6866
let result = {
69-
command: execCommand,
67+
command,
7068
error: data.stderr,
7169
object: null,
7270
raw: data.stdout,

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as _ from 'lodash';
33
//import nodeify from '../node_modules/nodeify-ts/lib/';
44
import nodeify from 'nodeify-ts';
55
import * as child_process from 'child_process';
6-
const exec = child_process.exec;
6+
const execFile = child_process.execFile;
77

88

99
const extractResult = (result: Result): Result => {
@@ -25,10 +25,8 @@ export class Aws {
2525

2626
public command(command: string, callback?: (err: any, data: any) => void) {
2727
let aws = this;
28-
let execCommand = 'aws ' + command;
2928

3029
const promise = Promise.resolve().then(function () {
31-
//console.log('execCommand =', execCommand);
3230

3331

3432
const env_vars = ('HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
@@ -66,7 +64,7 @@ export class Aws {
6664
//console.log('exec options =', execOptions);
6765

6866
return new Promise<{ stderr: string, stdout: string }>( (resolve, reject) => {
69-
exec(execCommand, execOptions, (error, stdout, stderr) => {
67+
execFile('aws', [...command.split(' ')], execOptions, (error: Error | null, stdout: string, stderr: string) => {
7068
if (error) {
7169
const message = `error: '${error}' stdout = '${stdout}' stderr = '${stderr}'`;
7270
console.error(message);
@@ -79,7 +77,7 @@ export class Aws {
7977
}).then((data: { stderr: string, stdout: string }) => {
8078

8179
let result: Result = {
82-
command: execCommand,
80+
command,
8381
error: data.stderr,
8482
object: null,
8583
raw: data.stdout,

0 commit comments

Comments
 (0)