Skip to content

Commit ccd344f

Browse files
authored
fix(ci): avoid branch-name command injection in image dispatch (#8513)
### Motivation - Prevent command injection and secret exfiltration risk when a labeled PR triggers the image-dispatch path by ensuring untrusted branch names are not interpolated directly into shell script bodies. ### Description - In the Azure Pipelines job, read the PR source branch from an environment variable `PR_SOURCE_BRANCH` instead of embedding `$(System.PullRequest.SourceBranch)` directly into the script, and normalize it by stripping the `refs/heads/` prefix with `BRANCH_NAME="${BRANCH_NAME#refs/heads/}"` before use. - Quote the `REF` assignment (`REF="$(Build.SourceBranch)"`) to avoid accidental word-splitting during parsing. - Expose `PR_SOURCE_BRANCH` via the job `env` so the pipeline consumes an env var rather than untrusted inline interpolation. - In the dispatched GitHub Actions workflow, stop embedding `�${{ github.event.inputs.branch_name }}` directly in the script and instead pass the input through a step `env` variable `BRANCH_NAME_INPUT` and then sanitize/normalize that variable in-shell before generating the `image_tag`. ### Testing - No automated tests were run for this change. ------ [Codex Task](https://chatgpt.com/codex/cloud/tasks/task_b_69e94906c8248327bc2843e43daeaef7)
1 parent a5f6d3d commit ccd344f

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)