Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Fix command injection vulnerability #1

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ oneByOne([
}
, cb => {
console.log("> Created README.md");
myRepo.exec("add .", cb);
myRepo.exec(['add', '.'], cb);
}
, cb => {
console.log("> Added the files.");
Expand Down
25 changes: 9 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,22 @@ class Gry {
* @return {Gry} The `Gry` instance.
*/
exec (command, args, callback) {

var eargs = [];
if (typeof args === "function") {
callback = args;
args = null;
}

// Handle spawn
if (Array.isArray(args)) {
eargs.push("git", [command].concat(args));
} else {
eargs.push("git " + command.trim());
}

eargs.push({ cwd: this.cwd });

// Add the callback function
eargs.push((err, stdout) => {
if (err) { return callback(err); }
callback(null, stdout.trimRight());
});
console.log({command, eargs, callback})

el.add.apply(el, eargs);
el.add('git', command, eargs[0], eargs[1]);
return this;
}

Expand All @@ -88,7 +81,7 @@ class Gry {
* @return {Gry} The `Gry` instance.
*/
init (callback) {
return this.exec("init", callback);
return this.exec(['init'], callback);
}

/**
Expand Down Expand Up @@ -128,7 +121,7 @@ class Gry {
callback = options;
options = "";
}
return this.exec("commit -m \"" + message + "\" " + options, callback)
return this.exec(['commit', '-m', message, ...options.split(' ').filter(a => a)], callback)
}

/**
Expand All @@ -146,7 +139,7 @@ class Gry {
callback = options;
options = "";
}
return this.exec("pull " + options, callback);
return this.exec(['pull', ...options.split(' ')], callback);
}

/**
Expand All @@ -164,7 +157,7 @@ class Gry {
callback = options;
options = ".";
}
return this.exec("add " + options, callback);
return this.exec(['add', ...options.split(' ')], callback);
}

/**
Expand All @@ -182,7 +175,7 @@ class Gry {
callback = options;
options = "";
}
return this.exec("branch " + options, callback);
return this.exec(['branch', ...options.split(' ')], callback);
}

/**
Expand All @@ -200,7 +193,7 @@ class Gry {
callback = options;
options = "";
}
return this.exec("checkout " + options, callback);
return this.exec(['checkout', ...options.split(' ')], callback);
}

/**
Expand All @@ -219,7 +212,7 @@ class Gry {
callback = options;
options = "";
}
return this.exec("clone " + gitUrl + " " + options, callback);
return this.exec(['clone', gitUrl, ...options.split(' ')], callback);
}
}

Expand Down