Skip to content

Commit e57172b

Browse files
authored
Merge pull request #39 from MDA2AV/fix/pr-commands-shell-injection
fix: prevent shell injection in PR Commands workflow
2 parents 893cae5 + 7e8ea8f commit e57172b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

.github/workflows/pr-commands.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@ jobs:
2222
- name: Parse command
2323
id: parse
2424
run: |
25-
COMMENT="${{ github.event.comment.body }}"
26-
PR=${{ github.event.issue.number }}
25+
PR="$PR_NUMBER"
2726
echo "pr=$PR" >> "$GITHUB_OUTPUT"
2827
2928
# Detect changed frameworks from PR files via API (most reliable)
30-
FRAMEWORKS=$(gh api "/repos/${{ github.repository }}/pulls/$PR/files" --jq '.[].filename' | grep '^frameworks/' | cut -d'/' -f2 | sort -u | head -1)
29+
FRAMEWORKS=$(gh api "/repos/$REPO/pulls/$PR/files" --jq '.[].filename' | grep '^frameworks/' | cut -d'/' -f2 | sort -u | head -1)
3130
echo "framework=$FRAMEWORKS" >> "$GITHUB_OUTPUT"
3231
echo "Detected framework: $FRAMEWORKS"
3332
34-
if echo "$COMMENT" | grep -q '/benchmark'; then
33+
if echo "$COMMENT_BODY" | grep -q '/benchmark'; then
3534
echo "command=benchmark" >> "$GITHUB_OUTPUT"
3635
# Extract optional profile: /benchmark baseline
37-
PROFILE=$(echo "$COMMENT" | grep -oP '/benchmark\s+\K\S+' || echo "")
36+
PROFILE=$(echo "$COMMENT_BODY" | grep -oP '/benchmark\s+\K\S+' || echo "")
3837
echo "profile=$PROFILE" >> "$GITHUB_OUTPUT"
39-
elif echo "$COMMENT" | grep -q '/validate'; then
38+
elif echo "$COMMENT_BODY" | grep -q '/validate'; then
4039
echo "command=validate" >> "$GITHUB_OUTPUT"
4140
fi
4241
env:
4342
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
COMMENT_BODY: ${{ github.event.comment.body }}
44+
PR_NUMBER: ${{ github.event.issue.number }}
45+
REPO: ${{ github.repository }}
4446

4547
- name: React to comment
4648
run: |

0 commit comments

Comments
 (0)