Skip to content

Commit e27b813

Browse files
authored
Merge pull request #21 from GREENRAT-K405/fix/injection-pr-review
fix shell/code injection vulnerability in pr-review.yaml
2 parents 7253102 + 2414437 commit e27b813

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

.github/workflows/PR-review.yaml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ jobs:
1717
contains(github.event.comment.body, '/gemini-review')
1818
steps:
1919
- name: PR Info
20+
env:
21+
#Assign untrusted inputs to environment variables first
22+
COMMENT_BODY: ${{ github.event.comment.body }}
23+
ISSUE_NUM: ${{ github.event.issue.number }}
24+
REPO: ${{ github.repository }}
25+
#Use shell variables ("$VAR") instead of template tags
2026
run: |
21-
echo "Comment: ${{ github.event.comment.body }}"
22-
echo "Issue Number: ${{ github.event.issue.number }}"
23-
echo "Repository: ${{ github.repository }}"
27+
echo "Comment: $COMMENT_BODY"
28+
echo "Issue Number: $ISSUE_NUM"
29+
echo "Repository: $REPO"
2430
2531
- name: Checkout Repo
2632
uses: actions/checkout@v3
@@ -30,17 +36,20 @@ jobs:
3036

3137
- name: Get PR Details
3238
id: pr
33-
run: |
34-
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})
35-
echo "head_sha=$(echo $PR_JSON | jq -r .head.sha)" >> $GITHUB_OUTPUT
36-
echo "base_sha=$(echo $PR_JSON | jq -r .base.sha)" >> $GITHUB_OUTPUT
3739
env:
3840
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
REPO: ${{ github.repository }}
42+
ISSUE_NUM: ${{ github.event.issue.number }}
43+
#Use env vars for the API call to prevent injection
44+
#Use quotes around variables to prevent word splitting
45+
run: |
46+
PR_JSON=$(gh api "repos/$REPO/pulls/$ISSUE_NUM")
47+
echo "head_sha=$(echo "$PR_JSON" | jq -r .head.sha)" >> $GITHUB_OUTPUT
48+
echo "base_sha=$(echo "$PR_JSON" | jq -r .base.sha)" >> $GITHUB_OUTPUT
3949
4050
- uses: truongnh1992/gemini-ai-code-reviewer@main
4151
with:
4252
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4353
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
4454
GEMINI_MODEL: gemini-2.5-flash
45-
EXCLUDE: "*.md,*.txt,package-lock.json"
46-
55+
EXCLUDE: "*.md,*.txt,package-lock.json"

0 commit comments

Comments
 (0)