Skip to content

Commit 05dff7c

Browse files
authored
Fix shell injection vulnerability in comment handling (#963)
Replace all `${{ inputs.* }}` interpolations inside `run:` scripts with environment variables passed via `env:` blocks, preventing shell interpretation of backticks, `$(...)`, and other metacharacters in user-supplied inputs. - Pass `comment` directly as an env var to the Close Issue step, eliminating the heredoc/delimiter pass-through via `GITHUB_OUTPUT` - Use a bash array (`comment_args`) to conditionally include `--comment` flag, avoiding unsafe string concatenation - Route `close-reason`, `labels`, `repository`, and `issue-number` through `env:` blocks in all steps for defense in depth - Quote variable references in label processing to handle whitespace
1 parent 1c7be94 commit 05dff7c

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

action.yml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,54 @@ runs:
2929
- name: Set parameters
3030
id: params
3131
shell: bash
32+
env:
33+
CLOSE_REASON: ${{ inputs.close-reason }}
34+
LABELS: ${{ inputs.labels }}
3235
run: |
33-
if [ -n "${{ inputs.comment }}" ]; then
34-
comment="--comment \"${{ inputs.comment }}\""
35-
delimiter="$(openssl rand -hex 8)"
36-
echo "comment<<$delimiter" >> $GITHUB_OUTPUT
37-
echo "$comment" >> $GITHUB_OUTPUT
38-
echo "$delimiter" >> $GITHUB_OUTPUT
39-
fi
40-
41-
if [ "${{ inputs.close-reason }}" == "not_planned" ]; then
36+
if [ "$CLOSE_REASON" == "not_planned" ]; then
4237
echo close-reason="not planned" >> $GITHUB_OUTPUT
4338
else
4439
echo close-reason="completed" >> $GITHUB_OUTPUT
4540
fi
4641
4742
# Convert labels to comma separated list
48-
if [ -n "${{ inputs.labels }}" ]; then
49-
labels=$(echo "${{ inputs.labels }}" | tr '\n' ',' | sed 's/,$//')
43+
if [ -n "$LABELS" ]; then
44+
labels=$(echo "$LABELS" | tr '\n' ',' | sed 's/,$//')
5045
# Remove trailing comma and whitespace
51-
labels=$(echo $labels | sed 's/,$//' | sed 's/[[:space:]]//g')
52-
echo labels=$labels >> $GITHUB_OUTPUT
46+
labels=$(echo "$labels" | sed 's/,$//' | sed 's/[[:space:]]//g')
47+
echo labels="$labels" >> $GITHUB_OUTPUT
5348
fi
5449
5550
- name: Close Issue
5651
shell: bash
57-
run: |
58-
gh issue close -R "${{ inputs.repository }}" \
59-
--reason "${{ steps.params.outputs.close-reason }}" \
60-
${{ steps.params.outputs.comment }} \
61-
"${{ inputs.issue-number }}"
6252
env:
6353
GH_TOKEN: ${{ inputs.token }}
54+
COMMENT: ${{ inputs.comment }}
55+
REPOSITORY: ${{ inputs.repository }}
56+
CLOSE_REASON: ${{ steps.params.outputs.close-reason }}
57+
ISSUE_NUMBER: ${{ inputs.issue-number }}
58+
run: |
59+
comment_args=()
60+
if [ -n "$COMMENT" ]; then
61+
comment_args=(--comment "$COMMENT")
62+
fi
63+
gh issue close -R "$REPOSITORY" \
64+
--reason "$CLOSE_REASON" \
65+
"${comment_args[@]}" \
66+
"$ISSUE_NUMBER"
6467
6568
- name: Add Labels
6669
if: steps.params.outputs.labels != ''
6770
shell: bash
68-
run: |
69-
gh issue edit -R "${{ inputs.repository }}" \
70-
--add-label "${{ steps.params.outputs.labels }}" \
71-
"${{ inputs.issue-number }}"
7271
env:
7372
GH_TOKEN: ${{ inputs.token }}
73+
REPOSITORY: ${{ inputs.repository }}
74+
LABELS: ${{ steps.params.outputs.labels }}
75+
ISSUE_NUMBER: ${{ inputs.issue-number }}
76+
run: |
77+
gh issue edit -R "$REPOSITORY" \
78+
--add-label "$LABELS" \
79+
"$ISSUE_NUMBER"
7480
7581
branding:
7682
icon: 'git-pull-request'

0 commit comments

Comments
 (0)