Skip to content

Keep quoted file names with secrets in review (GST-1451) - #4203

Merged
capy-ai[bot] merged 3 commits into
mainfrom
capy/keep-quoted-file-names
Nov 9, 2026
Merged

capy-ai[bot] merged 3 commits into
mainfrom
capy/keep-quoted-file-names

Conversation

@garrytan

@garrytan garrytan commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

A data file whose name git quotes in patch headers no longer slips past the secret-line keep rule in review_exclude_paths, so a credential value in such a file reaches every reviewer like any other.

What changed

Before: on a base policy of {"review_exclude_paths":["r/**"]}, a branch adding r/q"x.json with a credential value had that file excluded from every reader's diff. The same content at r/s.json was kept.
After: both are kept as secret-line. A quoted or UTF-8 name with no secret is still excluded.

  • The collector decodes quoted patch headers. core.quotePath=false only stops git escaping bytes of 0x80 and above. git still C-quotes a ---/+++ header when the name holds a ", a backslash, a tab or another control byte, and -z doesn't change patch output, so the -U0 parser stored added lines under the quoted header text. lib/review-collect.ts now decodes those headers byte by byte (octal escapes, \", \\, \t and the rest, then UTF-8). It also pins --src-prefix=a/ --dst-prefix=b/ so a user's diff.noprefix or diff.mnemonicPrefix can't shift the slice, and records an empty added-lines entry for every file section it parsed.
  • The exclusion fails closed. In reviewExclude, a matched file that no rule keeps but that the collector has no record of (no per-path entry, or a text file with changed lines and no added-lines entry) is kept as consumer-scan-unavailable instead of being excluded.
  • The new tests skip on Windows. Windows cannot create file names holding a quote, a tab or a control byte, so the quoted-name block runs on Linux and macOS only; the rest of the file still runs everywhere.

Why

Credential values in excluded data files would never reach any reviewer, and only the file name decided whether they did.

Blast radius

The change is limited to readDiff in lib/review-collect.ts and the reason loop in reviewExclude. Every reviewExclude caller (gstack-review-plan, ship-receipt-depth) passes collector output, so the fail-closed check only fires when collector keys and git's listing disagree; two reviewers read every consumer of the added-lines map and found that the new empty entries change none of them (file:line read). The kept-reason set and the receipt schema are unchanged, and names without special characters parse exactly as before.

Tests

  • New in test/review-exclude-secret-value.test.ts: the collector keys added lines by the real path for five quoted names and a UTF-8 name. Quoted and UTF-8 names with a value line are kept, while quoted and UTF-8 names without one are excluded, and so are a deletion-only edit and a whole-file deletion, both through collectCommit+reviewExclude and through gstack-review-plan --json on the live tree. A matched file with no collector entry is kept as unread.
  • Failing first on 350d419: 3 of the new tests failed. The UTF-8-only case already passed there, because core.quotePath=false covers it, and it stays as a guard.
  • Focused suite run locally: review-exclude, review-collect, review-secret-excerpt, review-reader-selection, review-exclude-secret-value, review-plan-cli and module-size-ratchet, 129 pass and 0 fail. bun run typecheck is clean.
Agent notes
  • I chose decoding over -z/core.quotePath=false because neither changes how patch headers are quoted, so decoding is required for patch output. Mapping sections to numstat order would also work but couples two outputs.
  • On a branch that isn't valid UTF-8, the names come out as U+FFFD in both the numstat and the decoded headers, so the keys still agree.
  • The repro line from the issue (curl -H $OPENAI_API_KEY alone) only names a variable, and GST-1967 deliberately doesn't keep files for that, so the tests use a line that carries a value.

Test Coverage

All new code paths have test coverage: each of the 3 changed runtime files has a changed test naming it (deterministic coverage map, no audit reader).

  • Failing first on 350d419: 3 of the new tests in test/review-exclude-secret-value.test.ts failed; the UTF-8-only case already passed there and stays as a guard.
  • Tests ran: free carried from CI (see Test plan).

Pre-Landing Review

Pre-Landing Review: 1 issue, 1 fixed after the outside voice, 0 deferred, 2 noted.

  • Pass 1 (specialists testing, security and state machines, plus red team): no findings. Pass 2 on the fix range: no findings.
  • Outside voice (openai/gpt-6.1-sol, certified configuration): one blocking finding, verified against CI. The new quoted-name tests could not create their fixture files on Windows, and windows-scoped-shard failed with ENOENT on receipts/q"plain.json (run 42587806615). Fixed in 84447ed by skipping that describe block on win32.
  • Native adversarial voice: no blocking findings; its two notes are listed below.

Review notes

Below the blocking floor; recorded here and not fixed in this PR.

  • INFORMATIONAL lib/review-exclude.ts:370: the new p in text.added check also matches inherited object keys, so a root-level path named constructor or toString would read as seen. It can't be reached in practice, because such an extensionless name counts as code and is never excludable. Object.hasOwn would close it.
  • INFORMATIONAL lib/review-collect.ts:127 (pre-existing at the base): a root-level file named __proto__ makes the collector throw. It fails loudly, so nothing is excluded silently. Building the maps with Object.create(null) would close it.

