Skip to content

Commit 385f412

Browse files
committed
Fix GitHub Actions template injection (CWE-78) in workflow shell commands
Move untrusted PR event data (title, head ref, base ref, SHAs) from inline ${{ }} interpolation in shell run: blocks to env: blocks, referencing them as shell variables instead. This prevents arbitrary code execution via crafted PR titles or branch names. Affected workflows: - test_smoke-starter.yml: PR title, user login, head SHA - publish-release.yml: PR head ref (branch name) - static_quality.yml: PR base ref, base SHA, head SHA
1 parent a7efb02 commit 385f412

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

.github/workflows/publish-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ jobs:
2626
steps:
2727
- name: Extract scope from branch
2828
id: meta
29+
env:
30+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
2931
run: |
30-
BRANCH="${{ github.event.pull_request.head.ref }}"
32+
BRANCH="${PR_HEAD_REF}"
3133
# Branch format: release/publish/<scope>/v<version>
3234
SCOPE=$(echo "$BRANCH" | sed 's|release/publish/\([^/]*\)/v.*|\1|')
3335
echo "scope=$SCOPE" >> $GITHUB_OUTPUT

.github/workflows/static_quality.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ jobs:
5959
- name: Collect PR-changed files for formatting
6060
if: github.event_name == 'pull_request'
6161
id: changed
62+
env:
63+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
6264
run: |
63-
base_ref="${{ github.event.pull_request.base.ref }}"
65+
base_ref="${PR_BASE_REF}"
6466
# Fetch the current tip of the base branch so the merge-base tracks
6567
# main as it advances (using the PR's stored base.sha would pull in
6668
# every file main has touched since the PR opened).
@@ -228,7 +230,10 @@ jobs:
228230
id: commitlint
229231
if: github.event_name == 'pull_request'
230232
continue-on-error: true
231-
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose 2>&1 | tee /tmp/commitlint-output.txt
233+
env:
234+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
235+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
236+
run: npx commitlint --from "${PR_BASE_SHA}" --to "${PR_HEAD_SHA}" --verbose 2>&1 | tee /tmp/commitlint-output.txt
232237

233238
- name: Post fix suggestion on failure
234239
if: github.event_name == 'pull_request' && steps.commitlint.outcome == 'failure'

.github/workflows/test_smoke-starter.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ jobs:
6161
if: failure()
6262
id: failure-cause
6363
working-directory: examples/integrations/${{ matrix.starter }}
64+
env:
65+
EVENT_NAME: ${{ github.event_name }}
66+
PR_NUMBER: ${{ github.event.pull_request.number }}
67+
PR_USER_LOGIN: ${{ github.event.pull_request.user.login }}
68+
PR_TITLE: ${{ github.event.pull_request.title }}
69+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
6470
run: |
6571
{
6672
echo "summary<<CAUSE_EOF"
@@ -86,10 +92,10 @@ jobs:
8692
echo ""
8793
8894
# Identify recent changes that may have caused the failure
89-
if [ "${{ github.event_name }}" = "pull_request" ]; then
90-
echo "Triggered by PR #${{ github.event.pull_request.number }} (${{ github.event.pull_request.user.login }}): ${{ github.event.pull_request.title }}"
91-
echo "Head: ${{ github.event.pull_request.head.sha }}"
92-
elif [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_run" ]; then
95+
if [ "$EVENT_NAME" = "pull_request" ]; then
96+
echo "Triggered by PR #${PR_NUMBER} (${PR_USER_LOGIN}): ${PR_TITLE}"
97+
echo "Head: ${PR_HEAD_SHA}"
98+
elif [ "$EVENT_NAME" = "schedule" ] || [ "$EVENT_NAME" = "workflow_run" ]; then
9399
# Use GitHub API instead of git log (avoids needing deep clone)
94100
echo "Recent commits touching this starter (last 12h):"
95101
gh api "repos/${{ github.repository }}/commits?path=examples/integrations/${{ matrix.starter }}&since=$(date -u -d '12 hours ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-12H +%Y-%m-%dT%H:%M:%SZ)&per_page=5" \

0 commit comments

Comments
 (0)