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:
@@ -121,7 +121,12 @@ if files=$("$repo_root/scripts/pr-changed-files.sh" "$owner" "$repo" "$pr" "$sha
|
||||
files_complete=yes
|
||||
fi
|
||||
|
||||
if [ "$files_complete" = yes ] && [ -n "$files" ] && ! printf '%s\n' "$files" | grep -qvE '^(docs/|\.claude/|\.husky/|\.gitea/|.*\.md$)'; then
|
||||
# The here-string is load-bearing, not style: `printf … | grep -q` inverts under `set -o pipefail`
|
||||
# once the list exceeds the pipe buffer, because grep exits early and printf dies of SIGPIPE (141) —
|
||||
# turning a MATCH into a failed pipeline and this negated test into a spurious docs-only exemption.
|
||||
# Same defect as the enforced gate's (ersatztv#698); advisory here, so the blast radius is a missing
|
||||
# prompt rather than a green required check, but the fix is identical.
|
||||
if [ "$files_complete" = yes ] && [ -n "$files" ] && ! grep -qvE '^(docs/|\.claude/|\.husky/|\.gitea/|.*\.md$)' <<< "$files"; then
|
||||
# Docs/process-only PR: the Done-when + review-verdict gate doesn't apply — but this exemption is a
|
||||
# file-TYPE bypass, NOT the a+b+c "provably reviewed & ready" proof, so it does NOT auto-grant. It
|
||||
# passes through to normal permissioning (one prompt). This deliberately keeps a human in the loop for
|
||||
|
||||
@@ -202,7 +202,15 @@ jobs:
|
||||
# Package Management versions live in `Directory.Packages.props`, so a `.csproj` edit
|
||||
# attributed to Renovate is anomalous by construction. Such a PR is not blocked, it simply
|
||||
# needs a real verdict, which is the correct handling for a PR carrying source changes.
|
||||
BOT_MANIFESTS='^(Directory\.Packages\.props|\.config/dotnet-tools\.json|web/package\.json|web/package-lock\.json)$'
|
||||
# NOTE the npm manifests are deliberately ABSENT. An earlier draft included
|
||||
# `web/package.json` / `web/package-lock.json` "so a first SPA bump cannot deadlock". That was
|
||||
# a self-inflicted code-execution vector for zero benefit: `renovate.json` sets
|
||||
# `enabledManagers: ["nuget", "github-actions", "dockerfile"]`, so Renovate does not manage npm
|
||||
# in this repo at all, while `package.json` carries `scripts` that CI EXECUTES (`npm ci`,
|
||||
# `npm run build` in docker-build.yml). Exempting it would let a hijacked bot branch run
|
||||
# arbitrary shell in CI while every path still "looked like a manifest". If npm is ever added
|
||||
# to enabledManagers, the lockfile may be exemptible but `package.json` is not.
|
||||
BOT_MANIFESTS='^(Directory\.Packages\.props|\.config/dotnet-tools\.json)$'
|
||||
# Paths where NEITHER exemption applies, because a change here can alter the gate itself,
|
||||
# what CI runs, or what the hooks enforce.
|
||||
PROTECTED='^(\.claude/|\.gitea/|\.husky/|scripts/|docker/ci/)'
|
||||
@@ -284,7 +292,7 @@ jobs:
|
||||
existing_desc=$(printf '%s' "$existing_row" | jq -r '.description // ""')
|
||||
|
||||
human_verdict=no
|
||||
if [ -n "$existing_creator" ] && printf '%s' "$existing_desc" | grep -q '^Review-verdict:'; then
|
||||
if [ -n "$existing_creator" ] && grep -q '^Review-verdict:' <<< "$existing_desc"; then
|
||||
human_verdict=yes
|
||||
fi
|
||||
|
||||
@@ -335,7 +343,7 @@ jobs:
|
||||
reason="${enum_error} — no exemption"
|
||||
elif [ "${count:-0}" -eq 0 ]; then
|
||||
reason="no changed files could be read from the API — no exemption"
|
||||
elif printf '%s\n' "$files" | grep -qE "$PROTECTED"; then
|
||||
elif grep -qE "$PROTECTED" <<< "$files"; then
|
||||
reason="touches a protected path (gate/CI/hooks/scripts/ci-image) — exemptions do not apply"
|
||||
else
|
||||
# The two exemptions are evaluated as INDEPENDENT predicates rather than as a chain.
|
||||
@@ -356,12 +364,27 @@ jobs:
|
||||
# blocks the merge) but it would do so on the ORDINARY path — every non-bot PR — so the
|
||||
# gate would look broken rather than strict. `cmd || var=yes` is safe for the same
|
||||
# reason it is confusing; both are spelled out instead.
|
||||
# WHY HERE-STRINGS (`<<<`) AND NOT `printf … | grep -q` — a fail-open found by cross-family
|
||||
# review and reproduced here. `grep -q` exits at its FIRST match; the upstream `printf` then
|
||||
# takes SIGPIPE and exits 141 once the path list exceeds the pipe buffer (~64K). Under
|
||||
# `set -o pipefail` the PIPELINE is therefore a failure even though grep MATCHED, which
|
||||
# inverts every guard built on it:
|
||||
# * `if ! … grep -qvE "$DOCS_ONLY"` sets docs_only=yes for a list containing a C# file;
|
||||
# * `if … grep -qE "$PROTECTED"` MISSES, so a PR editing `.gitea/` skips the protected-path
|
||||
# guard entirely and falls through to the exemptions.
|
||||
# Reproduced with `A.cs` + 1900 docs paths (171KB, well inside the enumerator's 2000-file cap):
|
||||
# `docs_only=yes`, pipeline status 141. This construct PREDATES #698 — it shipped with the
|
||||
# original docs-only check — so it was a live hole on `main`, reachable with no retarget, no
|
||||
# bot account and no forged status, by nothing more sinister than a large PR.
|
||||
# A here-string is written to a temp file rather than a pipe, so the writer cannot be
|
||||
# signalled and the exit status is grep's alone. `grep -c`/`grep -v` without `-q` are safe
|
||||
# (they drain stdin) and are left as they are.
|
||||
is_bot=no
|
||||
if printf '%s\n' "$BOTS" | tr ' ' '\n' | grep -qxF "$AUTHOR"; then is_bot=yes; fi
|
||||
if grep -qxF "$AUTHOR" <<< "$(tr ' ' '\n' <<< "$BOTS")"; then is_bot=yes; fi
|
||||
manifests_only=no
|
||||
if ! printf '%s\n' "$files" | grep -qvE "$BOT_MANIFESTS"; then manifests_only=yes; fi
|
||||
if ! grep -qvE "$BOT_MANIFESTS" <<< "$files"; then manifests_only=yes; fi
|
||||
docs_only=no
|
||||
if ! printf '%s\n' "$files" | grep -qvE "$DOCS_ONLY"; then docs_only=yes; fi
|
||||
if ! grep -qvE "$DOCS_ONLY" <<< "$files"; then docs_only=yes; fi
|
||||
|
||||
if [ "$is_bot" = yes ] && [ "$manifests_only" = yes ]; then
|
||||
exempt=yes
|
||||
|
||||
+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.
|
||||
@@ -343,16 +343,26 @@ def test_positive_control_an_unmoved_base_still_enumerates(enumerate_files):
|
||||
assert enumerate_files.paths() == ["docs/a.md", "ErsatzTV/Program.cs"]
|
||||
|
||||
|
||||
def test_a_base_that_merely_ADVANCES_is_not_a_retarget(enumerate_files):
|
||||
def test_the_base_comparator_is_the_BRANCH_NAME_never_the_TIP_SHA():
|
||||
"""`.base.ref` is compared, never `.base.sha` — matching `post-review-verdict.sh` (ersatztv#632).
|
||||
|
||||
Comparing tips would fail every enumeration on every unrelated merge to `main`: a self-inflicted
|
||||
deadlock dressed as a security control. The stub always serves branch NAMES, so this passes only
|
||||
because the script never looks at a tip sha.
|
||||
deadlock dressed as a security control.
|
||||
|
||||
This is a STRUCTURAL assertion on purpose, and the previous version of this test is why. It was
|
||||
written behaviourally as `head_moves_to(SHA)` — the sha that was ALREADY current — so it modelled
|
||||
no movement at all and was simply a duplicate positive control. It would have passed just as
|
||||
happily against a script comparing tip shas. The stub serves only branch names, so no behavioural
|
||||
test in this harness can distinguish the two comparators; say so and assert the source instead.
|
||||
"""
|
||||
enumerate_files.set_pages(_rows(["docs/a.md"]))
|
||||
enumerate_files.head_moves_to(SHA) # head unchanged; base branch unchanged
|
||||
assert enumerate_files.paths() == ["docs/a.md"]
|
||||
src = SCRIPT.read_text()
|
||||
assert ".base.ref" in src, "the enumeration no longer reads .base.ref"
|
||||
binding = [ln for ln in src.splitlines()
|
||||
if "base_before=" in ln or "base_after=" in ln]
|
||||
assert binding, "no base binding assignments found"
|
||||
for ln in binding:
|
||||
assert ".base.ref" in ln and ".base.sha" not in ln, (
|
||||
f"the base binding compares a tip sha, which deadlocks on ordinary churn: {ln.strip()!r}")
|
||||
|
||||
|
||||
def test_a_SHORT_page_does_not_end_the_enumeration(enumerate_files):
|
||||
@@ -579,6 +589,11 @@ def test_the_caller_passes_the_BASE_REF_argument(caller):
|
||||
assert len(args) >= 5, (
|
||||
f"{caller.relative_to(REPO_ROOT)} calls the enumeration with {len(args)} quoted "
|
||||
f"arguments, expected 5 including the expected base ref: {ln.strip()!r}")
|
||||
# Counting five arguments is not enough — cold review caught that passing `"$SHA"` twice
|
||||
# satisfied the count while stalling every real exemption. Name the fifth.
|
||||
assert re.search(r'(?i)base', args[4]), (
|
||||
f"{caller.relative_to(REPO_ROOT)} passes {args[4]} as the 5th argument; it must be the "
|
||||
f"expected BASE ref: {ln.strip()!r}")
|
||||
|
||||
|
||||
@CALLERS
|
||||
@@ -1130,8 +1145,7 @@ def test_bot_positive_control_a_REAL_dependency_bump_IS_still_exempt(tmp_path):
|
||||
"would now stall waiting on a human verdict")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["Directory.Packages.props", ".config/dotnet-tools.json",
|
||||
"web/package.json", "web/package-lock.json"])
|
||||
@pytest.mark.parametrize("path", ["Directory.Packages.props", ".config/dotnet-tools.json"])
|
||||
def test_every_manifest_in_the_allow_list_is_actually_exempt(tmp_path, path):
|
||||
"""Pin the SET, not one example of it. A test that only ever exercises Directory.Packages.props
|
||||
cannot see a typo in any of the other three alternations."""
|
||||
@@ -1260,3 +1274,71 @@ def test_a_PENDING_status_from_a_previous_run_is_replaced_normally(tmp_path):
|
||||
status_creator=None, status_desc="Awaiting review verdict for a9e3e23")
|
||||
assert posted is not None
|
||||
assert posted["state"] == "success"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["web/package.json", "web/package-lock.json"])
|
||||
def test_the_npm_manifests_are_NOT_exempt(tmp_path, path):
|
||||
"""Cross-family review called an earlier draft's inclusion of these a Blocker, correctly.
|
||||
|
||||
`renovate.json` sets `enabledManagers: ["nuget", "github-actions", "dockerfile"]`, so Renovate does
|
||||
not manage npm here at all — the entry bought nothing. Meanwhile `package.json` carries `scripts`
|
||||
that CI EXECUTES (`npm ci`, `npm run build`), so exempting it lets a hijacked bot branch run
|
||||
arbitrary shell in CI while every path still matches a "manifest" allow-list. Widening an exemption
|
||||
to a code-execution vector for no operational benefit is strictly worse than the hole being closed.
|
||||
"""
|
||||
posted, _ = _run_classify(tmp_path, _emitting(path), author="renovate")
|
||||
assert posted is not None
|
||||
assert posted["state"] == "pending", (
|
||||
f"{path} was exempted; package.json scripts execute in CI, and npm is not a managed ecosystem "
|
||||
"in this repo")
|
||||
|
||||
|
||||
# --- The `grep -q` + `pipefail` inversion (found by cross-family review of this PR) ---------------
|
||||
#
|
||||
# `grep -q` exits at its FIRST match, so the upstream writer takes SIGPIPE (141) once the path list
|
||||
# exceeds the pipe buffer. Under `set -o pipefail` the pipeline is then a FAILURE even though grep
|
||||
# MATCHED, inverting every guard built on `printf … | grep -q`. Reproduced at 171KB / 1901 paths,
|
||||
# comfortably inside the enumerator's 2000-file cap.
|
||||
#
|
||||
# These are the regression guards, and they are the tests the original round did not have: every
|
||||
# earlier case used a handful of short paths, far below the buffer, so the whole class was invisible.
|
||||
# The construct PREDATES #698, so `main` carried this hole with no retarget or bot account required.
|
||||
|
||||
def _many_docs(n=1900):
|
||||
return [f"docs/{'d' * 40}-{i:040d}.md" for i in range(n)]
|
||||
|
||||
|
||||
def test_a_LARGE_pr_with_a_code_file_is_not_classified_docs_only(tmp_path):
|
||||
"""The code file goes FIRST so `grep -qv` matches immediately and the writer is left with ~171KB
|
||||
still to push — the exact shape that produced exit 141 and `docs_only=yes`."""
|
||||
posted, r = _run_classify(tmp_path, _emitting("A.cs", *_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending", (
|
||||
"a PR containing A.cs was exempted as docs-only because the classification pipeline was "
|
||||
f"inverted by SIGPIPE on a large file list (desc={posted['description']!r})")
|
||||
|
||||
|
||||
def test_a_LARGE_pr_touching_a_PROTECTED_path_still_voids_the_exemptions(tmp_path):
|
||||
"""The worse direction: here the inversion makes the PROTECTED guard MISS, so a PR editing the
|
||||
gate's own workflow falls through to the docs-only exemption and self-exempts."""
|
||||
posted, r = _run_classify(tmp_path, _emitting(".gitea/workflows/review-verdict.yml", *_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending", (
|
||||
"a PR editing .gitea/workflows/ was exempted — the protected-path guard was skipped on a "
|
||||
f"large file list (desc={posted['description']!r})")
|
||||
|
||||
|
||||
def test_a_LARGE_bot_pr_with_a_code_file_is_not_manifest_exempt(tmp_path):
|
||||
"""The same inversion reached through the third guard added by this change."""
|
||||
posted, r = _run_classify(tmp_path, _emitting("A.cs", *_many_docs()), author="renovate")
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending"
|
||||
|
||||
|
||||
def test_positive_control_a_LARGE_genuinely_docs_only_pr_IS_still_exempt(tmp_path):
|
||||
"""Without this the three tests above could pass because large lists now fail outright, which
|
||||
would be a merge deadlock rather than a fix."""
|
||||
posted, r = _run_classify(tmp_path, _emitting(*_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "success", (
|
||||
f"a large but genuinely docs-only PR lost its exemption (desc={posted['description']!r})")
|
||||
|
||||
Reference in New Issue
Block a user