Skip to content

fix: use pull_request_target for label-triggered workflows#12638

Merged
kim-em merged 4 commits intomasterfrom
fix-bot-approval-workflows
Mar 1, 2026
Merged

fix: use pull_request_target for label-triggered workflows#12638
kim-em merged 4 commits intomasterfrom
fix-bot-approval-workflows

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Feb 22, 2026

This PR switches four lightweight workflows from pull_request to
pull_request_target to stop GitHub from requiring manual approval when the
mathlib-lean-pr-testing[bot] app triggers label events (e.g. adding
builds-mathlib). Since the bot never lands commits on master, it is
perpetually treated as a "first-time contributor" and every pull_request
event it triggers requires approval. pull_request_target events always run
without approval because they execute trusted code from the base branch.

This is safe for all four workflows because none check out or execute code
from the PR branch — they only read labels, PR body, and file lists from the
event payload and API:

  • awaiting-mathlib.yml — checks label combinations
  • awaiting-manual.yml — checks label combinations
  • pr-body.yml — checks PR body formatting
  • check-stdlib-flags.yml — checks if stdlib_flags.h was modified via API

Also adds explicit permissions: pull-requests: read to each workflow as a
least-privilege hardening measure, since pull_request_target has access to
secrets.

Addresses the issue reported by Sebastian:
https://lean-fro.zulipchat.com/#narrow/channel/398861-general/topic/mathlib.20pr-testing.20breakage.3F/near/575084348

🤖 Prepared with Claude Code

This PR switches four workflows from `pull_request` to `pull_request_target`
to prevent GitHub from requiring manual approval when the
`mathlib-lean-pr-testing[bot]` app triggers label events. Since the bot never
lands commits on master, it is perpetually treated as a "first-time
contributor" and every `pull_request` event it triggers requires approval.
`pull_request_target` events always run without approval because they execute
trusted code from the base branch. This is safe for all four workflows because
none check out or execute code from the PR branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 22, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing bot commented Feb 22, 2026

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-02-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-02-22 13:04:59)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-02-28 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-01 07:40:11)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented Feb 22, 2026

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-02-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-02-22 13:05:00)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-02-28 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-03-01 07:40:12)

@nomeata
Copy link
Copy Markdown
Collaborator

nomeata commented Feb 22, 2026

PR body

Did you (or claude) double check if PR body is safely handled and no risk of injections here?

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Feb 22, 2026

Claude audited all four workflows for injection risk under pull_request_target and says:

pr-body.yml — reads context.payload.pull_request.body (attacker-controlled), but only passes it to regex.test(body) — a pure read-only string match in JavaScript. The body is never interpolated into shell commands, eval'd, written to GITHUB_ENV/GITHUB_OUTPUT, or used in API calls. Same for title. Failure messages are constant strings. The regexes are simple/linear (no ReDoS risk).

awaiting-mathlib.yml / awaiting-manual.yml — only read label names via exact-match comparisons. The only output is a constant 'true' string. No attacker-controlled data reaches any sink.

check-stdlib-flags.yml — reads the file list via API (pulls.listFiles) and does a strict equality check against 'src/stdlib_flags.h'. Labels are checked by exact name. No attacker-controlled data is echoed or interpolated.

None of the workflows check out PR code, use ${{ }} expression interpolation with untrusted data, or write attacker input to env/output files. The permissions: pull-requests: read block further limits GITHUB_TOKEN scope.

(Also confirmed by a separate Codex security audit.)

@kim-em kim-em enabled auto-merge February 22, 2026 22:02
@nomeata
Copy link
Copy Markdown
Collaborator

nomeata commented Feb 22, 2026

Thanks for the extra checks

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 27, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Feb 27, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 27, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Feb 27, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

@kim-em kim-em disabled auto-merge March 1, 2026 06:50
@kim-em kim-em enabled auto-merge March 1, 2026 06:51
@kim-em kim-em closed this Mar 1, 2026
auto-merge was automatically disabled March 1, 2026 07:56

Pull request was closed

@kim-em kim-em reopened this Mar 1, 2026
@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Mar 1, 2026

As this changes the trigger, the check-awaiting-mathlib and check-pr-body checks aren't running, so I will merge this one manually, bypassing the queue.

For pull_request events, GitHub uses the workflow definition from the PR branch. The PR branch's definition says "only trigger on pull_request_target", so the pull_request event is ignored. But pull_request_target events use the base branch's workflow definition, and the base branch still says pull_request, not pull_request_target. Neither version matches!

@kim-em kim-em merged commit feea8a7 into master Mar 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-other mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants