File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7474 - name : Assert the scanner was not called
7575 run : |
7676 ./test/assertFileDoesntExist ./output.properties
77+ argsCommandInjectionTest :
78+ name : >
79+ 'args' input with backticks injection does not execute command
80+ strategy :
81+ matrix :
82+ os : [ ubuntu-latest-large, windows-latest-large, macos-latest ]
83+ runs-on : ${{ matrix.os }}
84+ steps :
85+ - uses : actions/checkout@v5
86+ with :
87+ token : ${{ secrets.GITHUB_TOKEN }}
88+ - name : Run action with args
89+ uses : ./
90+ continue-on-error : true
91+ with :
92+ args : -Dsonar.someArg="test `echo Command Injection`"
93+ env :
94+ SONAR_HOST_URL : http://not_actually_used
95+ SONAR_SCANNER_JSON_PARAMS : ' {"sonar.scanner.internal.dumpToFile": "./output.properties"}'
96+ - name : Assert command in arg is not executed
97+ run : |
98+ ./test/assertFileContains ./output.properties "sonar.someArg=test Command Injection"
7799 projectBaseDirInputTest :
78100 name : >
79101 'projectBaseDir' input
Original file line number Diff line number Diff line change 5353 - name : Run SonarScanner
5454 run : |
5555 args=(${{ inputs.args }})
56- cmd=(${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh "${args[@]}")
57- "${cmd[@]}"
56+ "${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh" "${args[@]}"
5857 shell : bash
5958 env :
6059 INPUT_PROJECTBASEDIR : ${{ inputs.projectBaseDir }}
Original file line number Diff line number Diff line change @@ -73,9 +73,16 @@ if [[ -n "${SONAR_ROOT_CERT}" ]]; then
7373 scanner_args+=(" -Dsonar.scanner.truststorePassword=$SONAR_SSL_TRUSTSTORE_PASSWORD " )
7474fi
7575
76- scanner_args+=(" $@ " )
77-
76+ for arg in " $@ " ; do
77+ # Append each argument to the array
78+ # The double quotes around "$arg" are crucial
79+ scanner_args+=(" $arg " )
80+ done
81+ echo " Args to sonar-scanner: ${scanner_args} "
7882set -ux
7983
80- $SCANNER_BIN ${scanner_args[@]+" ${scanner_args[@]} " }
81-
84+ if [[ ${# scanner_args[@]} -gt 0 ]]; then
85+ $SCANNER_BIN " ${scanner_args[@]} "
86+ else
87+ $SCANNER_BIN
88+ fi
You can’t perform that action at this time.
0 commit comments