Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/npm-package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
release:
# skip this job if the commit was created by this workflow (prevents infinite loop)
if: ${{ github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'NPM Package Release') }}
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'NPM Package Release')) }}
runs-on: ubuntu-latest
permissions:
id-token: write
Expand All @@ -31,6 +34,7 @@ jobs:
- uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.PUBLISH_PRIVATE_KEY }}
ref: ${{ github.head_ref || github.ref_name }}
# WASM builds require significant disk space; free up space to prevent build failures
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
Expand Down Expand Up @@ -154,12 +158,12 @@ jobs:
- name: Set Version
if: ${{ env.OLD_HASH != env.NEW_HASH }}
run: |
npm version prerelease --preid alpha --no-git-tag-version -w @rainlanguage/raindex
npm version prerelease --preid alpha --no-git-tag-version --no-workspaces-update -w @rainlanguage/raindex
RAINDEX_NEW_VERSION=$(jq -r '.version' ./packages/raindex/package.json)
echo "RAINDEX_NEW_VERSION=$RAINDEX_NEW_VERSION" >> $GITHUB_ENV
jq --arg v "$RAINDEX_NEW_VERSION" '.dependencies."@rainlanguage/raindex" = $v' ./packages/ui-components/package.json > tmp.json && mv tmp.json ./packages/ui-components/package.json
npx prettier --write ./packages/ui-components/package.json
npm version prerelease --preid alpha --no-git-tag-version -w @rainlanguage/ui-components
npm version prerelease --preid alpha --no-git-tag-version --no-workspaces-update -w @rainlanguage/ui-components
UC_NEW_VERSION=$(jq -r '.version' ./packages/ui-components/package.json)
echo "UC_NEW_VERSION=$UC_NEW_VERSION" >> $GITHUB_ENV
jq --indent 4 --arg rd "$RAINDEX_NEW_VERSION" --arg uc "$UC_NEW_VERSION" '
Expand Down Expand Up @@ -210,7 +214,7 @@ jobs:
- name: Push Changes To Remote
if: ${{ env.OLD_HASH != env.NEW_HASH }}
run: |
git push origin
git push origin HEAD:${{ github.head_ref || github.ref_name }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Template injection vulnerability in git push command.

github.head_ref is directly interpolated into the shell command, which zizmor correctly flags as a template injection risk. Although GitHub restricts many special characters in branch names and the workflow already blocks fork PRs, the recommended practice is to use an intermediate environment variable for proper shell escaping.

🛡️ Proposed fix using environment variable
     - name: Push Changes To Remote
       if: ${{ env.OLD_HASH != env.NEW_HASH }}
       run: |
-        git push origin HEAD:${{ github.head_ref || github.ref_name }}
+        git push origin "HEAD:${TARGET_REF}"
         git push -u origin "npm-raindex-v${{ env.RAINDEX_NEW_VERSION }}-uc-v${{ env.UC_NEW_VERSION }}"
       env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        TARGET_REF: ${{ github.head_ref || github.ref_name }}
🧰 Tools
🪛 zizmor (1.25.2)

[error] 217-217: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)


[error] 217-217: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/npm-package-release.yml at line 217, The git push line
interpolates github.head_ref directly into the shell which risks template
injection; fix it by assigning the branch expression to a workflow environment
variable (e.g., GIT_REF = ${{ github.head_ref || github.ref_name }}) and then
use a quoted env variable in the push command (git push origin HEAD:"$GIT_REF")
so the shell receives a single safely-escaped argument; update the workflow step
that contains git push origin HEAD:${{ github.head_ref || github.ref_name }} to
use the GIT_REF env var and ensure the push command uses double quotes around
$GIT_REF.

git push -u origin "npm-raindex-v${{ env.RAINDEX_NEW_VERSION }}-uc-v${{ env.UC_NEW_VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/npm-raindex-bootstrap-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Bootstrap raindex NPM Publish

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
publish:
if: ${{ github.head_ref == 'fix-raindex-npm-release-pr-trigger' || github.ref_name == 'fix-raindex-npm-release-pr-trigger' }}
runs-on: ubuntu-latest
permissions:
contents: read
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
swap-storage: false

- uses: DeterminateSystems/nix-installer-action@main
with:
determinate: true

- uses: DeterminateSystems/flakehub-cache-action@main

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24.x"
registry-url: "https://registry.npmjs.org"

- name: Verify npm token auth
run: npm whoami

- name: Install dependencies
run: ./prep-base.sh

- name: Build raindex package
run: nix develop -c npm run build -w @rainlanguage/raindex

- name: Publish raindex package
run: |
RAINDEX_VERSION=$(jq -r '.version' ./packages/raindex/package.json)
if npm view "@rainlanguage/raindex@${RAINDEX_VERSION}" version >/dev/null 2>&1; then
echo "@rainlanguage/raindex@${RAINDEX_VERSION} is already published"
exit 0
fi
npm publish -w @rainlanguage/raindex --access public --tag bootstrap --verbose
Loading