From 4206b8aab1600ae037546c38410ff83dc0688486 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Sat, 11 Apr 2026 10:56:33 +0100 Subject: [PATCH] fix: prevent command injection in auto-publish workflow - Pass all user-controlled values via env vars instead of interpolating ${{ outputs.* }} into inline scripts - Fix operator precedence bug: entry.source || (owner && repo ? ...) - Use --body-file instead of heredocs with interpolated values - Quote all variable references in shell commands --- .github/workflows/auto-publish.yml | 76 +++++++++++++++++++----------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/.github/workflows/auto-publish.yml b/.github/workflows/auto-publish.yml index 30b35f96..cfe62632 100644 --- a/.github/workflows/auto-publish.yml +++ b/.github/workflows/auto-publish.yml @@ -65,7 +65,7 @@ jobs: return; } - const source = entry.source || entry.owner && entry.repo ? `${entry.owner}/${entry.repo}` : null; + const source = entry.source || (entry.owner && entry.repo ? `${entry.owner}/${entry.repo}` : null); const name = entry.name; const description = entry.description || ''; @@ -215,15 +215,20 @@ jobs: - name: Add source and commit if: steps.validate.outputs.status == 'pass' + env: + SKILL_SOURCE: ${{ steps.validate.outputs.source }} + SKILL_NAME: ${{ steps.validate.outputs.name }} + SKILL_DESCRIPTION: ${{ steps.validate.outputs.description }} + ISSUE_NUMBER: ${{ github.event.issue.number }} run: | node -e " const fs = require('fs'); const data = JSON.parse(fs.readFileSync('marketplace/sources.json', 'utf-8')); - const newEntry = { source: '${{ steps.validate.outputs.source }}', name: '${{ steps.validate.outputs.name }}' }; + const newEntry = { source: process.env.SKILL_SOURCE, name: process.env.SKILL_NAME }; - if ('${{ steps.validate.outputs.description }}') { - newEntry.description = '${{ steps.validate.outputs.description }}'; + if (process.env.SKILL_DESCRIPTION) { + newEntry.description = process.env.SKILL_DESCRIPTION; } const skillsSh = data.sources.pop(); @@ -239,66 +244,81 @@ jobs: git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add marketplace/sources.json - git commit -m "feat(marketplace): add source ${{ steps.validate.outputs.source }} from #${{ github.event.issue.number }}" + git commit -m "feat(marketplace): add source from #${ISSUE_NUMBER}" git push - name: Close issue on success if: steps.validate.outputs.status == 'pass' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SKILL_SOURCE: ${{ steps.validate.outputs.source }} + SKILL_NAME: ${{ steps.validate.outputs.name }} + SCAN_SUMMARY: ${{ steps.validate.outputs.scan_summary }} + QUALITY_SUMMARY: ${{ steps.validate.outputs.quality_summary }} + ISSUE_NUMBER: ${{ github.event.issue.number }} run: | - gh issue comment ${{ github.event.issue.number }} --body "$(cat <<'EOF' + cat > /tmp/comment.md < /tmp/comment.md < /tmp/comment.md <<'ENDOFCOMMENT' **Could not process skill submission.** - ${{ steps.validate.outputs.message }} + ENDOFCOMMENT + echo "${ERROR_MESSAGE}" >> /tmp/comment.md + cat >> /tmp/comment.md <<'ENDOFCOMMENT' **Expected format in issue body:** - \`\`\`json + ```json { "source": "owner/repo", "name": "Display Name", "description": "Optional description" } - \`\`\` + ``` Please update the issue body and re-apply the `skill-submission` label. - EOF - )" - gh issue edit ${{ github.event.issue.number }} --add-label "needs-review" + ENDOFCOMMENT + gh issue comment "${ISSUE_NUMBER}" --body-file /tmp/comment.md + gh issue edit "${ISSUE_NUMBER}" --add-label "needs-review"