Merge pull request #3106 from code-yeongyu/fix/prepublish-ci-injection

fix(ci): prevent shell injection in workflow expressions
This commit is contained in:
YeonGyu-Kim
2026-04-04 14:56:42 +09:00
committed by GitHub
2 changed files with 41 additions and 26 deletions
+12 -8
View File
@@ -17,8 +17,10 @@ jobs:
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
steps: steps:
- name: Check PR target branch - name: Check PR target branch
env:
BASE_REF: ${{ github.base_ref }}
run: | run: |
if [ "${{ github.base_ref }}" = "master" ]; then if [ "$BASE_REF" = "master" ]; then
echo "::error::PRs to master branch are not allowed. Please target the 'dev' branch instead." echo "::error::PRs to master branch are not allowed. Please target the 'dev' branch instead."
echo "" echo ""
echo "PULL REQUESTS TO MASTER ARE BLOCKED" echo "PULL REQUESTS TO MASTER ARE BLOCKED"
@@ -27,7 +29,7 @@ jobs:
echo "Please close this PR and create a new one targeting 'dev'." echo "Please close this PR and create a new one targeting 'dev'."
exit 1 exit 1
else else
echo "PR targets '${{ github.base_ref }}' branch - OK" echo "PR targets '${BASE_REF}' branch - OK"
fi fi
test: test:
@@ -132,6 +134,10 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create or update draft release - name: Create or update draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTES: ${{ steps.notes.outputs.notes }}
TARGET_SHA: ${{ github.sha }}
run: | run: |
EXISTING_DRAFT=$(gh release list --json tagName,isDraft --jq '.[] | select(.isDraft == true and .tagName == "next") | .tagName') EXISTING_DRAFT=$(gh release list --json tagName,isDraft --jq '.[] | select(.isDraft == true and .tagName == "next") | .tagName')
@@ -140,8 +146,8 @@ jobs:
gh release edit next \ gh release edit next \
--title "Upcoming Changes 🍿" \ --title "Upcoming Changes 🍿" \
--notes-file - \ --notes-file - \
--draft <<'EOF' --draft <<EOF
${{ steps.notes.outputs.notes }} $NOTES
EOF EOF
else else
echo "Creating new draft release..." echo "Creating new draft release..."
@@ -149,9 +155,7 @@ jobs:
--title "Upcoming Changes 🍿" \ --title "Upcoming Changes 🍿" \
--notes-file - \ --notes-file - \
--draft \ --draft \
--target ${{ github.sha }} <<'EOF' --target "$TARGET_SHA" <<EOF
${{ steps.notes.outputs.notes }} $NOTES
EOF EOF
fi fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+29 -18
View File
@@ -40,8 +40,10 @@ jobs:
# gh CLI auth as sisyphus-dev-ai # gh CLI auth as sisyphus-dev-ai
- name: Authenticate gh CLI as sisyphus-dev-ai - name: Authenticate gh CLI as sisyphus-dev-ai
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
run: | run: |
echo "${{ secrets.GH_PAT }}" | gh auth login --with-token echo "$GITHUB_TOKEN" | gh auth login --with-token
gh auth status gh auth status
- name: Ensure tmux is available (Linux) - name: Ensure tmux is available (Linux)
@@ -372,28 +374,33 @@ jobs:
if: steps.context.outputs.comment_id != '' if: steps.context.outputs.comment_id != ''
env: env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }} GITHUB_TOKEN: ${{ secrets.GH_PAT }}
REPOSITORY: ${{ github.repository }}
COMMENT_ID: ${{ steps.context.outputs.comment_id }}
run: | run: |
gh api "/repos/${{ github.repository }}/issues/comments/${{ steps.context.outputs.comment_id }}/reactions" \ gh api "/repos/${REPOSITORY}/issues/comments/${COMMENT_ID}/reactions" \
-X POST -f content="eyes" || true -X POST -f content="eyes" || true
- name: Add working label - name: Add working label
if: steps.context.outputs.number != '' if: steps.context.outputs.number != ''
env: env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }} GITHUB_TOKEN: ${{ secrets.GH_PAT }}
REPOSITORY: ${{ github.repository }}
CONTEXT_TYPE: ${{ steps.context.outputs.type }}
CONTEXT_NUMBER: ${{ steps.context.outputs.number }}
run: | run: |
gh label create "sisyphus: working" \ gh label create "sisyphus: working" \
--repo "${{ github.repository }}" \ --repo "$REPOSITORY" \
--color "fcf2e1" \ --color "fcf2e1" \
--description "Sisyphus is currently working on this" \ --description "Sisyphus is currently working on this" \
--force || true --force || true
if [[ "${{ steps.context.outputs.type }}" == "pr" ]]; then if [[ "$CONTEXT_TYPE" == "pr" ]]; then
gh pr edit "${{ steps.context.outputs.number }}" \ gh pr edit "$CONTEXT_NUMBER" \
--repo "${{ github.repository }}" \ --repo "$REPOSITORY" \
--add-label "sisyphus: working" || true --add-label "sisyphus: working" || true
else else
gh issue edit "${{ steps.context.outputs.number }}" \ gh issue edit "$CONTEXT_NUMBER" \
--repo "${{ github.repository }}" \ --repo "$REPOSITORY" \
--add-label "sisyphus: working" || true --add-label "sisyphus: working" || true
fi fi
@@ -514,26 +521,30 @@ jobs:
if: always() if: always()
env: env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }} GITHUB_TOKEN: ${{ secrets.GH_PAT }}
REPOSITORY: ${{ github.repository }}
COMMENT_ID: ${{ steps.context.outputs.comment_id }}
CONTEXT_NUMBER: ${{ steps.context.outputs.number }}
CONTEXT_TYPE: ${{ steps.context.outputs.type }}
run: | run: |
if [[ -n "${{ steps.context.outputs.comment_id }}" ]]; then if [[ -n "$COMMENT_ID" ]]; then
REACTION_ID=$(gh api "/repos/${{ github.repository }}/issues/comments/${{ steps.context.outputs.comment_id }}/reactions" \ REACTION_ID=$(gh api "/repos/${REPOSITORY}/issues/comments/${COMMENT_ID}/reactions" \
--jq '.[] | select(.content == "eyes" and .user.login == "sisyphus-dev-ai") | .id' | head -1) --jq '.[] | select(.content == "eyes" and .user.login == "sisyphus-dev-ai") | .id' | head -1)
if [[ -n "$REACTION_ID" ]]; then if [[ -n "$REACTION_ID" ]]; then
gh api -X DELETE "/repos/${{ github.repository }}/reactions/${REACTION_ID}" || true gh api -X DELETE "/repos/${REPOSITORY}/reactions/${REACTION_ID}" || true
fi fi
gh api "/repos/${{ github.repository }}/issues/comments/${{ steps.context.outputs.comment_id }}/reactions" \ gh api "/repos/${REPOSITORY}/issues/comments/${COMMENT_ID}/reactions" \
-X POST -f content="+1" || true -X POST -f content="+1" || true
fi fi
if [[ -n "${{ steps.context.outputs.number }}" ]]; then if [[ -n "$CONTEXT_NUMBER" ]]; then
if [[ "${{ steps.context.outputs.type }}" == "pr" ]]; then if [[ "$CONTEXT_TYPE" == "pr" ]]; then
gh pr edit "${{ steps.context.outputs.number }}" \ gh pr edit "$CONTEXT_NUMBER" \
--repo "${{ github.repository }}" \ --repo "$REPOSITORY" \
--remove-label "sisyphus: working" || true --remove-label "sisyphus: working" || true
else else
gh issue edit "${{ steps.context.outputs.number }}" \ gh issue edit "$CONTEXT_NUMBER" \
--repo "${{ github.repository }}" \ --repo "$REPOSITORY" \
--remove-label "sisyphus: working" || true --remove-label "sisyphus: working" || true
fi fi
fi fi