Skip to content

Commit 92ea305

Browse files
authored
ci: fix shell injection via github.head_ref in auto-fixer (#2558)
## Bug \`pr-no-generated-changes.yml\` interpolated \`github.head_ref\` (the PR branch name, attacker-controlled) directly into a shell command: \`\`\`yaml git push origin HEAD:\${{ github.head_ref }} \`\`\` A PR opened with a branch name like \`;rm -rf /;\` (or anything containing shell metacharacters) would execute arbitrary commands inside the auto-fixer job. That job runs with the \`AUTOFIXER_APP_SECRET\` GitHub App credentials, which have write access to the repo — so this is a real privilege-escalation vector for any external contributor opening a PR. ## Fix Route \`github.head_ref\` and \`inputs.commit\` through env vars so the values are quoted shell data instead of inlined source: \`\`\`yaml env: HEAD_REF: \${{ github.head_ref }} COMMIT: \${{ inputs.commit }} run: | ... git push origin "HEAD:\$HEAD_REF" \`\`\` Standard mitigation per [GitHub's secure-use guide](https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks). ## Diff 1 file, +8/−3.
1 parent 69250d8 commit 92ea305

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

.github/workflows/pr-no-generated-changes.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,23 @@ jobs:
7676
run: make fmt
7777

7878
- name: Commit generated changes if any
79+
# head_ref is attacker-controlled (PR branch name); pass via env to avoid
80+
# shell injection in the inline script.
81+
env:
82+
HEAD_REF: ${{ github.head_ref }}
83+
COMMIT: ${{ inputs.commit }}
7984
run: |
8085
if [[ -z $(git status --porcelain) ]]; then
8186
echo "✅ No changes detected."
8287
exit 0
8388
fi
8489
85-
if [[ "${{ inputs.commit }}" != "true" ]]; then
90+
if [[ "$COMMIT" != "true" ]]; then
8691
echo "❌ Generated files are not up to date. Please run 'make generate' and commit the changes."
8792
git status --short
8893
exit 1
8994
fi
90-
95+
9196
echo "📝 Generated files are not up to date. Committing changes..."
9297
git status --short
9398
@@ -96,7 +101,7 @@ jobs:
96101
97102
git add -A
98103
git commit -m "chore: auto-commit generated changes"
99-
git push origin HEAD:${{ github.head_ref }}
104+
git push origin "HEAD:$HEAD_REF"
100105
101106
echo "✅ Changes committed and pushed successfully."
102107

0 commit comments

Comments
 (0)