review-verdict.yml is head-resolved, so a PR editing it can self-approve the required check #672

Closed
opened 2026-07-27 00:05:43 +02:00 by timothy · 4 comments
Owner

Found while reviewing the #649 wiring. Not a regression — it predates all of #643/#647/#649 and those changes strictly reduced the surrounding surface. Filing it because the ci.shared-pr-file-enumeration record previously implied it was mitigated, and it is not.

The hole

Gitea, like GitHub, resolves a pull_request workflow definition from the PR's own head commit. So a PR that edits .gitea/workflows/review-verdict.yml runs its own rewritten copy.

That copy can simply POST review-verdict/h10=success for its head sha and stop. Two things that look like they should prevent it, do not:

  • PROTECTED does not help — the tampered copy also defines PROTECTED.
  • Branch protection does not help. The rule on main requires the context review-verdict/h10 to be success. It does not care who posted it, and the rule carries required_approvals: 0. A self-posted success satisfies the requirement outright.

The #649 base-ref checkout closes the adjacent hole (a PR rewriting scripts/pr-changed-files.sh, the script the workflow executes), and a branches: [main] filter closes a third (forging a status via a PR into an attacker-created base branch). Neither touches this one, because the workflow file itself is head-supplied.

Why it is currently low-severity

Pushing a branch to this repo requires write access, so the threat model is a compromised contributor, not an anonymous attacker. Someone with write access has other paths. It is worth closing anyway, because the entire H10 mechanism exists to make merge-consent derivable from state rather than assertable — and this is a way to assert it.

Options (not deciding here)

  1. Verify the status author. Have something outside the PR's control reject a review-verdict/h10 whose author is the CI account rather than a reviewer. Needs a second, non-PR-writable actor.
  2. Require an approval alongside the check. required_approvals: 1 on main means a forged status alone is insufficient. Cheapest by far; changes the human workflow.
  3. Move the exemption decision out of the PR-controlled workflow — e.g. a scheduled/workflow_dispatch job that reads the PR and posts, so its definition comes from main rather than the head.
  4. Accept and document, on the grounds that write access is already trust. Defensible only if written down where a reader will find it.

Done-when

  • Confirm empirically that Gitea resolves the pull_request workflow definition from the HEAD — confirmed on this instance (Gitea 1.25.4), scratch PR #693: the head's rewritten copy ran and posted its probe context, and the real review-verdict/h10 was never written at all
  • Decide between the options above, with the cost to the normal review flow stated — chose option 3, via pull_request_target + branches: [main]. Option 2 (required_approvals: 1) was cheapest but is unusable here: Gitea forbids approving your own PR and this is effectively a single-maintainer repo, so it would deadlock every PR. Option 1 buys nothing without a second identity, since the tampered workflow holds the same token. Cost of the chosen fix: a non-main-based PR gets no status (fail-closed), a retargeted PR stays statusless until its next push, and the gate is no longer exercised by its own PR — documented in docs/ci-cd.md
  • If a fix lands: demonstrate by constructing the bypass on a scratch branch and showing it now fails — done, scoped: PR #694 shows the identical rewrite is ignored under pull_request_target (base definition ran, posted h10=pending), and PR #695 shows a non-main base produces no run at all. This demonstrates the fix for this workflow only — probe #696 shows the bypass still succeeds via docker-build.yml, which is the residual below
  • ci.shared-pr-file-enumeration updated to match the resolved state — past-tensed, plus release.verdict-status-check (body and its rule: field) and a new record ci.gate-trigger-base-resolved
  • Adversarial review passed — three cold reviews across two model families; rounds 1–2 BLOCKED on doc overclaim and residual scope, both fixed; final head ceef16081 MERGEABLE

Residual — deliberately NOT closed here

This fix closes the definition-rewrite route through review-verdict.yml. It does not close the class: Gitea injects a write-capable GITEA_TOKEN into every job, and branch protection binds the context, not its issuer. Filed as #697. Three further exemption-path defects found during review (retarget race, Renovate-PR hijack, unreclassified inherited success) — none introduced by this fix — are #698.

