diff --git a/.mokogit/workflows/issue-branch.yml b/.mokogit/workflows/issue-branch.yml index da40381..e736ca8 100644 --- a/.mokogit/workflows/issue-branch.yml +++ b/.mokogit/workflows/issue-branch.yml @@ -27,14 +27,22 @@ jobs: runs-on: ubuntu-latest steps: - name: Create branch and comment + # SECURITY: never interpolate github.event.* into a run: script — the + # Actions engine splices the raw value into the shell source (command + # injection via a crafted issue title). Pass everything through env so + # the values arrive as ordinary shell variables that are not re-parsed. + env: + MOKOGIT_TOKEN: ${{ secrets.MOKOGIT_TOKEN }} + REPO: ${{ github.repository }} + ISSUE_NUM: ${{ github.event.issue.number }} + ISSUE_TITLE: ${{ github.event.issue.title }} run: | - TOKEN="${{ secrets.MOKOGIT_TOKEN }}" - API="${MOKOGIT_URL}/api/v1/repos/${{ github.repository }}" - ISSUE_NUM="${{ github.event.issue.number }}" - ISSUE_TITLE="${{ github.event.issue.title }}" + TOKEN="${MOKOGIT_TOKEN}" + API="${MOKOGIT_URL}/api/v1/repos/${REPO}" - # Build slug from title: lowercase, replace non-alnum with dash, trim - SLUG=$(echo "${ISSUE_TITLE}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//' | cut -c1-40) + # Build slug from title: lowercase, replace non-alnum with dash, trim. + # printf (not echo) so a title beginning with "-" is not read as flags. + SLUG=$(printf '%s' "${ISSUE_TITLE}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//' | cut -c1-40) BRANCH="feature/${ISSUE_NUM}-${SLUG}" # Check dev branch exists @@ -58,7 +66,7 @@ jobs: echo "Created branch: ${BRANCH}" # Comment on issue with branch link - REPO_URL="${MOKOGIT_URL}/${{ github.repository }}" + REPO_URL="${MOKOGIT_URL}/${REPO}" BODY="Branch created: [\`${BRANCH}\`](${REPO_URL}/src/branch/${BRANCH})\n\n\`\`\`bash\ngit fetch origin\ngit checkout ${BRANCH}\n\`\`\`" curl -sf -X POST \