:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): block publish jobs that a pull request can reach (#104860)
Tom Piccirelloeb1b5c80ccab
diff --git a/.github/workflows/ci-security.yaml b/.github/workflows/ci-security.yamlindex 4cabaeca62cc..b320834e911f 100644--- a/.github/workflows/ci-security.yaml+++ b/.github/workflows/ci-security.yaml@@ -362,6 +362,11 @@ jobs:uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2# exclude all directories already scanned by other jobs+ #+ # This job is the only one that scans .github/, so a workflow rule in+ # .semgrep/rules/security/ gates nothing until it is named here. The jobs+ # that load that whole directory restrict their targets to trees that hold+ # no workflow file.- name: Run Semgrepuses: ./.github/actions/semgrep-ciwith:@@ -371,6 +376,7 @@ jobs:--config p/security-audit--config p/trailofbits--config p/github-actions+ --config .semgrep/rules/security/github-actions-publish-on-pull-request.yaml--exclude-rule dockerfile.security.no-sudo-in-dockerfile.no-sudo-in-dockerfile--exclude-rule trailofbits.generic.redis-unencrypted-transport.redis-unencrypted-transport--exclude-rule trailofbits.yaml.docker-compose.port-all-interfaces.port-all-interfaces@@ -506,6 +512,18 @@ jobs:${{ env.SEMGREP_IMAGE }} \semgrep --test .semgrep/+ # semgrep-general runs `semgrep ci`, which drops every match that the merge-base+ # copy of a file also has. A rule-only change leaves every workflow unchanged, so+ # that scan cannot report what the edited rule now matches. This full scan can.+ - name: Scan workflows with the workflow rules+ run: |+ docker run --rm -v "${{ github.workspace }}:/src" -w /src \+ -e SEMGREP_ENABLE_VERSION_CHECK=false \+ ${{ env.SEMGREP_IMAGE }} \+ semgrep scan --error --metrics=off --timeout 300 \+ --config .semgrep/rules/security/github-actions-publish-on-pull-request.yaml \+ .github/workflows/+# products/desktop is an imported standalone app that does not follow the monorepo's# semgrep *convention* rules (.semgrep custom rules, devex), so those jobs exclude it.# This job gives its TS/Python real static security coverage from the universal registrydiff --git a/.semgrep/rules/security/github-actions-publish-on-pull-request.test.yaml b/.semgrep/rules/security/github-actions-publish-on-pull-request.test.yamlnew file mode 100644index 000000000000..f3bb43394248--- /dev/null+++ b/.semgrep/rules/security/github-actions-publish-on-pull-request.test.yaml@@ -0,0 +1,550 @@+# Multi-document file: each `---` section is a separate workflow, so one file+# can carry both PR-triggered and tag-triggered shapes.+name: Version check as the only gate+on:+ push:+ branches:+ - master+ pull_request:+ paths-ignore:+ - rust/**++jobs:+ hog-tests:+ runs-on: ubuntu-24.04+ outputs:+ is-new-version: ${{ steps.check.outputs.is-new-version }}+ steps:+ - run: echo build++ release-package:+ name: Release a new package version+ runs-on: ubuntu-24.04+ needs: hog-tests+ # Only gate is a version check, so a pull request run reaches the publish step.+ if: needs.hog-tests.outputs.is-new-version == 'true'+ steps:+ - name: Mint a token+ # A step-level event check does not gate the publish step below it.+ if: github.event_name != 'pull_request'+ uses: actions/create-github-app-token@v3+ - name: Publish the package in the npm registry+ # ruleid: github-actions-publish-on-pull-request+ run: cd packages/example && npm publish --access public+---+name: Ungated jobs with no if at all+on: [push, pull_request]++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-pypi:+ runs-on: ubuntu-24.04+ environment: pypi-thing+ steps:+ # An `environment:` alone is not an event or ref gate.+ # ruleid: github-actions-publish-on-pull-request+ - uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0++ publish-crate:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-data++ cut-release-with-an-archived-action:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - uses: actions/create-release@v1+ # ruleid: github-actions-publish-on-pull-request+ - uses: actions/upload-release-asset@v1++ cut-release:+ runs-on: ubuntu-24.04+ steps:+ - name: Cut a GitHub release+ # ruleid: github-actions-publish-on-pull-request+ run: |+ gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \+ --title "$TAG" dist/*++ publish-draft-release:+ runs-on: ubuntu-24.04+ steps:+ - name: Make an existing draft release public+ # ruleid: github-actions-publish-on-pull-request+ run: gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false++ dry-run-then-publish:+ runs-on: ubuntu-24.04+ steps:+ # The second command ships the package, so the block stays flagged.+ # ruleid: github-actions-publish-on-pull-request+ - run: |+ npm publish \+ --dry-run+ npm publish --access public++ publish-then-echo-dry-run:+ runs-on: ubuntu-24.04+ steps:+ # A `--dry-run` after a shell operator belongs to another command.+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public && echo --dry-run++ sync-release-across-a-continuation:+ runs-on: ubuntu-24.04+ steps:+ # A shell continuation keeps the release destination inside the same command.+ # ruleid: github-actions-publish-on-pull-request+ - run: |+ aws s3 sync dist/ \+ s3://public-release-bucket/releases/++ publish-with-a-split-command-word:+ runs-on: ubuntu-24.04+ steps:+ # A shell continuation between command words still runs one command.+ # ruleid: github-actions-publish-on-pull-request+ - run: |+ npm \+ publish --access public++ release-with-a-split-command-word:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: |+ gh release \+ create "$TAG" dist/*++ publish-with-global-options:+ runs-on: ubuntu-24.04+ steps:+ # Options between the tool and the subcommand still run a publish.+ # ruleid: github-actions-publish-on-pull-request+ - run: pnpm --filter=@posthog/example publish --access public+ # ruleid: github-actions-publish-on-pull-request+ - run: pnpm --filter @posthog/example publish --access public+ # ruleid: github-actions-publish-on-pull-request+ - run: npm --prefix packages/example publish+ # ruleid: github-actions-publish-on-pull-request+ - run: pnpm -r publish+ # ruleid: github-actions-publish-on-pull-request+ - run: yarn workspace @posthog/example publish+ # ruleid: github-actions-publish-on-pull-request+ - run: poetry -C packages/example publish++ publish-with-dry-run-false:+ runs-on: ubuntu-24.04+ steps:+ # npm reads `--dry-run=false` as a real publish.+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --dry-run=false++ upload-to-a-release-bucket:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: aws s3 cp ./dist/pkg.tgz s3://example-release-bucket/+---+name: Fixed shape - dispatch plus master gate+on:+ pull_request:+ paths:+ - common/hogql_parser/**+ workflow_dispatch:++jobs:+ build-wasm:+ runs-on: ubuntu-24.04+ steps:+ # Build-only validation on a pull request. No publish command.+ # ok: github-actions-publish-on-pull-request+ - run: cd common/hogql_parser && npm run build++ publish-npm:+ name: Publish on npm+ needs: build-wasm+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master' && github.repository == 'PostHog/posthog'+ environment: npm-hogql-parser+ runs-on: ubuntu-24.04+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: cd common/hogql_parser && npm publish --access public++ publish-pypi:+ needs: build-wasm+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master' && github.repository == 'PostHog/posthog'+ environment: pypi-hogql-parser+ runs-on: ubuntu-24.04+ steps:+ # ok: github-actions-publish-on-pull-request+ - uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0+---+name: Fixed shape - push event gate and ref gate+on:+ pull_request: {}+ push:+ branches:+ - master++jobs:+ publish-crate:+ runs-on: ubuntu-24.04+ if: github.event_name == 'push' && github.repository == 'PostHog/posthog'+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ release-skills:+ runs-on: ubuntu-24.04+ if: github.repository_owner == 'PostHog' && github.ref == 'refs/heads/master'+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: gh release create "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" dist/*++ validate-only:+ runs-on: ubuntu-24.04+ steps:+ # A dry run ships nothing.+ # ok: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-data --dry-run++ validate-only-across-a-continuation:+ runs-on: ubuntu-24.04+ steps:+ # A shell continuation keeps `--dry-run` inside the same command.+ # ok: github-actions-publish-on-pull-request+ - run: |+ npm publish \+ --dry-run++ validate-only-with-a-split-command-word:+ runs-on: ubuntu-24.04+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: |+ cargo \+ publish --dry-run++ validate-only-with-dry-run-true:+ runs-on: ubuntu-24.04+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: npm publish --dry-run=true++ build-that-disables-publishing:+ runs-on: ubuntu-24.04+ steps:+ # `--publish` is a flag of the build tool here, not a publish subcommand.+ # ok: github-actions-publish-on-pull-request+ - run: pnpm exec electron-builder build --mac --publish never++ download-from-a-release-bucket:+ runs-on: ubuntu-24.04+ steps:+ # A copy from S3 to the runner downloads and publishes nothing.+ # ok: github-actions-publish-on-pull-request+ - run: aws s3 cp s3://example-release-bucket/pkg.tgz ./pkg.tgz++ publish-crate-behind-a-variable:+ runs-on: ubuntu-24.04+ # A string compare such as `== 'true'` tests a value, not a clause's result.+ if: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.CRATE_PUBLISH_ENABLED == 'true'+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ gate-declared-after-steps:+ runs-on: ubuntu-24.04+ steps:+ # The gate still counts when the author writes `if:` below `steps:`.+ # ok: github-actions-publish-on-pull-request+ - run: npm publish --access public+ if: github.event_name == 'push' && github.ref == 'refs/heads/master'+---+name: Tag-triggered publisher+on:+ push:+ tags:+ - 'hogli-v*'+ workflow_dispatch:++jobs:+ publish:+ runs-on: ubuntu-24.04+ if: startsWith(github.ref, 'refs/tags/hogli-v')+ environment: pypi-hogli+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: uv publish dist/*.whl+---+name: Manual-run-only publisher+on:+ workflow_dispatch:+ inputs:+ tag:+ required: true++jobs:+ publish:+ runs-on: ubuntu-24.04+ environment: Release+ steps:+ # No pull request trigger, so nothing to gate against here.+ # ok: github-actions-publish-on-pull-request+ - run: npm publish "$TARBALL" --tag "$NPM_TAG" --access public+---+name: Compound gate that still admits a pull request+on:+ push:+ branches:+ - master+ pull_request:+ paths-ignore:+ - docs/**++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ # One arm of an alternation can admit a pull request, and a regex cannot+ # decompose an alternation, so any `||` in the gate counts as no gate.+ if: github.event_name == 'push' || github.event_name == 'pull_request'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-crate:+ runs-on: ubuntu-24.04+ # `!` inverts the clause it wraps, so the job runs on every other event.+ if: ${{ !(github.event_name == 'push') }}+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-data++ publish-pypi:+ runs-on: ubuntu-24.04+ # A comparison on a clause's result inverts it the same way `!` does.+ if: ${{ (github.event_name == 'push') == false }}+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: twine upload dist/*++ publish-crate-on-a-chained-comparison:+ runs-on: ubuntu-24.04+ if: github.event_name == 'push' == false+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ publish-crate-on-a-reversed-comparison:+ runs-on: ubuntu-24.04+ if: false == (github.event_name == 'push')+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ publish-npm-on-a-pull-request-ref:+ runs-on: ubuntu-24.04+ # `refs/pull/` is where a pull request run's own ref lives.+ if: startsWith(github.ref, 'refs/pull/')+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public+---+name: Publishers gated on an event that a pull request can start+on:+ push:+ branches:+ - master+ pull_request: {}+ merge_group:+ workflow_run:+ workflows:+ - Build+ types:+ - completed++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ # A merge queue run holds the queued pull request merged onto the base, before+ # it lands. The queue can still reject it, so the version would describe code+ # that never reaches master.+ if: github.event_name == 'merge_group'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-pypi:+ runs-on: ubuntu-24.04+ # An inequality admits every other event, the merge queue included.+ if: github.event_name != 'pull_request'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: twine upload dist/*++ publish-crate:+ runs-on: ubuntu-24.04+ # A pull request run of the upstream workflow can trigger `workflow_run`.+ if: github.event_name == 'workflow_run'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-data+---+name: pull_request_target publisher+on:+ merge_group:+ pull_request_target:+ types:+ - opened+ - synchronize+ workflow_dispatch:++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ # `github.ref` names the base branch on a `pull_request_target` run, so it reads+ # `refs/heads/master` while a pull request runs. A ref pin gates nothing here.+ if: github.ref == 'refs/heads/master'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-pypi:+ runs-on: ubuntu-24.04+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: twine upload dist/*++ publish-crate-on-a-ref-prefix:+ runs-on: ubuntu-24.04+ # The other two ref forms read the base branch here as well.+ if: startsWith(github.ref, 'refs/heads/')+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ publish-crate:+ runs-on: ubuntu-24.04+ # An event pin is the one gate that holds for `pull_request_target`.+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-data++ publish-crate-on-a-negated-pin:+ runs-on: ubuntu-24.04+ if: ${{ !(github.event_name == 'workflow_dispatch') }}+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ publish-npm-on-the-merge-queue:+ runs-on: ubuntu-24.04+ if: github.event_name == 'merge_group'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-crate-on-a-compared-pin:+ runs-on: ubuntu-24.04+ if: ${{ (github.event_name == 'workflow_dispatch') == false }}+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-replay-anonymizer++ publish-npm-on-workflow-run:+ runs-on: ubuntu-24.04+ if: github.event_name == 'workflow_run'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-pypi-on-an-inequality:+ runs-on: ubuntu-24.04+ if: github.event_name != 'pull_request_target'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: twine upload dist/*+---+name: Review-triggered publisher+on: [pull_request_review]++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ # A review runs the pull request's merge ref, so an approval gates nothing.+ if: github.event.review.state == 'approved'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public+---+name: Review-comment-triggered publisher+on: pull_request_review_comment++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ if: github.event.comment.body == '/publish'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public+---+name: Quoted trigger key+'on':+ pull_request:++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ if: github.event.pull_request.draft == false+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public+---+name: Quoted pull_request_target trigger key+'on': pull_request_target++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ if: github.ref == 'refs/heads/master'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public+---+name: Both pull request triggers+on:+ pull_request:+ pull_request_target:+ workflow_dispatch:++jobs:+ publish-npm:+ runs-on: ubuntu-24.04+ # Each clause excludes only one of the two pull request events.+ if: github.event_name != 'pull_request_target'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: npm publish --access public++ publish-pypi:+ runs-on: ubuntu-24.04+ if: github.event_name != 'pull_request'+ steps:+ # ruleid: github-actions-publish-on-pull-request+ - run: twine upload dist/*++ publish-crate:+ runs-on: ubuntu-24.04+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'+ steps:+ # ok: github-actions-publish-on-pull-request+ - run: cargo publish -p posthog-symbol-datadiff --git a/.semgrep/rules/security/github-actions-publish-on-pull-request.yaml b/.semgrep/rules/security/github-actions-publish-on-pull-request.yamlnew file mode 100644index 000000000000..8911c9bc9e53--- /dev/null+++ b/.semgrep/rules/security/github-actions-publish-on-pull-request.yaml@@ -0,0 +1,221 @@+# Flags a job that publishes a package to a public registry in a workflow that+# a pull request event can trigger, when nothing in the job's `if:` pins the run+# to a non-PR event or to a branch/tag ref. The pull request events are+# `pull_request`, `pull_request_target`, `pull_request_review` and+# `pull_request_review_comment`.+#+# A `pull_request` run checks out code the PR author controls. If a publish step+# reaches it, anyone who can open a PR can push a release version of+# an npm package such as `hogql-parser`, a crate, or a GitHub release to the public+# and burn a version number that no later commit can take back. The registry+# credential is exposed on the same run.+#+# Fix: keep `pull_request` for build-only validation, add `workflow_dispatch`,+# and gate the publish job on the event plus the ref:+#+# publish:+# if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master' && github.repository == 'PostHog/posthog'+# environment: npm-<package>+#+# The gate must be an `&&` chain. A `||` anywhere in the job `if:` counts as no+# gate, because one arm of an alternation can admit a pull request and a regex+# cannot decompose an alternation. Give each event its own job when two events+# must reach a publish. A `!` outside `!=` counts as no gate too, because it can+# invert an accepted clause. A comparison on a clause's result, such as+# `(...) == false`, counts as no gate for the same reason. A `merge_group` pin+# counts as no gate either: the merge queue runs the queued pull request before+# it lands, and the queue can still reject it afterwards. A `workflow_run` pin+# counts as no gate, because a pull request run of the upstream workflow can+# trigger it. An inequality such as `!= 'pull_request'` counts as no gate,+# because it admits every other event, `merge_group` and `workflow_run` included.+#+# `pull_request_target` sets `github.ref` to the base branch, so `refs/heads/master`+# reads true while a pull request runs. Pin the event in those workflows.+#+# `.github/workflows/build-hogql-parser-npm.yml` is the reference shape.+rules:+ - id: github-actions-publish-on-pull-request+ languages:+ - yaml+ message: |+ This job publishes to a public registry, and a pull request can trigger the workflow it+ lives in. Nothing in the job's `if:` holds a pull request run back, so that run reaches the+ publish step with PR-author-controlled code and the registry credential in scope. A version+ published this way is public forever; no later commit retracts it.++ Fix: keep the pull request trigger for build-only validation, add `workflow_dispatch`, and+ gate the publish job on both the event and the ref.++ publish:+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master' && github.repository == 'PostHog/posthog'+ environment: npm-<package>++ These shapes count as no gate too. A `||` anywhere in the job `if:` does, because one arm+ of an alternation can admit a pull request. A `!` outside `!=` does, because it can invert+ an accepted clause, and so does a comparison on a clause's result, such as `(...) == false`.+ A `merge_group` pin does, because the merge queue runs the queued pull request before it+ lands. A `workflow_run` pin does, because a pull request run of the upstream workflow can+ trigger it. An inequality such as `github.event_name != 'pull_request'` does, because it+ admits every other event. A ref pin does in a `pull_request_target`+ workflow, because `github.ref` names the base branch there and reads `refs/heads/master`+ while a pull request runs.++ `.github/workflows/build-hogql-parser-npm.yml` is the reference shape.+ metadata:+ category: security+ cwe:+ - 'CWE-284: Improper Access Control'+ owasp:+ - A01:2021 - Broken Access Control+ references:+ - https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/control-jobs#using-a-specific-environment+ - https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/+ technology:+ - github-actions+ subcategory:+ - vuln+ likelihood: MEDIUM+ impact: HIGH+ confidence: MEDIUM+ paths:+ include:+ - '**/.github/workflows/*.yml'+ - '**/.github/workflows/*.yaml'+ patterns:+ # 1. The workflow can run on a pull request. Anchored on the whole document+ # mapping (trailing `...`), so a job anywhere in the file counts as inside it.+ # The trigger key is a metavariable so that a quoted `"on":` matches too. Some+ # authors quote it, because YAML 1.1 reads a bare `on` as the boolean `true`.+ - pattern-either:+ - pattern-inside: |+ $ON:+ ...+ $EVENT: ...+ ...+ ...+ - pattern-inside: |+ $ON: [..., $EVENT, ...]+ ...+ - pattern-inside: |+ $ON: $EVENT+ ...+ - metavariable-regex:+ metavariable: $ON+ regex: ^["']?on["']?$+ - metavariable-regex:+ metavariable: $EVENT+ regex: ^pull_request(?:_target|_review|_review_comment)?$+ # 2. The job holding this step is ungated. `$GATE` binds the job-level `if:`+ # scalar only, never a step-level one. Which clauses count as a gate depends+ # on the `github.ref` the trigger sets, so `pull_request_target` gets its own arm.+ - pattern-either:+ # The job declares no `if:` at all.+ - patterns:+ - pattern-inside: |+ $JOB:+ ...+ steps: ...+ ...+ - pattern-not-inside: |+ $JOB_WITH_IF:+ ...+ if: $ANY+ ...+ steps: ...+ ...+ # `pull_request` and the two review events set `github.ref` to+ # `refs/pull/<number>/merge`, so a branch or tag pin excludes their runs and+ # counts as a gate.+ - patterns:+ - pattern-either:+ - pattern-inside: |+ $PR_ON:+ ...+ $PR_EVENT: ...+ ...+ ...+ - pattern-inside: |+ $PR_ON: [..., $PR_EVENT, ...]+ ...+ - pattern-inside: |+ $PR_ON: $PR_EVENT+ ...+ - metavariable-regex:+ metavariable: $PR_ON+ regex: ^["']?on["']?$+ - metavariable-regex:+ metavariable: $PR_EVENT+ regex: ^pull_request(?:_review|_review_comment)?$+ - pattern-inside: |+ $JOB:+ ...+ if: $GATE+ ...+ steps: ...+ ...+ - metavariable-regex:+ metavariable: $GATE+ # (?s) so a folded multi-line `if:` is one subject. The job is+ # ungated when no clause pins the event to a trusted release one,+ # or the ref to a branch or tag. An inequality such as+ # `!= 'pull_request'` is no pin, because it admits every other event,+ # `merge_group` and `workflow_run` included. `merge_group` is not a trusted+ # release event, because the queue run holds the pull request+ # merged onto the base before it lands. `workflow_run` is not one+ # either, because a pull request run of the upstream workflow can+ # trigger it. A `||` counts as no gate too, because one arm of an+ # alternation can admit a pull request and a regex cannot decompose+ # an alternation. A `!` outside `!=` counts as no gate for the same+ # reason: it can invert an accepted clause. So can a comparison on+ # a clause's result, such as `(...) == false` or `... == 'push' == false`.+ regex: "(?s)^(?:(?!.*(?:github\\.event_name\\s*==\\s*'(?:push|workflow_dispatch|release|schedule)'|github\\.ref\\s*==\\s*'refs/(?:heads|tags)/|github\\.ref_name\\s*==\\s*'|startsWith\\(\\s*github\\.ref\\s*,\\s*'refs/(?:heads|tags)/))|(?=.*(?:\\|\\||!(?!=)|\\)\\s*[=!]=|[=!]=\\s*\\(|'\\s*[=!]=))).*$"+ # `pull_request_target` sets `github.ref` to the base branch, so a branch pin+ # reads true while a pull request runs. An event pin is the only gate here.+ - patterns:+ - pattern-either:+ - pattern-inside: |+ $PRT_ON:+ ...+ pull_request_target: ...+ ...+ ...+ - pattern-inside: |+ $PRT_ON: [..., pull_request_target, ...]+ ...+ - pattern-inside: |+ $PRT_ON: pull_request_target+ ...+ - metavariable-regex:+ metavariable: $PRT_ON+ regex: ^["']?on["']?$+ - pattern-inside: |+ $JOB:+ ...+ if: $GATE+ ...+ steps: ...+ ...+ - metavariable-regex:+ metavariable: $GATE+ regex: "(?s)^(?:(?!.*(?:github\\.event_name\\s*==\\s*'(?:push|workflow_dispatch|release|schedule)'))|(?=.*(?:\\|\\||!(?!=)|\\)\\s*[=!]=|[=!]=\\s*\\(|'\\s*[=!]=))).*$"+ # 3. The step publishes. A `--dry-run` invocation validates without shipping. The+ # guard follows a shell line continuation, so a dry run that wraps onto the next+ # line stays exempt while a real publish on a line of its own does not. It stops+ # at a shell operator or comment, where the `--dry-run` belongs to another command.+ # `--dry-run=false` publishes, so only a bare `--dry-run` or `--dry-run=true` counts.+ # Options may sit between the tool and `publish` (`pnpm --filter=<pkg> publish`), but+ # `publish` must be a bare word, so `electron-builder --publish never` stays clear.+ # An S3 copy counts only when a release URI follows the source argument, so a+ # download from a release bucket stays clear.+ - pattern-either:+ - patterns:+ - pattern: 'run: $CMD'+ - metavariable-regex:+ metavariable: $CMD+ regex: "(?s).*(?:\\b(?:npm|pnpm|yarn|uv|poetry|cargo)(?:(?:[ \\t]|\\\\\\r?\\n)+(?:-[^\\s;&|#]*(?:(?:[ \\t]|\\\\\\r?\\n)+[^\\s;&|#\\-\\\\][^\\s;&|#]*)?|workspace(?:[ \\t]|\\\\\\r?\\n)+[^\\s;&|#\\-\\\\][^\\s;&|#]*))*(?:[ \\t]|\\\\\\r?\\n)+publish(?![\\w-])(?!(?:[^\\n;&|#]*\\\\[ \\t]*\\r?\\n)*[^\\n;&|#]*--dry-run(?:=true)?(?![=\\w-]))|\\btwine(?:[ \\t]|\\\\\\r?\\n)+upload\\b(?!(?:[^\\n;&|#]*\\\\[ \\t]*\\r?\\n)*[^\\n;&|#]*--dry-run(?:=true)?(?![=\\w-]))|\\bgh(?:[ \\t]|\\\\\\r?\\n)+release(?:[ \\t]|\\\\\\r?\\n)+(?:create|upload|edit)\\b|\\baws(?:[ \\t]|\\\\\\r?\\n)+s3(?:[ \\t]|\\\\\\r?\\n)+(?:cp|sync)\\b(?:(?:[ \\t]|\\\\\\r?\\n)+-[^\\s;&|#]*)*(?:[ \\t]|\\\\\\r?\\n)+[^\\s;&|#\\-\\\\][^\\s;&|#]*(?:[ \\t]|\\\\\\r?\\n)+(?:[^\\n;&|#]|\\\\\\r?\\n)*?s3://[^\\s;&|#]*release).*"+ - patterns:+ - pattern: 'uses: $ACTION'+ - metavariable-regex:+ metavariable: $ACTION+ regex: '^(?:pypa/gh-action-pypi-publish|JS-DevTools/npm-publish|softprops/action-gh-release|ncipollo/release-action|actions/create-release|actions/upload-release-asset)@'+ severity: ERRORdiff --git a/AGENTS.md b/AGENTS.mdindex 20f3fb92db0f..3543a86b6cc3 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -137,6 +137,7 @@ Examples:- CI uploads test results to Trunk Flaky Tests; the `trunk` MCP server in `.mcp.json` queries per-test flakiness on a PR or `master` (authenticate via `/mcp`, or a `TRUNK_API_TOKEN` bearer header when headless) — see `/debugging-ci-failures` and `/fixing-flaky-tests`- **A workflow edit reaches every open PR before those branches rebase.** It runs against the PR merged with master, but a companion change — a new dependency, file, or config — only arrives when the branch rebases. A workflow that starts requiring something unrebased branches lack fails every in-flight PR before its tests run. Make the new behavior degrade gracefully, or gate it. This has broken CI repeatedly.- Mechanical workflow rules (`timeout-minutes`, concurrency, dispatch budget, path filters, gate hygiene) are enforced by `hogli lint:workflows` and actionlint, which are the source of truth. `/authoring-ci-workflows` explains the reasoning behind each.+- **A pull request never publishes a package or release.** `[lint: github-actions-publish-on-pull-request]` A published version is public forever, and a pull request run executes code its author controls. Publish only from a `push` to `master`, a release tag, or a `workflow_dispatch` on `master`. A pull request run only builds and validates, for example with `--dry-run`. The semgrep rule cannot see a publisher inside a reusable workflow, so gate that job in the called workflow too. Never run a publish command by hand from a pull request branch. [`build-hogql-parser-npm.yml`](.github/workflows/build-hogql-parser-npm.yml) is the reference shape.## Security