PR #699.

Found while reviewing the #649 wiring. **Not a regression** — it predates all of #643/#647/#649 and those changes strictly reduced the surrounding surface. Filing it because the `ci.shared-pr-file-enumeration` record previously implied it was mitigated, and it is not. ## The hole Gitea, like GitHub, resolves a `pull_request` workflow **definition** from the PR's own head commit. So a PR that edits `.gitea/workflows/review-verdict.yml` runs **its own rewritten copy**. That copy can simply POST `review-verdict/h10=success` for its head sha and stop. Two things that look like they should prevent it, do not: - **`PROTECTED` does not help** — the tampered copy also defines `PROTECTED`. - **Branch protection does not help.** The rule on `main` requires the *context* `review-verdict/h10` to be `success`. It does not care who posted it, and the rule carries `required_approvals: 0`. A self-posted `success` satisfies the requirement outright. The #649 base-ref checkout closes the adjacent hole (a PR rewriting `scripts/pr-changed-files.sh`, the script the workflow *executes*), and a `branches: [main]` filter closes a third (forging a status via a PR into an attacker-created base branch). Neither touches this one, because the workflow file itself is head-supplied. ## Why it is currently low-severity Pushing a branch to this repo requires write access, so the threat model is a **compromised contributor**, not an anonymous attacker. Someone with write access has other paths. It is worth closing anyway, because the entire H10 mechanism exists to make merge-consent *derivable from state* rather than assertable — and this is a way to assert it. ## Options (not deciding here) 1. **Verify the status author.** Have something outside the PR's control reject a `review-verdict/h10` whose author is the CI account rather than a reviewer. Needs a second, non-PR-writable actor. 2. **Require an approval alongside the check.** `required_approvals: 1` on `main` means a forged status alone is insufficient. Cheapest by far; changes the human workflow. 3. **Move the exemption decision out of the PR-controlled workflow** — e.g. a scheduled/`workflow_dispatch` job that reads the PR and posts, so its definition comes from `main` rather than the head. 4. **Accept and document**, on the grounds that write access is already trust. Defensible only if written down where a reader will find it. ## Done-when - [x] Confirm empirically that Gitea resolves the `pull_request` workflow definition from the HEAD — **confirmed on this instance (Gitea 1.25.4)**, scratch PR #693: the head's rewritten copy ran and posted its probe context, and the real `review-verdict/h10` was never written at all - [x] Decide between the options above, with the cost to the normal review flow stated — **chose option 3**, via `pull_request_target` + `branches: [main]`. Option 2 (`required_approvals: 1`) was cheapest but is unusable here: Gitea forbids approving your own PR and this is effectively a single-maintainer repo, so it would deadlock every PR. Option 1 buys nothing without a second identity, since the tampered workflow holds the same token. Cost of the chosen fix: a non-`main`-based PR gets no status (fail-closed), a retargeted PR stays statusless until its next push, and **the gate is no longer exercised by its own PR** — documented in `docs/ci-cd.md` - [x] If a fix lands: demonstrate by constructing the bypass on a scratch branch and showing it now fails — **done, scoped**: PR #694 shows the identical rewrite is ignored under `pull_request_target` (base definition ran, posted `h10=pending`), and PR #695 shows a non-`main` base produces no run at all. **This demonstrates the fix for _this workflow_ only** — probe #696 shows the bypass still succeeds via `docker-build.yml`, which is the residual below - [x] `ci.shared-pr-file-enumeration` updated to match the resolved state — past-tensed, plus `release.verdict-status-check` (body *and* its `rule:` field) and a new record `ci.gate-trigger-base-resolved` - [x] Adversarial review passed — three cold reviews across two model families; rounds 1–2 BLOCKED on doc overclaim and residual scope, both fixed; final head `ceef16081` MERGEABLE ## Residual — deliberately NOT closed here This fix closes the definition-rewrite route through `review-verdict.yml`. It does **not** close the class: Gitea injects a write-capable `GITEA_TOKEN` into every job, and branch protection binds the *context*, not its issuer. Filed as **#697**. Three further exemption-path defects found during review (retarget race, Renovate-PR hijack, unreclassified inherited success) — none introduced by this fix — are **#698**. PR #699.
timothy added the ci-cdpriority: mediumsecurity labels 2026-07-27 00:05:46 +02:00
Author
Owner

