From 879c050cf31ef0db36f4275f5087b38364e92925 Mon Sep 17 00:00:00 2001 From: hieu-w Date: Wed, 2 Dec 2026 20:27:01 +0700 Subject: [PATCH 1/2] ci: keep the release-notes write token away from PR-supplied code Co-authored-by: Cursor --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a69ff584..538e34e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,10 @@ jobs: release-notes: if: github.event_name == 'pull_request' && !startsWith(github.head_ref, 'changeset-release/') permissions: - # contents: write pushes the automatic changeset created below. + # contents: write pushes the automatic changeset created below. The write + # token reaches only the "Commit changeset" step, which runs no + # PR-supplied code; the steps that execute the PR's lockfile (npm ci, + # npm exec, node) carry no token. contents: write runs-on: ubuntu-latest steps: @@ -98,13 +101,16 @@ jobs: - name: Install dependencies run: npm ci + # Untrusted step: it executes binaries from the PR's lockfile (npm exec, + # node), so it must not carry the job's write token. It only prepares + # the changeset and hands it to the token-holding step below. - name: Check release notes + id: changeset env: BASE_REF: ${{ github.base_ref }} HEAD_REF: ${{ github.head_ref }} PR_NUMBER: ${{ github.event.pull_request.number }} PR_TITLE: ${{ github.event.pull_request.title }} - GH_TOKEN: ${{ github.token }} run: | git fetch --no-tags origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}" # Dependabot subjects only; --no-merges skips GitHub's pull/N/merge test commits. @@ -143,10 +149,26 @@ jobs: git add "${changeset_path}" npm exec -- changeset status --since="origin/${BASE_REF}" - encoded_path="${changeset_path//\//%2F}" + { + echo "path=${changeset_path}" + echo "b64=$(base64 -w0 "${changeset_path}")" + } >> "${GITHUB_OUTPUT}" + + # Trusted step: it holds the job's write token, so it must run nothing + # from node_modules — only gh, a GitHub-hosted binary, and shell. + - name: Commit changeset + if: steps.changeset.outputs.path != '' + env: + HEAD_REF: ${{ github.head_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + GH_TOKEN: ${{ github.token }} + CHANGESET_PATH: ${{ steps.changeset.outputs.path }} + CHANGESET_B64: ${{ steps.changeset.outputs.b64 }} + run: | + encoded_path="${CHANGESET_PATH//\//%2F}" put_args=( -f message="chore: add patch changeset for Dependabot PR #${PR_NUMBER}" - -f content="$(base64 -w0 "${changeset_path}")" + -f content="${CHANGESET_B64}" -f branch="${HEAD_REF}" ) # The file already exists when a run is re-executed. @@ -154,8 +176,7 @@ jobs: put_args+=(-f sha="${file_sha}") fi gh api -X PUT "repos/${GITHUB_REPOSITORY}/contents/${encoded_path}" "${put_args[@]}" - echo "Created ${changeset_path} on ${HEAD_REF}" - + echo "Created ${CHANGESET_PATH} on ${HEAD_REF}" deploy-demo: name: deploy demo if: github.event_name == 'push' && github.ref == 'refs/heads/master' From ac0db2f59488b00d543422145673f0c180ad5d53 Mon Sep 17 00:00:00 2001 From: hieu-w Date: Thu, 3 Dec 2026 11:24:30 +0700 Subject: [PATCH 2/2] ci: run release-notes commit in a separate trusted job Step-level token isolation (PR #435) does not hold within one job: the untrusted step runs lockfile-provided binaries (npm ci install scripts, npm exec, node) that inherit GITHUB_OUTPUT and can rewrite GITHUB_PATH/GITHUB_ENV, so a hijacked dependency could forge the path/b64 outputs or capture the write token via the trusted step's gh execution and push arbitrary files. Split the release-notes job instead: - release-notes (untrusted, contents: read) runs npm ci / npm exec / node, then uploads the changeset via artifact and exports only a boolean flag. - release-notes-commit (trusted, contents: write) runs on a fresh runner, so PATH/ENV tampering from the untrusted job is gone. It recomputes the commit path from PR context and PUTs the downloaded artifact with gh. Addresses Bugbot finding 01d7c393 on PR #435. Co-authored-by: Cursor --- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 538e34e5..edf750ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,20 +73,28 @@ jobs: npm ci npm run build + # Untrusted job: it executes PR-supplied lockfile code (npm ci install + # scripts, npm exec, node) with only a read token. It never sees the write + # token, and because the token-holding job below runs on a fresh runner, + # GITHUB_PATH/GITHUB_ENV tampering here cannot capture it either. release-notes: if: github.event_name == 'pull_request' && !startsWith(github.head_ref, 'changeset-release/') permissions: - # contents: write pushes the automatic changeset created below. The write - # token reaches only the "Commit changeset" step, which runs no - # PR-supplied code; the steps that execute the PR's lockfile (npm ci, - # npm exec, node) carry no token. - contents: write + contents: read + outputs: + # Boolean flag only. A hijacked dependency could forge "true", but the + # worst case is the commit job below PUTting attacker-controlled bytes + # to the attacker's own PR branch — which the PR author can already do. + created: ${{ steps.changeset.outputs.created }} runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + # Keep the token out of .git/config, where PR-controlled install + # scripts could read it and push. The repository is public, so the + # git fetch below needs no credentials. persist-credentials: false - name: Use Node.js @@ -101,9 +109,6 @@ jobs: - name: Install dependencies run: npm ci - # Untrusted step: it executes binaries from the PR's lockfile (npm exec, - # node), so it must not carry the job's write token. It only prepares - # the changeset and hands it to the token-holding step below. - name: Check release notes id: changeset env: @@ -149,26 +154,49 @@ jobs: git add "${changeset_path}" npm exec -- changeset status --since="origin/${BASE_REF}" - { - echo "path=${changeset_path}" - echo "b64=$(base64 -w0 "${changeset_path}")" - } >> "${GITHUB_OUTPUT}" + echo "created=true" >> "${GITHUB_OUTPUT}" + + - name: Upload changeset + if: steps.changeset.outputs.created == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: changeset + path: .changeset/dependabot-${{ github.event.pull_request.number }}.md + if-no-files-found: error + retention-days: 1 + + # Trusted job: fresh runner, so PATH/ENV state from the untrusted job is + # gone. It holds the job's write token and runs no PR-supplied code — + # only GitHub-hosted actions, gh, and shell. The commit path is derived + # from PR context, not from the untrusted job's outputs. + release-notes-commit: + if: >- + github.event_name == 'pull_request' && + !startsWith(github.head_ref, 'changeset-release/') && + needs.release-notes.outputs.created == 'true' + needs: release-notes + permissions: + # contents: write pushes the automatic changeset created above. + contents: write + runs-on: ubuntu-latest + steps: + - name: Download changeset + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: changeset + path: changeset - # Trusted step: it holds the job's write token, so it must run nothing - # from node_modules — only gh, a GitHub-hosted binary, and shell. - name: Commit changeset - if: steps.changeset.outputs.path != '' env: HEAD_REF: ${{ github.head_ref }} PR_NUMBER: ${{ github.event.pull_request.number }} GH_TOKEN: ${{ github.token }} - CHANGESET_PATH: ${{ steps.changeset.outputs.path }} - CHANGESET_B64: ${{ steps.changeset.outputs.b64 }} run: | - encoded_path="${CHANGESET_PATH//\//%2F}" + changeset_path=".changeset/dependabot-${PR_NUMBER}.md" + encoded_path="${changeset_path//\//%2F}" put_args=( -f message="chore: add patch changeset for Dependabot PR #${PR_NUMBER}" - -f content="${CHANGESET_B64}" + -f content="$(base64 -w0 changeset/*.md)" -f branch="${HEAD_REF}" ) # The file already exists when a run is re-executed. @@ -176,7 +204,7 @@ jobs: put_args+=(-f sha="${file_sha}") fi gh api -X PUT "repos/${GITHUB_REPOSITORY}/contents/${encoded_path}" "${put_args[@]}" - echo "Created ${CHANGESET_PATH} on ${HEAD_REF}" + echo "Created ${changeset_path} on ${HEAD_REF}" deploy-demo: name: deploy demo if: github.event_name == 'push' && github.ref == 'refs/heads/master'