fix(ci): pass workflow_run head_branch through env; read-only tokens

auto-merge.yml interpolated ${{ github.event.workflow_run.head_branch }} straight into a run script that holds a contents:write token. A fork pull request controls that branch name, so it could run commands with write access (CodeQL actions/code-injection/critical). It now arrives as an environment variable.

ci.yml, code-quality.yml and deploy.yml get permissions: contents: read; none of them writes through GITHUB_TOKEN.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-20 22:07:02 +04:00
1 parent cb25e08547
commit 07facbdda2
4 files changed
+18 -1

No files matched your search

+3 -1
View File
@@ -18,8 +18,10 @@ jobs:
- name: Find and merge master → main PR - name: Find and merge master → main PR
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Through the environment, never interpolated into the script: a fork's
# branch name is attacker-chosen and would run with this job's write token.
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: | run: |
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}"
echo "Workflow ran on branch: $HEAD_BRANCH" echo "Workflow ran on branch: $HEAD_BRANCH"
if [ "$HEAD_BRANCH" != "master" ]; then if [ "$HEAD_BRANCH" != "master" ]; then
+5
View File
@@ -6,6 +6,11 @@ on:
pull_request: pull_request:
branches: [main] branches: [main]
# Read-only token: these jobs never write through GITHUB_TOKEN.
permissions:
contents: read
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+5
View File
@@ -6,6 +6,11 @@ on:
pull_request: pull_request:
branches: [main] branches: [main]
# Read-only token: these jobs never write through GITHUB_TOKEN.
permissions:
contents: read
jobs: jobs:
lint: lint:
name: ESLint name: ESLint
+5
View File
@@ -18,6 +18,11 @@ on:
env: env:
SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }} SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }}
# Read-only token: these jobs never write through GITHUB_TOKEN.
permissions:
contents: read
jobs: jobs:
deploy-pezkuwi: deploy-pezkuwi:
if: ${{ github.event_name == 'release' || github.event.inputs.project == 'all' || github.event.inputs.project == 'pezkuwi' }} if: ${{ github.event_name == 'release' || github.event.inputs.project == 'all' || github.event.inputs.project == 'pezkuwi' }}