Agreeing with the analysis, and recording the branches: [main] variant properly rather than leaving it in a passing clause — it was offered to me during #666 and I want the trade-off written down before someone reaches for it as an obvious win.

The mechanism it closes. The #666 base-ref checkout rests on "a PR cannot push to its own base branch". That holds for main and fails for any attacker-created base: push evil-base carrying a tampered scripts/pr-changed-files.sh, open payload → evil-base, and the job checks out evil-base, runs the tampered enumeration, and posts a forged review-verdict/h10=success on payload's head sha. Retarget to main and the never-overwrite guard (existing = success → exit 0) actively preserves it — a guard that is correct in isolation becoming load-bearing in the attacker's favour. That is #663's inheritance property supplying the last step.

Why it is not a free fix. edited is not in this workflow's types:, so a PR retargeted into main from another base gets no run and therefore no status at all. Fail-closed, but it stalls silently — an exempt Renovate PR would sit unmergeable with a missing required context and no log explaining why. Adding branches: [main] without also adding edited trades a hostile-actor hole for a routine-operations one, and adding edited re-opens the question of what happens when the workflow re-runs over an existing verdict.

Which is why I think you are right that this issue dominates it. All three (this, the branches: variant, #663) require write access, and while a head-supplied workflow definition can post its own success, closing the other two changes nothing about the threat model — they are alternate routes to a door that is already open. Sequencing matters: fix this one first, then re-evaluate whether the branches: filter is still worth its operational cost, because option 1 in your list (verify the status author from outside the PR's control) closes all three at once and makes the filter redundant rather than merely unnecessary.

One correction to my own record while I am here: ci.shared-pr-file-enumeration says the base-ref checkout means "a PR cannot supply the code that judges it". That is true of the scripts and false of the workflow, which is exactly your point. I scoped it in the "what is deliberately NOT claimed" paragraph, but the headline sentence still reads stronger than it should. Worth tightening when this is fixed, so the record does not have to be read to the end to avoid being misled.

Agreeing with the analysis, and recording the `branches: [main]` variant properly rather than leaving it in a passing clause — it was offered to me during #666 and I want the trade-off written down before someone reaches for it as an obvious win. **The mechanism it closes.** The #666 base-ref checkout rests on "a PR cannot push to its own base branch". That holds for `main` and fails for any attacker-created base: push `evil-base` carrying a tampered `scripts/pr-changed-files.sh`, open `payload → evil-base`, and the job checks out `evil-base`, runs the tampered enumeration, and posts a forged `review-verdict/h10=success` on `payload`'s head sha. Retarget to `main` and the never-overwrite guard (`existing = success → exit 0`) actively *preserves* it — a guard that is correct in isolation becoming load-bearing in the attacker's favour. That is #663's inheritance property supplying the last step. **Why it is not a free fix.** `edited` is not in this workflow's `types:`, so a PR retargeted *into* `main` from another base gets no run and therefore no status at all. Fail-closed, but it stalls silently — an exempt Renovate PR would sit unmergeable with a missing required context and no log explaining why. Adding `branches: [main]` without also adding `edited` trades a hostile-actor hole for a routine-operations one, and adding `edited` re-opens the question of what happens when the workflow re-runs over an existing verdict. **Which is why I think you are right that this issue dominates it.** All three (this, the `branches:` variant, #663) require write access, and while a head-supplied workflow definition can post its own `success`, closing the other two changes nothing about the threat model — they are alternate routes to a door that is already open. Sequencing matters: fix this one first, then re-evaluate whether the `branches:` filter is still worth its operational cost, because option 1 in your list (verify the status *author* from outside the PR's control) closes all three at once and makes the filter redundant rather than merely unnecessary. One correction to my own record while I am here: `ci.shared-pr-file-enumeration` says the base-ref checkout means "a PR cannot supply the code that judges it". That is true of the *scripts* and false of the *workflow*, which is exactly your point. I scoped it in the "what is deliberately NOT claimed" paragraph, but the headline sentence still reads stronger than it should. Worth tightening when this is fixed, so the record does not have to be read to the end to avoid being misled.
timothy added the in-progress label 2026-07-28 21:02:36 +02:00
Author
Owner

Claiming this — orchestrator session starting 2026-07-28.

Pre-claim checks (per process.parallel-session-claim): no open PR references #672, git ls-remote --heads origin '*672*' is empty, no prior claiming comment, origin/main freshly fetched at 036bcfc5a. The CLAIM? flag from select-queue.sh resolved to "no claim" — the only existing comment is the filer's own.

Claiming this — orchestrator session starting 2026-07-28. Pre-claim checks (per `process.parallel-session-claim`): no open PR references #672, `git ls-remote --heads origin '*672*'` is empty, no prior claiming comment, `origin/main` freshly fetched at `036bcfc5a`. The `CLAIM?` flag from `select-queue.sh` resolved to "no claim" — the only existing comment is the filer's own.
Author
Owner

Closing record

Outcome: Merged via PR #699 (0c492defa). .gitea/workflows/review-verdict.yml now triggers on pull_request_target with branches: [main], so Gitea resolves its definition from the base rather than the PR head. Closes the definition-rewrite route through this workflow — explicitly not the whole class (see Deferred).

Root cause: Gitea resolves a pull_request workflow definition from the PR's own head commit. #649's base-ref checkout bound the scripts this job executes to the base, but nothing bound the job definition, so a PR editing the gate ran its own rewritten copy. PROTECTED couldn't help (the rewrite defines it too) and branch protection couldn't either — it requires the context, not an issuer, with required_approvals: 0.

Decisions/conventions changed: new record ci.gate-trigger-base-resolved. Updated: ci.shared-pr-file-enumeration (its "does NOT mean a PR cannot rewrite the gate" paragraph past-tensed) and release.verdict-status-check (item 4 and its rule: frontmatter, which had gone stale in the round-1 fix — the exact failure mode that record's own archaeology warns about).

Reusable knowledge:

  • pull_request_target is base-resolved on Gitea 1.25.4, and branches: [main] is half the fix, not a refinement. Base resolution means the base branch supplies the definition, so without the filter the rewrite just relocates to an attacker-pushed base — and because a commit status is repo-global per sha (#663), a success forged there is inherited by a later genuine PR with the same head.
  • pull_request_target's usual danger doesn't transfer here only because this job never checks out or executes head-supplied code. Trigger and base-ref checkout are one decision; a head checkout under this trigger would be strictly worse than the bug.
  • The probe design matters. Each experiment posted a probe-named context, never the real h10, so a test of the gate could never forge the gate.
  • Probing beat reasoning. The residual (#697) was found by trying docker-build.yml's credentials, not by reading it. A reasoned audit would have concluded "only this workflow writes the status."
  • The fix removes the gate's own self-test. Base resolution cuts both ways: a change here is not exercised by its own PR, so it goes live only on merge, repo-wide, having never run. Recipe for verifying one safely is now in docs/ci-cd.md → Review-verdict gate.

Verification: Four scratch PRs on this instance (Gitea 1.25.4), all since deleted — #693 (pull_request is head-resolved: head's rewrite ran, real h10 never written), #694 (pull_request_target is base-resolved: base gate ran and posted h10=pending, on opened and synchronize, secrets available), #695 (branches: [main] blocks a non-main base: no run, no statuses), #696 (the negative result behind #697). New test pins the exact trigger set — an earlier version stayed green when workflow_dispatch was added alongside — plus a guard that no other workflow names the context in executable lines. Nine trigger mutations verified red by an independent reviewer. 340 script tests green; full CI green on ceef16081. Three cold reviews across two model families; rounds 1–2 BLOCKED on doc overclaim and residual scope.

Deferred: The class is not closed and the docs say so in the record's rule: field, not just its body. Gitea injects a write-capable GITEA_TOKEN into every job and branch protection binds the context rather than its issuer → #697. Three exemption-path defects found during review, none introduced here → #698. Post-merge live confirmation of the gate is partially complete: probe PR #702 shows the job registers and starts as (pull_request_target) against base main (so the trigger fires), but the job was killed by runner starvation before posting, so the classify-and-post half rests on #694's evidence rather than a main-based observation.

Docs updated: docs/ci-cd.md (gate section + the ⚠️ "not exercised by its own PR" recipe), new docs/decisions/records/ci/gate-trigger-base-resolved.md, ci.shared-pr-file-enumeration, release.verdict-status-check, regenerated docs/decisions/README.md.

## Closing record **Outcome:** Merged via PR #699 (`0c492defa`). `.gitea/workflows/review-verdict.yml` now triggers on `pull_request_target` with `branches: [main]`, so Gitea resolves its definition from the base rather than the PR head. Closes the definition-rewrite route through this workflow — explicitly **not** the whole class (see Deferred). **Root cause:** Gitea resolves a `pull_request` workflow *definition* from the PR's own head commit. #649's base-ref checkout bound the *scripts* this job executes to the base, but nothing bound the job definition, so a PR editing the gate ran its own rewritten copy. `PROTECTED` couldn't help (the rewrite defines it too) and branch protection couldn't either — it requires the *context*, not an issuer, with `required_approvals: 0`. **Decisions/conventions changed:** new record `ci.gate-trigger-base-resolved`. Updated: `ci.shared-pr-file-enumeration` (its "does NOT mean a PR cannot rewrite the gate" paragraph past-tensed) and `release.verdict-status-check` (item 4 **and** its `rule:` frontmatter, which had gone stale in the round-1 fix — the exact failure mode that record's own archaeology warns about). **Reusable knowledge:** - **`pull_request_target` is base-resolved on Gitea 1.25.4, and `branches: [main]` is half the fix, not a refinement.** Base resolution means the *base branch* supplies the definition, so without the filter the rewrite just relocates to an attacker-pushed base — and because a commit status is repo-global per sha (#663), a `success` forged there is inherited by a later genuine PR with the same head. - **`pull_request_target`'s usual danger doesn't transfer here** only because this job never checks out or executes head-supplied code. Trigger and base-ref checkout are one decision; a head checkout under this trigger would be strictly worse than the bug. - **The probe design matters.** Each experiment posted a *probe-named* context, never the real `h10`, so a test of the gate could never forge the gate. - **Probing beat reasoning.** The residual (#697) was found by *trying* `docker-build.yml`'s credentials, not by reading it. A reasoned audit would have concluded "only this workflow writes the status." - **The fix removes the gate's own self-test.** Base resolution cuts both ways: a change here is not exercised by its own PR, so it goes live only on merge, repo-wide, having never run. Recipe for verifying one safely is now in `docs/ci-cd.md` → Review-verdict gate. **Verification:** Four scratch PRs on this instance (Gitea 1.25.4), all since deleted — #693 (`pull_request` is head-resolved: head's rewrite ran, real `h10` never written), #694 (`pull_request_target` is base-resolved: base gate ran and posted `h10=pending`, on `opened` *and* `synchronize`, secrets available), #695 (`branches: [main]` blocks a non-`main` base: no run, no statuses), #696 (the negative result behind #697). New test pins the **exact** trigger set — an earlier version stayed green when `workflow_dispatch` was *added* alongside — plus a guard that no other workflow names the context in executable lines. Nine trigger mutations verified red by an independent reviewer. 340 script tests green; full CI green on `ceef16081`. Three cold reviews across two model families; rounds 1–2 BLOCKED on doc overclaim and residual scope. **Deferred:** The class is **not** closed and the docs say so in the record's `rule:` field, not just its body. Gitea injects a write-capable `GITEA_TOKEN` into every job and branch protection binds the context rather than its issuer → **#697**. Three exemption-path defects found during review, none introduced here → **#698**. Post-merge live confirmation of the gate is partially complete: probe PR #702 shows the job registers and starts as `(pull_request_target)` against base `main` (so the trigger fires), but the job was killed by runner starvation before posting, so the classify-and-post half rests on #694's evidence rather than a `main`-based observation. **Docs updated:** `docs/ci-cd.md` (gate section + the ⚠️ "not exercised by its own PR" recipe), new `docs/decisions/records/ci/gate-trigger-base-resolved.md`, `ci.shared-pr-file-enumeration`, `release.verdict-status-check`, regenerated `docs/decisions/README.md`.
timothy removed the in-progress label 2026-07-29 00:02:05 +02:00
Author
Owner

Correction to the closing record above — post-merge verification is COMPLETE, not partial.

That record said the classify-and-post half rested on #694's scratch-base evidence because the probe job was killed. The job was retried once runners freed up and completed in 5s. On probe PR #702, against base main, with the merged workflow:

success | review-verdict/h10 | Exempt: docs-only change (no code, no protected path)
success | Review verdict / Set review-verdict status (pull_request_target) | Successful in 5s

That exercises the whole live path end to end: the pull_request_target trigger fires with base main, the base-ref checkout resolves, the jq preflight passes, scripts/pr-changed-files.sh enumerates exhaustively from the base tree, the docs-only classification is correct, and the status is written. The earlier 14m44s "failure" was a killed job — missing log file, the documented tell — and not a defect.

So the gate is confirmed working on main. Probe PR #702 closed and its branch deleted; the throwaway docs/_gate-probe.md existed only on that branch and never merged.

Worth recording for whoever next changes this workflow: this is exactly the procedure docs/ci-cd.md → Review-verdict gate now prescribes, and it was needed precisely because the change could not be verified from its own PR. Three separate job-kill events occurred while landing this (all missing-log signature, one taking 22m on EF migration integrity), so budget for runner contention when running the probe — a killed probe reads exactly like a broken gate if you don't check for the missing log.

**Correction to the closing record above — post-merge verification is COMPLETE, not partial.** That record said the classify-and-post half rested on #694's scratch-base evidence because the probe job was killed. The job was retried once runners freed up and completed in 5s. On probe PR #702, against base `main`, with the merged workflow: ``` success | review-verdict/h10 | Exempt: docs-only change (no code, no protected path) success | Review verdict / Set review-verdict status (pull_request_target) | Successful in 5s ``` That exercises the whole live path end to end: the `pull_request_target` trigger fires with base `main`, the base-ref checkout resolves, the jq preflight passes, `scripts/pr-changed-files.sh` enumerates exhaustively from the base tree, the docs-only classification is correct, and the status is written. The earlier 14m44s "failure" was a killed job — missing log file, the documented tell — and not a defect. So the gate is confirmed working on `main`. Probe PR #702 closed and its branch deleted; the throwaway `docs/_gate-probe.md` existed only on that branch and never merged. Worth recording for whoever next changes this workflow: this is exactly the procedure `docs/ci-cd.md` → Review-verdict gate now prescribes, and it was needed precisely because the change could not be verified from its own PR. Three separate job-kill events occurred while landing this (all missing-log signature, one taking 22m on `EF migration integrity`), so budget for runner contention when running the probe — a killed probe reads exactly like a broken gate if you don't check for the missing log.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#672