Skip to content

Commit 04bb0ef

Browse files
Fix command injection vulnerability in create-article-from-issue workflow
Pass all untrusted inputs (issue body, extracted outputs) through environment variables instead of direct ${{ }} interpolation in run blocks, preventing shell injection via crafted issue content.
1 parent 070604f commit 04bb0ef

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

.github/workflows/create-article-from-issue.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ jobs:
4949
5050
- name: Extract information from Issue
5151
id: extract
52+
env:
53+
ISSUE_BODY: ${{ github.event.issue.body }}
5254
run: |
53-
echo "${{ github.event.issue.body }}" > issue_body.txt
55+
echo "$ISSUE_BODY" > issue_body.txt
5456
5557
echo "Extracted issue body:"
5658
cat issue_body.txt
@@ -86,34 +88,43 @@ jobs:
8688
rm issue_body.txt
8789
8890
- name: Run the article generation script
91+
env:
92+
FILEID: ${{ steps.extract.outputs.fileid }}
93+
AUTHOR: ${{ steps.extract.outputs.author }}
94+
TAGS: ${{ steps.extract.outputs.tags }}
8995
run: |
9096
uv run python scripts/pandoc_google_doc.py \
91-
--fileid "${{ steps.extract.outputs.fileid }}" \
92-
--author "${{ steps.extract.outputs.author }}" \
93-
--tags "${{ steps.extract.outputs.tags }}"
97+
--fileid "$FILEID" \
98+
--author "$AUTHOR" \
99+
--tags "$TAGS"
94100
95101
- name: Commit and push generated article
102+
env:
103+
FILEID: ${{ steps.extract.outputs.fileid }}
96104
run: |
97105
git config user.name "github-actions[bot]"
98106
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
99107
100-
BRANCH="articles/${{ steps.extract.outputs.fileid }}"
108+
BRANCH="articles/$FILEID"
101109
git checkout -b "$BRANCH"
102110
103111
git add .
104-
git commit -m "Generated article from Google Doc ID: ${{ steps.extract.outputs.fileid }}"
112+
git commit -m "Generated article from Google Doc ID: $FILEID"
105113
git push origin "$BRANCH"
106114
107115
- name: Create Pull Request
108116
id: create_pr
109-
run: |
110-
gh pr create \
111-
--title "Article draft: ${{ steps.extract.outputs.title }}" \
112-
--body "This PR was automatically generated from issue #${{ github.event.issue.number }}. Closes #${{ github.event.issue.number }}" \
113-
--head "articles/${{ steps.extract.outputs.fileid }}" \
114-
--base main
115117
env:
116118
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
ARTICLE_TITLE: ${{ steps.extract.outputs.title }}
120+
FILEID: ${{ steps.extract.outputs.fileid }}
121+
ISSUE_NUMBER: ${{ github.event.issue.number }}
122+
run: |
123+
gh pr create \
124+
--title "Article draft: $ARTICLE_TITLE" \
125+
--body "This PR was automatically generated from issue #$ISSUE_NUMBER. Closes #$ISSUE_NUMBER" \
126+
--head "articles/$FILEID" \
127+
--base main
117128
- name: Comment on the original Issue
118129
uses: peter-evans/create-or-update-comment@v3
119130
with:

0 commit comments

Comments
 (0)