From 96235b28493dd356f670ad1ce52dc1bea552f687 Mon Sep 17 00:00:00 2001 From: Jonathan Miller <1+jmiller@noreply.git.mokoconsulting.tech> Date: Wed, 15 Jul 2026 03:25:58 +0000 Subject: [PATCH] fix(ci): harden issue-branch.yml against Actions injection (sync from Template-Generic) --- .mokogit/workflows/issue-branch.yml | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/.mokogit/workflows/issue-branch.yml b/.mokogit/workflows/issue-branch.yml index 7b56f28..e736ca8 100644 --- a/.mokogit/workflows/issue-branch.yml +++ b/.mokogit/workflows/issue-branch.yml @@ -3,9 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # FILE INFORMATION -# DEFGROUP: Git.Workflow -# INGROUP: mokocli.Automation -# VERSION: 01.00.37 +# DEFGROUP: MokoGIT.Workflow +# INGROUP: MokoCLI.Automation +# VERSION: 01.00.00 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" @@ -19,7 +19,7 @@ permissions: issues: write env: - GIT_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }} + MOKOGIT_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }} jobs: create-branch: @@ -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.GA_TOKEN }}" - API="${GIT_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="${GIT_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 \