Skip to content

Commit 91e1738

Browse files
nickrolfeCopilot
andcommitted
Harden cli-test workflow against script injection
Use the $CLI_VERSION env var instead of interpolating ${{ matrix.version }} directly into the shell script, and validate the version string read from supported_cli_versions.json before using it to build the checkout ref. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: dc84e21b-6038-4939-b81a-7b477b0c9634
1 parent 4a396bf commit 91e1738

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/cli-test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,18 @@ jobs:
8989
id: choose-ref
9090
shell: bash
9191
run: |
92-
if [[ "${{ matrix.version }}" == "nightly" ]]
92+
if [[ "$CLI_VERSION" == "nightly" ]]
9393
then
9494
REF="codeql-cli/latest"
9595
else
96-
REF="codeql-cli/${{ matrix.version }}"
96+
# Validate the version read from supported_cli_versions.json before
97+
# using it, to guard against script injection from untrusted input.
98+
if [[ ! "$CLI_VERSION" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]
99+
then
100+
echo "Unexpected CLI version: '$CLI_VERSION'" >&2
101+
exit 1
102+
fi
103+
REF="codeql-cli/$CLI_VERSION"
97104
fi
98105
echo "ref=$REF" >> "$GITHUB_OUTPUT"
99106

0 commit comments

Comments
 (0)