Skip to content

Commit 14ab5a1

Browse files
Merge pull request #118 from 418sec/master
fix: security Fix for Remote Code Execution - huntr.dev
2 parents 178252f + f7f3273 commit 14ab5a1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Promise = require('promise');
1414
var URL = require('url');
1515
var options = require('./options')
1616
var packageJson = require('./package.json')
17+
const shellescape = require('shell-escape');
1718

1819
var regexParseProjectName = /(.+:\/\/.+?\/|.+:)(.+\/[^\.]+)+(\.git)?/;
1920

@@ -56,7 +57,7 @@ function getMergeRequestTitle(title) {
5657

5758
exec('git rev-parse --show-toplevel', function (error, repoDir/*, stderr*/) {
5859
var filePath = repoDir.trim() + '/.git/PULL_REQUEST_TITLE';
59-
exec('git log -1 --pretty=%B > ' + filePath, function (/*error, remote, stderr*/) {
60+
exec('git log -1 --pretty=%B > ' + shellescape([filePath]), function (/*error, remote, stderr*/) {
6061
exec('git config core.editor', function (error, gitEditor/*, stderr*/) {
6162
editor(filePath, { editor: gitEditor.trim() || null }, function (/*code, sig*/) {
6263
fs.readFile(filePath, 'utf8', function (err, data) {
@@ -171,8 +172,8 @@ function getRemoteForBranch(branchName) {
171172
resolve(branchRemoteInfo.remote);
172173
} else {
173174
//Remote info is not supplied. Get it from remote set
174-
logger.log('Executing git config branch.' + branchName.trim() + '.remote');
175-
exec('git config branch.' + branchName.trim() + '.remote', { cwd: projectDir }, function (error, remote/*, stderr*/) {
175+
logger.log('Executing git config branch.' + shellescape([branchName.trim()]) + '.remote');
176+
exec('git config branch.' + shellescape([branchName.trim()]) + '.remote', { cwd: projectDir }, function (error, remote/*, stderr*/) {
176177
if (error) {
177178
console.error(colors.red('Error occured while getting remote of the branch: ', branchName , '\n') );
178179
console.log('\n\nSet the remote tracking by `git branch --set-upstream-to=origin/'+ branchName + '`. Assuming origin is your remote.');
@@ -194,7 +195,7 @@ function getURLOfRemote(remote) {
194195
logger.log('\nGetting URL of remote : ' + remote);
195196
var promise = new Promise(function (resolve/*, reject*/) {
196197
logger.log('Executing ', 'git config remote.' + remote.trim() + '.url');
197-
exec('git config remote.' + remote.trim() + '.url', { cwd: projectDir }, function (error, remoteURL/*, stderr*/) {
198+
exec('git config remote.' + shellescape([remote.trim()]) + '.url', { cwd: projectDir }, function (error, remoteURL/*, stderr*/) {
198199
if (error) {
199200
console.error(colors.red('Error occured :\n') , colors.red(error));
200201

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"gitlab": "^3.0.0",
4242
"open": "7.2.0",
4343
"promise": "^7.1.1",
44-
"readline-sync": "^1.4.7"
44+
"readline-sync": "^1.4.7",
45+
"shell-escape": "^0.2.0"
4546
}
4647
}

0 commit comments

Comments
 (0)