Exploratory QA

Functional smoke on gstack-review-plan --json in an owned fixture repo (3 probes, pass):

  • A plain data edit under receipts/** is excluded (capture 001).
  • receipts/q"x.json with a credential value is kept as secret-line, and receipts/tab<TAB>plain.json with no secret is excluded (capture 002).
  • Negative control: the installed base build (350d419) excludes all three on the same fixture, which reproduces the bug (capture 003).

Octal-escaped and control-byte names are covered by the unit tests, not probed.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped. The eval selector lists dependents of lib/review-collect.ts and lib/review-exclude.ts as scheduled and release coverage, not PR passes.

Review bot comments

No review bot comments.

Scope Drift

Scope Check: CLEAN

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). This is a bug fix, exempt from plan review.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. The docs already match the change, so no edits were made.

Scope: committed diff 350d419..84447ed on capy/keep-quoted-file-names: lib/review-collect.ts (decodes C-quoted patch-header paths and pins the a/ and b/ prefixes), lib/review-exclude.ts (keeps a matched text file whose changed lines the collector holds no lines for, as consumer-scan-unavailable), a new test, docs/ship-policy.md and a changelog.d fragment. Nothing is staged, unstaged or untracked.

Documentation health:

  • docs/ship-policy.md: current. The branch updated the consumer-scan-unavailable row of the kept-reasons table for the new fail-closed case.
  • docs/review-policy.md: current. Its review_exclude_paths reader section is not affected.
  • docs/troubleshooting.md: current. No reason-code text changed.
  • changelog.d/keep-quoted-file-names-with-secrets-in-review.md: present and accurate. The parent owns it.

Coverage debt: none. The change is internal collector behavior, and its only public surface, the kept reason, is covered by the reference table in ship-policy.md.

Diagram drift: none. No diagrams reference the collector or the exclusion.

Test plan

  • bun run test (free lane): carried from CI run 42595036747/1 at tree 58140858799f, 1652 files, 36767 tests, green
  • bun --no-env-file test --timeout=30000 test/review-exclude-secret-value.test.ts: 8 pass, 0 fail
  • bun run typecheck:test: 812 known diagnostics, none new
Agent notes
  • Refs GST-1451
  • /ship fixed two CI failures at earlier heads: the test-code type-debt ratchet (TS2769 on an untyped kept reason, fixed in 215c6e0) and windows-scoped-shard (fixed in 84447ed).
  • The free-tests pull_request run hit tree_mismatch after main moved, so free-tests.yml was dispatched on the branch (run 42595036747) and carried.
  • Locally, test/review-collect.test.ts and test/review-exclude.test.ts hung past 580 s on this 4-core machine; two reviewers saw one 5 s timeout there that also fails at base 350d419. CI passed them.

Approvals

No approvals recorded for branch capy/keep-quoted-file-names.
Plan: exempt: bug fix (R65)

{
  "schema_version": 1,
  "pr": 4203,
  "head": "84447ed9f845a20334d9f1e45e66d8c21f792eb7",
  "version": "1.98.0.0",
  "base": "main",
  "gate": {
    "free": {
      "pass": 1652,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "free",
      "run": 42595036747,
      "attempt": 1,
      "tree": "58140858799f97b325dffd36ba1175f45fa408ad"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "58140858799f97b325dffd36ba1175f45fa408ad",
  "product_patch_id": "77c170ac43f7335677a8a47305e40a25cf879b17",
  "gstack_version": "1.98.0.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 38,
    "rules": "66e5174161eecc2c",
    "base": "350d4196c3444d81590d36cc2d8752be71cf19b6",
    "registry": "350d4196c3444d81590d36cc2d8752be71cf19b6",
    "gate_scan": {
      "tagged": 0,
      "head": "84447ed9f845a20334d9f1e45e66d8c21f792eb7"
    },
    "reasons": [
      "gate-class",
      "runtime=38"
    ],
    "risk": [],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @58140858799f (8 checks, current for 84447ed9f845)",
  "requires_remote": [
    "pregate.json/remote_gate: remote-gate tree=58140858799f tests=36767 skipped=2 runs=42595036747/1 profiles=ci-reuse/free-tests heads=84447ed9f845 verified=2026-11-09T09:48:01.633Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md against 350d4196..84447ed9"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 1,
    "deferred": 0,
    "noted": 0,
    "fixed": 1,
    "scope": "frozen",
    "rounds": 2,
    "ledgers_read": 3,
    "dispatches": {
      "specialist": 6,
      "red-team": 2
    }
  }
}

Open in Capy

The review collector now decodes git's C-quoted patch headers, so the secret-line keep rule reads the added lines of a file whose name holds a quote, backslash or control byte. reviewExclude also keeps a matched file the collector holds no lines for, as unread.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit d59a523 into main Nov 9, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant