Skip to content

Commit e69de0f

Browse files
committed
fix: prevent code injection in handle-fix-commit action
Resolve 6 medium-severity code injection alerts (CodeQL #107, #105, #104, #103, #102, #100) in .github/actions/handle-fix-commit/action.yaml by moving user inputs to environment variables before use in shell commands. This follows GitHub Security Lab best practices for preventing code injection in GitHub Actions workflows: https://securitylab.github.com/research/github-actions-untrusted-input/ Changes: - Added env: section mapping all user inputs to environment variables - Updated shell script to use $VAR syntax instead of ${{ inputs.X }} syntax - Properly quoted all variable references to prevent word splitting Inputs affected: - inputs.token → $TOKEN - inputs.tool → $TOOL - inputs.retry-attempts → $RETRY_ATTEMPTS - inputs.pr-info-ref → $PR_REF
1 parent c66e143 commit e69de0f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

.github/actions/handle-fix-commit/action.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ runs:
7777
id: commit_and_push
7878
shell: bash
7979
working-directory: ${{ inputs.working-directory }}
80+
env:
81+
TOOL: ${{ inputs.tool }}
82+
TOKEN: ${{ inputs.token }}
83+
PR_REF: ${{ inputs.pr-info-ref }}
84+
RETRY_ATTEMPTS: ${{ inputs.retry-attempts }}
8085
run: |
8186
git config --local user.name "github-actions[bot]"
8287
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
@@ -85,15 +90,15 @@ runs:
8590
rm -f ~/.git-credentials
8691
umask 077
8792
cat <<EOF > ~/.git-credentials
88-
https://x-access-token:${{ inputs.token }}@github.com
93+
https://x-access-token:$TOKEN@github.com
8994
EOF
9095
git config --local credential.helper 'store --file ~/.git-credentials'
9196
9297
git add -u
93-
git commit -m "Apply ${{ inputs.tool }} fixes"
98+
git commit -m "Apply $TOOL fixes"
9499
95-
for i in $(seq 1 ${{ inputs.retry-attempts }}); do
96-
if git push origin HEAD:${{ inputs.pr-info-ref }}; then
100+
for i in $(seq 1 "$RETRY_ATTEMPTS"); do
101+
if git push origin HEAD:"$PR_REF"; then
97102
echo "Push successful on attempt $i."
98103
COMMIT_SHA=$(git rev-parse HEAD)
99104
COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)
@@ -102,12 +107,12 @@ runs:
102107
echo "pushed=true" >> "$GITHUB_OUTPUT"
103108
exit 0
104109
fi
105-
if [ $i -eq ${{ inputs.retry-attempts }} ]; then
110+
if [ "$i" -eq "$RETRY_ATTEMPTS" ]; then
106111
break
107112
fi
108113
echo "Push failed on attempt $i. Fetching and rebasing before retry..."
109114
git fetch origin
110-
if ! git rebase origin/${{ inputs.pr-info-ref }}; then
115+
if ! git rebase origin/"$PR_REF"; then
111116
echo "::error::Automatic rebase failed. Please resolve conflicts manually."
112117
exit 1
113118
fi

0 commit comments

Comments
 (0)