Skip to content

Commit 8380bed

Browse files
committed
fix(ci): avoid branch-name command injection in image dispatch
1 parent 276cb7d commit 8380bed

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

.azure-pipelines/ultimate-pipeline.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4320,7 +4320,7 @@ stages:
43204320
- checkout: none
43214321
- template: steps/create-github-app-token.yml
43224322
- bash: |
4323-
REF=$(Build.SourceBranch)
4323+
REF="$(Build.SourceBranch)"
43244324
BRANCH_NAME="latest_snapshot"
43254325
if [ "$(Build.Reason)" = "PullRequest" ]; then
43264326
LABELS=$(curl -s $(CURL_RETRY_FLAGS) \
@@ -4329,7 +4329,8 @@ stages:
43294329
| jq -r '.labels[].name')
43304330
43314331
if echo "$LABELS" | grep -q "docker_image_artifacts"; then
4332-
BRANCH_NAME="$(System.PullRequest.SourceBranch)"
4332+
BRANCH_NAME="$PR_SOURCE_BRANCH"
4333+
BRANCH_NAME="${BRANCH_NAME#refs/heads/}"
43334334
REF="refs/heads/$BRANCH_NAME"
43344335
else
43354336
echo "Label 'docker_image_artifacts' not found in PR — skipping Docker image build"
@@ -4358,6 +4359,7 @@ stages:
43584359
)
43594360
env:
43604361
GITHUB_TOKEN: $(retrieve_github_token.GITHUB_APP_TOKEN)
4362+
PR_SOURCE_BRANCH: $(System.PullRequest.SourceBranch)
43614363
43624364
- stage: coverage
43634365
condition: and(succeeded(), eq(variables['runCodeCoverage'], 'True'))

.github/workflows/create-system-test-docker-base-images.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ jobs:
5252
- name: "Sanitize branch name"
5353
id: image_tag
5454
run: |
55-
BRANCH="${{github.event.inputs.branch_name}}"
55+
BRANCH="$BRANCH_NAME_INPUT"
5656
if [[ -z "$BRANCH" ]]; then
5757
echo "ERROR: Missing required 'branch_name' input. Aborting docker image build."
5858
exit 1
5959
fi
6060
SAFE_TAG="${BRANCH//\//_}"
6161
echo "tag=$SAFE_TAG" >> $GITHUB_OUTPUT
62+
env:
63+
BRANCH_NAME_INPUT: "${{ github.event.inputs.branch_name }}"
6264

6365
- uses: ./.github/actions/create-system-test-docker-base-images
6466
name: 'Create system test docker images'

0 commit comments

Comments
 (0)