fix(698): review round 2 — close a PRE-EXISTING SIGPIPE inversion, narrow the bot allow-list, correct two overclaims
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / Docs update reminder (pull_request) Successful in 24s
PR Gates / decisions lifecycle (pull_request) Successful in 33s
review-verdict/h10 Awaiting review verdict for bafb487
PR Gates / Script tests (pytest) (pull_request) Successful in 59s
Review verdict / Set review-verdict status (pull_request_target) Successful in 34s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m30s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m36s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m9s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 21m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 22m6s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / Docs update reminder (pull_request) Successful in 24s
PR Gates / decisions lifecycle (pull_request) Successful in 33s
review-verdict/h10 Awaiting review verdict for bafb487
PR Gates / Script tests (pytest) (pull_request) Successful in 59s
Review verdict / Set review-verdict status (pull_request_target) Successful in 34s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m30s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m36s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m9s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 21m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 22m6s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Cross-family adversarial review returned BLOCKED with 3 Blockers + 2 Highs. Two were verified independently before acting on them. BLOCKER 1 (pre-existing on main, not introduced here). `producer | grep -q…` inverts under `set -o pipefail`: grep exits at its first match, the producer takes SIGPIPE and exits 141 once the list exceeds the pipe buffer, so a MATCH is reported as a FAILED pipeline. Reproduced at 1901 paths / ~171KB, inside the enumerator's 2000-file cap: * `A.cs` + 1900 docs paths -> docs_only=yes, status 141 (a C# PR exempted) * `.gitea/…` + 1900 docs -> the PROTECTED guard MISSES entirely The second reaches a green required status on a PR rewriting the gate, with no retarget, no bot account and no forged status. This construct shipped with the original docs-only check (review-verdict.yml:257 on main), so it was live. Fixed in both the enforced gate and the advisory hook by using here-strings, which have no writer to signal. New record `ci.grep-q-pipefail-inversion`. BLOCKER 2 (mine). `web/package.json` / `web/package-lock.json` are removed from BOT_MANIFESTS. renovate.json enables only nuget/github-actions/dockerfile, so npm is unmanaged here and the entry bought nothing — while package.json `scripts` are EXECUTED by CI (npm ci, npm run build). It widened an exemption onto a code-execution path for no benefit. BLOCKER 3 + HIGH (documentation was wrong, code unchanged). The claim that `edited` made the retarget residual "non-durable" is retracted: runs are not serialized, so a stale run can post `success` after the reclassifying run posts `pending`. The ABA transition is narrowed and observable, NOT closed. Likewise the provenance check asks "posted by a user credential", not "posted by a reviewer" — ETV_STATUS_AUTH is basic auth, so a #697 forgery gets a non-null creator AND an attacker-chosen description and is preserved as human. Both now stated at full strength. TESTS. 4 large-input cases crossing the pipe buffer, each paired with a large-input POSITIVE control so "large lists now fail closed" (a deadlock) cannot pass as a fix. Verified by mutation: reverting the here-strings turns all three negatives red while the control stays green. Two of my own weak tests fixed — the "base advances" case called head_moves_to(SHA) with the already-current sha (a duplicate positive control, now a structural assertion that the comparator is .base.ref and never .base.sha), and the arity test counted five arguments without checking the fifth was the base. The whole class was invisible because every previous test used a handful of short paths: a guard whose behaviour depends on a buffer threshold needs a test that crosses it. Refs: #698 Decisions-Edit: yes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+13
-2
@@ -795,8 +795,10 @@ gate must not be able to exempt itself from the gate. That includes Renovate's `
|
||||
bumps, which already need the manual publish-then-pin two-step anyway.
|
||||
|
||||
The Renovate exemption additionally requires **every** changed path to be a dependency manifest —
|
||||
`Directory.Packages.props`, `.config/dotnet-tools.json`, `web/package.json`, `web/package-lock.json`
|
||||
(ersatztv#698). An author match alone is not enough, because `pull_request.user.login` is the PR's
|
||||
`Directory.Packages.props` or `.config/dotnet-tools.json`, and only those (ersatztv#698). The npm
|
||||
manifests are deliberately excluded: `renovate.json` enables only `nuget`/`github-actions`/`dockerfile`,
|
||||
so npm is unmanaged here, while `package.json` `scripts` are executed by CI (`npm ci`, `npm run build`)
|
||||
— exempting it would put a code-execution path inside the allow-list for no benefit. An author match alone is not enough, because `pull_request.user.login` is the PR's
|
||||
*immutable creator* while its head is not: pushing application code onto an open Renovate branch
|
||||
leaves the PR still "authored by renovate" and, previously, still exempt. A Renovate PR touching
|
||||
anything else — a `.csproj`, a source file — is not blocked, it just needs a real verdict. **If a
|
||||
@@ -819,12 +821,21 @@ used by the advisory hook `.claude/hooks/pretooluse-merge-consent.sh` (ersatztv#
|
||||
reads that script's **exit status** — a non-zero exit means "could not tell" and withholds the
|
||||
exemption; its stdout is meaningless on any failure path and is never consumed.
|
||||
|
||||
**Never write a classification guard as `producer | grep -q…` here.** Under `set -o pipefail`, `grep -q`
|
||||
exits at its first match, the producer takes SIGPIPE (141), and a MATCH is reported as a failed
|
||||
pipeline — inverting the guard for any PR whose path list exceeds the pipe buffer. That let a large PR
|
||||
be classified docs-only, and let one editing `.gitea/` skip the protected-path check entirely. Use a
|
||||
here-string (`grep -q… <<< "$files"`). Full detail: `ci.grep-q-pipefail-inversion`.
|
||||
|
||||
That script takes the expected base branch as a **required 5th argument** and refuses to enumerate when
|
||||
the PR's live base does not match it, checked both before and after paging (ersatztv#698).
|
||||
`/pulls/{n}/files` diffs against the PR's *live* base, so retargeting changes the answer without moving
|
||||
the head sha — a PR opened into `main` and retargeted mid-run was granted a docs-only exemption while
|
||||
its diff against `main` carried a C# file. The workflow passes the base from the `pull_request_target`
|
||||
payload, which a retarget cannot rewrite, and `edited` is in `types:` so a retarget reclassifies.
|
||||
`edited` gives **detection, not atomicity**: runs are not serialized, so a stale run can still post
|
||||
`success` after the reclassifying run posts `pending`. The `main → scratch → main` ABA transition is
|
||||
narrowed and observable, not closed — see the residual in `ci.exemption-provenance`.
|
||||
|
||||
Three properties of this workflow are security-relevant and are **structurally** asserted by tests in
|
||||
`scripts/tests/test_pr_changed_files.py` — those tests pin the workflow's shape, which is not the same
|
||||
|
||||
@@ -48,6 +48,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
|
||||
| `ci.functional-e2e-harness` | The `functional-e2e` CI job boots the PR's own code from source via `dotnet run` (`scripts/e2e-local.sh`) and runs deterministic assertions (`scripts/e2e-functional.sh`) as an advisory (non-blocking) job, not a `build` dependency or required check. Originally curl-only; since #445 the same job carries a second, headless-browser step for the contracts curl cannot express — see `ci.ui-e2e-harness`. | 2026-07-16 | [link](records/ci/functional-e2e-harness.md) |
|
||||
| `ci.gate-trigger-base-resolved` | The workflow that writes the branch-protection-required `review-verdict/h10` status triggers on `pull_request_target` with `branches: [main]`, never on plain `pull_request`. Gitea resolves a `pull_request` workflow DEFINITION from the PR's own head commit, so under that trigger a PR editing `.gitea/workflows/review-verdict.yml` ran its own rewritten copy and could post `h10=success` for itself; `pull_request_target` resolves the definition from the base instead. The `branches: [main]` filter is part of the rule, not a refinement of it: base resolution only relocates the rewrite from the head to the base, so without the filter a PR opened into an attacker-pushed base branch runs that branch's gate. `pull_request_target` is safe HERE only because this job never checks out or executes head-supplied code — it checks out `base.sha` and runs only that tree's scripts (`ci.shared-pr-file-enumeration`); reintroducing a head checkout under this trigger would be worse than the bug it fixed. This closes the rewrite route through THIS workflow and does NOT close the class: Gitea injects a write-capable `GITEA_TOKEN` into EVERY job, so any ref-resolved workflow — and a collaborator's own API token, since branch protection binds the context and not its issuer — can still forge `review-verdict/h10`. Tracked in #697; the exemption path has its own separate defects in #698. | 2026-07-28 | [link](records/ci/gate-trigger-base-resolved.md) |
|
||||
| `ci.gitea-milestone-filter-noop` | Never filter issues with the server-side `?milestones=<name>` parameter — fetch all open issues once and filter LOCALLY on each issue's `.milestone.title`. | 2026-07-21 | [link](records/ci/gitea-milestone-filter-noop.md) |
|
||||
| `ci.grep-q-pipefail-inversion` | In any script running under `set -o pipefail`, a security or classification predicate of the form `producer \| grep -q…` is FORBIDDEN. `grep -q` exits at its first match; the producer then takes SIGPIPE and exits 141 once the data exceeds the pipe buffer (~64K), so `pipefail` reports the pipeline as FAILED even though grep MATCHED — inverting the predicate exactly when the input is large. Use a here-string (`grep -q… <<< "$data"`), which is written to a temp file and cannot signal its writer, so the exit status is grep's alone. `grep -c` and `grep -v` WITHOUT `-q` are safe because they drain stdin. This applies to both the enforced gate `.gitea/workflows/review-verdict.yml` and the advisory hook `.claude/hooks/pretooluse-merge-consent.sh`. | 2026-07-29 | [link](records/ci/grep-q-pipefail-inversion.md) |
|
||||
| `ci.infra-shaped-red-under-load` | When a job dies inside a setup/cache step before your code compiles, check the runner host's load before diagnosing the diff, and never file a CI bug off one sample under pressure. | 2026-07-21 | [link](records/ci/infra-shaped-red-under-load.md) |
|
||||
| `ci.jq-version-contract` | Every shell gate that shells out to `jq` is authored to the jq 1.6-compatible subset, because the CI runner ships jq 1.6 while every developer Mac ships 1.8.x. `scripts/jq-preflight.sh` (no args) prints the parsed version and asserts a floor of 1.6 in every gate job's log; `scripts/jq-preflight.sh --expect 1.6` additionally pins and fails loudly, but ONLY in the `script-tests` job. `review-verdict.yml` never pins — it writes the branch-protection-required `review-verdict/h10` status, so a hard pin there would turn any jq bump into a repo-wide merge deadlock. | 2026-07-26 | [link](records/ci/jq-version-contract.md) |
|
||||
| `ci.killed-job-triage` | Never trust a job's `conclusion` field alone — read the log tail and require an `❌ Failure - Main …` marker before treating a red as a real failure. | 2026-07-21 | [link](records/ci/killed-job-triage.md) |
|
||||
|
||||
@@ -20,39 +20,46 @@ mid-flight. The job enumerated against the moved base, read docs-only, and poste
|
||||
`review-verdict/h10=success — "Exempt: docs-only change"`. Retargeted back to `main`: **nothing
|
||||
reclassified** (`created_at == updated_at`), leaving a PR into `main` whose diff carried a C# file
|
||||
behind a green required check. Closed unmerged, branches deleted, no forged `h10` left anywhere.
|
||||
**Why a base BINDING and not a pinned diff.** Diffing two immutable shas would close it outright, and
|
||||
Gitea 1.25.4 cannot serve that — measured, not assumed: `compare/{base}...{head}` returns
|
||||
`total_commits`/`commits` and **no `files`**, and a `--depth=1` fetch of the two shas has **no merge
|
||||
base**, so three-dot is impossible and two-dot over-reports everything `main` gained since the branch
|
||||
point. A full-history fetch per PR event was judged too expensive. So the base is read before the
|
||||
first page and after the last, and **the gap is stated plainly**: a retarget opening *and* closing
|
||||
strictly between the files call and the re-read stays invisible from inside the enumeration. What
|
||||
makes that acceptable is that it is no longer *durable* — the retarget back to `main` fires `edited`,
|
||||
and the re-run re-derives. The two are one fix: `edited` without re-derivation re-runs and then exits
|
||||
on the existing `success`; re-derivation without `edited` never gets its second run.
|
||||
**Why a base BINDING and not a pinned diff.** Diffing two immutable shas would close it outright;
|
||||
Gitea 1.25.4 cannot serve that — measured: `compare/{base}...{head}` returns no `files`, and a
|
||||
`--depth=1` fetch of the two shas has no merge base, so three-dot is impossible and two-dot
|
||||
over-reports everything `main` gained since the branch point. So the base is read before the first page
|
||||
and after the last, and **the gap is stated plainly**: a retarget opening *and* closing strictly
|
||||
between the files call and the re-read stays invisible from inside the enumeration.
|
||||
|
||||
**An earlier draft claimed `edited` made that residual non-durable. It does not, and cross-family
|
||||
review was right to call it a Blocker.** `edited` gives DETECTION, not atomicity or ordering: runs are
|
||||
not serialized, so the stale run can post `success` AFTER the reclassifying run posts `pending`, and an
|
||||
already-scheduled merge can fire in the green window between them. The `main → scratch → main` ABA
|
||||
transition is therefore NARROWED and observable, not closed. Tracked as an explicit residual rather
|
||||
than described as fixed. `edited` and re-derivation remain one fix — `edited` alone re-runs and exits
|
||||
on the existing `success`; re-derivation alone never gets a second run — but together they are
|
||||
mitigation, not a guarantee.
|
||||
|
||||
**Route 2 — a bot ACCOUNT does not attribute the CODE.** `pull_request.user.login` is the PR's
|
||||
immutable *creator*; its head is not. Push application code onto an open Renovate branch and the PR is
|
||||
still "authored by renovate", touches no protected path, and was exempted. Checking the *pusher* fixes
|
||||
nothing — a git author is self-asserted text. So the exemption is constrained by what a bump can
|
||||
legitimately *be*: across all 11 Renovate PRs this repo has had, the paths touched were
|
||||
`Directory.Packages.props` (10) and `.config/dotnet-tools.json` (1); the `web/` manifests are included
|
||||
so the first SPA bump does not deadlock. `*.csproj` is excluded — under Central Package Management
|
||||
`Directory.Packages.props` (10) and `.config/dotnet-tools.json` (1) — and ONLY those. An earlier draft
|
||||
also exempted `web/package.json`/`web/package-lock.json` "so a first SPA bump cannot deadlock"; review
|
||||
called that a Blocker and was right. `renovate.json` enables only nuget/github-actions/dockerfile, so
|
||||
npm is unmanaged here and the entry bought nothing, while `package.json` `scripts` are EXECUTED by CI
|
||||
(`npm ci`, `npm run build`) — widening an exemption onto a code-execution path for no benefit. `*.csproj` is excluded — under Central Package Management
|
||||
versions live in `Directory.Packages.props`, so a Renovate `.csproj` edit is anomalous by
|
||||
construction. Cost stated: such a PR is not blocked, it needs a real verdict. The two exemptions are
|
||||
evaluated as INDEPENDENT predicates: written as an `elif` chain, a Renovate PR touching only `docs/`
|
||||
entered the bot branch, failed the manifest test, and never reached the docs-only branch.
|
||||
|
||||
**The shape occurs without an attacker, as a counterfactual.** Renovate PR #20 touched a `.csproj` and
|
||||
two C# files, but has no `h10` status and was never exempted: it merged 2026-06-27, the gate landed
|
||||
2026-07-25. The point is what identity-only *would* have done with it. An earlier draft claimed it had
|
||||
actually been exempted — wrong, and the correction is kept because "was silently exempted" and "would
|
||||
have been" are different claims.
|
||||
**A counterfactual, not an incident.** Renovate PR #20 touched a `.csproj` and two C# files but has no
|
||||
`h10` status: it merged 2026-06-27, the gate landed 2026-07-25. The point is what identity-only *would*
|
||||
have done. An earlier draft claimed it HAD been exempted — wrong, and the correction is kept because
|
||||
"was silently exempted" and "would have been" are different claims.
|
||||
|
||||
**Route 3 — provenance, and the direction of the test.** The short-circuit exited on any `success`, so
|
||||
an exemption this job wrote was indistinguishable from a human verdict; obtained once, a forgery was
|
||||
accepted on every later run. It could not simply be deleted — it exists so `pending` cannot un-approve
|
||||
a reviewed head. Measured on the **combined** endpoint the job reads: a status POSTed with a user
|
||||
a reviewed head. Measured on the **combined** endpoint: a status POSTed with a user
|
||||
credential carries `.creator.login`, one POSTed by an Actions job carries `"creator": null`. The test is
|
||||
written in the **positive** direction — short-circuit only on something identified as human — because
|
||||
spelled the other way ("skip if it looks machine-written") any unrecognised shape falls through to
|
||||
@@ -70,3 +77,6 @@ a PR, because `pull_request_target` resolves this definition from `main` — the
|
||||
`ci.gate-trigger-base-resolved` records. Pre-merge evidence is that reproduction plus the
|
||||
executed-behaviour tests in `scripts/tests/test_pr_changed_files.py`, each verified by mutation; the
|
||||
live re-check happens on `main` right after merge.
|
||||
|
||||
**Separate defect found reviewing this change:** `ci.grep-q-pipefail-inversion` — a pre-existing
|
||||
SIGPIPE inversion that let a large PR skip the `PROTECTED` guard entirely. Fixed in the same PR.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
key: ci.grep-q-pipefail-inversion
|
||||
title: '2026-07-29 — never feed `grep -q` from a pipe under `set -o pipefail`: SIGPIPE turns a MATCH into a failed pipeline and inverts the guard (#698)'
|
||||
status: active
|
||||
since: '2026-07-29'
|
||||
supersedes: none
|
||||
superseded-by: none
|
||||
rule: 'In any script running under `set -o pipefail`, a security or classification predicate of the form `producer | grep -q…` is FORBIDDEN. `grep -q` exits at its first match; the producer then takes SIGPIPE and exits 141 once the data exceeds the pipe buffer (~64K), so `pipefail` reports the pipeline as FAILED even though grep MATCHED — inverting the predicate exactly when the input is large. Use a here-string (`grep -q… <<< "$data"`), which is written to a temp file and cannot signal its writer, so the exit status is grep''s alone. `grep -c` and `grep -v` WITHOUT `-q` are safe because they drain stdin. This applies to both the enforced gate `.gitea/workflows/review-verdict.yml` and the advisory hook `.claude/hooks/pretooluse-merge-consent.sh`.'
|
||||
signals: 'grep -q pipefail, exit 141, SIGPIPE in a shell guard, large PR classified docs-only, protected path guard skipped, printf pipe grep -q, classification inverts on big input, pipe buffer 64K shell predicate · paths: `.gitea/workflows/review-verdict.yml`, `.claude/hooks/pretooluse-merge-consent.sh`, `scripts/tests/test_pr_changed_files.py` · issues: #698, #649'
|
||||
mechanics: '`if ! grep -qvE "$RE" <<< "$files"` / `if grep -qE "$RE" <<< "$files"`; regression tests `test_a_LARGE_pr_*` in `scripts/tests/test_pr_changed_files.py` build 1900+ paths (~171KB) to cross the pipe buffer'
|
||||
---
|
||||
|
||||
Found by cross-family adversarial review of the #698 PR, then reproduced directly. It is not a defect
|
||||
of that change — the construct shipped with the ORIGINAL docs-only check and was live on `main`.
|
||||
|
||||
**The mechanism.** `grep -q` stops reading at its first match. If the writer still has data queued, it
|
||||
gets SIGPIPE and exits 141. `pipefail` makes the pipeline's status that of the failing member, so a
|
||||
successful MATCH is reported as a FAILED pipeline. Every guard written as `if ! producer | grep -q…`
|
||||
or `if producer | grep -q…` therefore flips, and only for large inputs — which is why every existing
|
||||
test missed it: they all used a handful of short paths, far below the buffer.
|
||||
|
||||
**Both directions were reproduced**, at 1901 paths / ~171KB, inside the enumerator's 2000-file cap:
|
||||
|
||||
- `A.cs` followed by 1900 docs paths → `docs_only=yes`, pipeline status 141. A C# PR classified
|
||||
docs-only and auto-granted `review-verdict/h10=success`.
|
||||
- `.gitea/workflows/review-verdict.yml` followed by 1900 docs paths → the `PROTECTED` guard MISSES, so
|
||||
a PR editing the gate's own definition skips the protected-path check and falls through to the
|
||||
exemptions.
|
||||
|
||||
The second is the serious one: it reaches a green required status on a PR that rewrites the gate, with
|
||||
**no retarget, no bot account and no forged status** — nothing but a large PR. It is a more direct hole
|
||||
than any of the three routes #698 was filed for.
|
||||
|
||||
**Why a here-string rather than dropping `-q`.** Dropping `-q` also works (grep then drains stdin), but
|
||||
it relies on a subtle side effect and reads as a redundant `>/dev/null`. `<<<` removes the pipe
|
||||
entirely: bash materialises the string, so there is no writer to signal and the status is unambiguous.
|
||||
The cost is a temp file per evaluation, which is irrelevant at these sizes.
|
||||
|
||||
**The testing lesson, which generalises past this bug.** The whole class was invisible because every
|
||||
test used small inputs. A guard whose behaviour depends on a BUFFER THRESHOLD needs a test that crosses
|
||||
the threshold; otherwise the suite is measuring the wrong regime entirely and full coverage of the
|
||||
small regime proves nothing. The regression tests pair each large-input negative with a large-input
|
||||
POSITIVE control, so "large lists now fail closed" (a merge deadlock) cannot masquerade as a fix.
|
||||
Reference in New Issue
Block a user