Skip to content

Commit 87219cb

Browse files
committed
SQSCANGHA-89 Fix command injection
1 parent 12d7d00 commit 87219cb

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

.github/workflows/qa-main.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,35 @@ jobs:
3838
- name: Run action with args
3939
uses: ./
4040
with:
41-
args: -Dsonar.someArg=aValue -Dsonar.scanner.internal.dumpToFile=./output.properties
41+
args: -Dsonar.someArg=aValue -Dsonar.anotherArgWithSpaces="Another Value"
4242
env:
4343
SONAR_HOST_URL: http://not_actually_used
4444
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
4545
- name: Assert
4646
run: |
4747
./test/assertFileContains ./output.properties "sonar.someArg=aValue"
48+
./test/assertFileContains ./output.properties "sonar.anotherArgWithSpaces=Another Value"
49+
argsInputInjectionTest:
50+
name: >
51+
'args' input with command injection
52+
strategy:
53+
matrix:
54+
os: [ ubuntu-latest, windows-latest, macos-latest ]
55+
runs-on: ${{ matrix.os }}
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
- name: Run action with args
61+
uses: ./
62+
with:
63+
args: -Dsonar.someArg=aValue && echo "Injection"
64+
env:
65+
SONAR_HOST_URL: http://not_actually_used
66+
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
67+
- name: Assert
68+
run: |
69+
./test/assertFileContains ./output.properties "sonar.someArg=aValue"
4870
projectBaseDirInputTest:
4971
name: >
5072
'projectBaseDir' input

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ runs:
5050
run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH
5151
shell: bash
5252
- name: Run SonarScanner
53-
run: ${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh ${{ inputs.args }}
53+
run: |
54+
args=(${{ inputs.args }})
55+
cmd=(${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh "${args[@]}")
56+
"${cmd[@]}"
5457
shell: bash
5558
env:
5659
INPUT_PROJECTBASEDIR: ${{ inputs.projectBaseDir }}

test/assertFileContains

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/bin/bash
22

3+
set -eou pipefail
4+
35
error() { echo -e "\\e[31m✗ $*\\e[0m"; }
46

5-
assertFileExists $1
7+
scriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")
8+
9+
$scriptDir/assertFileExists "$1"
610

7-
if ! grep -q $2 $1; then
11+
if ! grep -q "$2" "$1"; then
812
error "'$2' not found in '$1'"
913
exit 1
1014
fi

test/assertFileDoesntExist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

3+
set -eou pipefail
4+
35
error() { echo -e "\\e[31m✗ $*\\e[0m"; }
46

5-
if [ -f $1 ]; then
7+
if [ -f "$1" ]; then
68
error "File '$1' found"
79
exit 1
810
fi

test/assertFileExists

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

3+
set -eou pipefail
4+
35
error() { echo -e "\\e[31m✗ $*\\e[0m"; }
46

5-
if [ ! -f $1 ]; then
7+
if [ ! -f "$1" ]; then
68
error "File '$1' not found"
79
exit 1
810
fi

0 commit comments

Comments
 (0)