Stop a crafted path from replacing another file's diff in the gathered review context
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Why we make these changes
scripts/gather-review-context.sh (douwebot) and its fork scripts/gather-pydantic-ai-review-context.sh (CI Review, UI Security Review) split a PR's diff into one file per changed path under diff/, and changed-files.txt names each path's diff in its third column. A crafted path could make a row name the wrong diff, so the reviewer read a decoy in place of the real change:
- Names.
/became__and leading dots were stripped, sopydantic_ai_slim/pydantic_ai/_ssrf.pyand a root-levelpydantic_ai_slim__pydantic_ai___ssrf.pyshared one diff, as did.github/ci.ymlandgithub/ci.yml. - Header parsing. The path was cut after the last
b/ofdiff --git a/P b/P, so a craftedz b/src.pywas read assrc.py. A path git quotes (non-ASCII,",\, control characters) got a mangled name that no row named. - Forged rows. douwebot's index was built by string interpolation, so a filename with a tab and a newline (
src.py<TAB>+1 -0<TAB>diff/evil.diff<LF>zz) wrote a wholesrc.pyrow naming another file's diff.
Now:
- Both scripts percent-encode
%,\,/, tab, newline, carriage return and a leading.in names, in the awk writer and the jq index alike. - The awk holds each file's lines until its extended header ends. A rename or copy names its new path in
rename to/copy to; any other header repeats one path, so the path is its first half. A quoted path is unquoted, and the diff runs withcore.quotePath=false. - douwebot's index uses
@tsv, like CI Review's. Its path column now escapes a\, tab, newline or carriage return, as CI Review's already did. shared/review-context.mdand both review prompts point at the third column ofchanged-files.txtfor each diff's name. The two importing locks are recompiled with gh-aw v1.2.1.
New public surface
None.
User-visible behavior
changed-files.txt for a PR adding both crafted paths:
-pydantic_ai_slim/pydantic_ai/_ssrf.py +1 -0 diff/pydantic_ai_slim__pydantic_ai___ssrf.py.diff
+pydantic_ai_slim/pydantic_ai/_ssrf.py +1 -0 diff/pydantic_ai_slim%2Fpydantic_ai%2F_ssrf.py.diff
pydantic_ai_slim__pydantic_ai___ssrf.py +1 -0 diff/pydantic_ai_slim__pydantic_ai___ssrf.py.diff
Verification
test_a_crafted_path_cannot_replace_another_files_diff runs both gatherers on one PR holding every case above: colliding names, b/ paths, a crafted rename, non-ASCII, "/\/tab paths, x\y next to x\\y, and the forged-row filename. It checks that the index lists each path once and that each row's diff adds exactly that path's lines. It fails on main for both scripts. The existing gather tests and agentic_workflow_guard.py check pass.
What changes for existing users
Nothing in the library. Review-context readers still find each file's diff in the third column of changed-files.txt; only its spelling changes. douwebot fetches its gatherer from the base ref, so it picks this up once merged.
Three pre-existing gaps in the same scripts (an unanchored generated-file skip, typechange truncation, gh pr diff fallback quoting) are tracked in #12896 for a follow-up PR after this one.
PR decisions
2026-11-08 · Percent-encode diff names · iter -
- Decision: Name each per-file diff by percent-encoding
%,/and a leading.(a/b.py->a%2Fb.py.diff) - Why: Injective and decodable with urllib.parse.unquote; underscore escaping (
_->_u) garbles the many underscores in Python paths; a hash suffix needs a hash in awk - Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · pre-push review 1 of 3 at 71c0b65c1e619d9892ec8eb820ffa9cae1b97207 · iter -
- Decision: reserved; dispatching light-tier fresh reviewer
- Why: tree 8f8ffbf6a61d926f15fc58e2d2937d68741015a7; scope 0bb132ff7c..71c0b65c1e (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · pre-push review 1 of 3 at 71c0b65c1e619d9892ec8eb820ffa9cae1b97207 · iter -
- Decision: 1 finding: shared/review-context.md and two shared/prompts describe the name as diff/
- Why: tree 8f8ffbf6a61d926f15fc58e2d2937d68741015a7; scope 0bb132ff7c..71c0b65c1e; fix pulls .github/workflows (second code-owner approval) and two lock recompiles into a scripts-only PR; wording was equally imprecise before
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · Fold b/ header parse and docs · iter -
- Decision: Fold the
b/header-parse fix and the docs rewording (option a) into this PR - Why: Manager: same attack, same two scripts; "Code that changes the diff naming must not ship with docs describing the old names."
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · Name each diff from its extended header · iter -
- Decision: Hold each file's lines until its extended header ends; take a rename/copy target from
rename to/copy to, else the first half ofa/P b/P - Why: Only renames and copies have different a/ and b/ paths, and they always name the new path; a per-path git diff loop would turn renames into full adds
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · pre-push review 2 of 3 at fa955f68239e230afe397729b8aae18f6091da14 · iter -
- Decision: reserved; dispatching light-tier fresh reviewer
- Why: tree e579060431815e0f471c8f45e16aafcb8efc2597; scope 71c0b65c1e..fa955f6823 plus full branch as context; verifies review-1 docs finding
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-08 · pre-push review 2 of 3 at fa955f68239e230afe397729b8aae18f6091da14 · iter -
- Decision: no findings (current at fa955f68239e230afe397729b8aae18f6091da14); review-1 docs finding verified fixed
- Why: tree e579060431815e0f471c8f45e16aafcb8efc2597; scope 71c0b65c1e..fa955f6823 + full branch context; reviewer read diffs only, its Bash calls were denied
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · exempt delta 4ccb2118f0 from reviewed fa955f6823 · iter -
- Decision: lock recompile is repo tooling output; no review
- Why: gh aw v1.2.1 compile of the two workflows on clean fa955f6823 produced exactly HEAD's tree; only body_hash lines changed; guard passes
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/review-context-diff-names
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · Unquote non-ASCII paths in the diff · iter -
- Decision: Run the gatherers' git diff with -c core.quotePath=false
- Why: With default quoting a non-ASCII path's header is quoted, the new header parse cannot name it, and its diff is dropped; before, it was written under a mangled name. Found in self-check after push
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · pre-push review 3 of 3 at c76ccbd6d4c63c85189b8624dbeabaa59c89e11f · iter -
- Decision: reserved; dispatching light-tier fresh reviewer
- Why: tree b9913ccf747417c5f8a7f102856670cf90c95a05; scope fa955f6823..c76ccbd6d4 (lock recompile exempt; quotePath fix); policy base c9c896e9f0
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · pre-push review 3 of 3 at c76ccbd6d4c63c85189b8624dbeabaa59c89e11f · iter -
- Decision: 1 finding: a path git still quotes (
",\\, control chars) gets no diff; remediating by unquoting in awk; budget exhausted, no fourth review - Why: tree b9913ccf747417c5f8a7f102856670cf90c95a05; scope fa955f6823..c76ccbd6d4; on main such a diff was written under a mangled name, on head it was dropped
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · Review-3 quoted-path finding is a sibling, not a regression · iter -
- Decision: Park the awk unquote fix (scratchpad); hold local c76ccbd6d4 (quotePath) unpushed; report both plus a verified douwebot index row forge to the manager
- Why: On main a quoted-header path's diff was written under a name no index row names, so the index already could not reach it; unquote alone would let CI Review's @tsv-escaped column 3 point x\y's row at x\\y's diff
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · Fold quotePath, quoted-path unquote and forged-row fix · iter -
- Decision: Fold all three siblings: core.quotePath=false; unquote git's C-style paths in awk; build douwebot's index with @tsv and percent-encode \, tab, LF, CR in names
- Why: Manager: each reproduces on main, shares this PR's root cause, and "changes output only for paths that already fail on main"
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · Encode index-escaped characters in diff names · iter -
- Decision: Percent-encode
\\(%5C), tab (%09), LF (%0A) and CR (%0D) in diff names, in awk and jq - Why: @tsv escapes exactly those in column 3; encoding them leaves column 3 equal to the written file name, so an escaped name cannot point at another path's diff
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · Adversarial verifier replaces a fourth review · iter -
- Decision: Pre-push budget spent: remediate, run local checks, then one fresh adversarial-verifier on the final candidate; no fourth pre-push review
- Why: Manager instruction; properties: each row names its own path's diff, no crafted path redirects or forges another row, both gatherers agree
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · adversarial verifier at 4f397ef242e9ee574c05bfd8bf7cf96a6b20bf8f · iter -
- Decision: dispatching fresh strong-tier verifier
- Why: tree 98b13a7d400721a865ba9a3863c3054ccf6cf011; full branch 0bb132ff7c..4f397ef242; manager-requested, not a pre-push review
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · adversarial verifier at 4f397ef242e9ee574c05bfd8bf7cf96a6b20bf8f · iter -
- Decision: all three properties hold (code reading; its Bash was denied); four pre-existing gaps reported to manager, not folded
- Why: tree 98b13a7d400721a865ba9a3863c3054ccf6cf011; gaps: typechange sections truncate one file, gh pr diff fallback drops octal-escaped non-ASCII, NAME_MAX (+1 byte per slash; longest repo path encodes to 163), unanchored uv.lock/cassettes skip hides e.g. cassettes/conftest.py
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · defer: generated-file skip, typechange, fallback quoting · iter -
- Decision: Filed as #12896 (assigned dsfaccini, pydanty:skip; immediate-work route) for one follow-up PR after #12894 merges
- Why: Out of scope for this PR: each changes what lands in a diff or which files count as generated; the fallback item is unverified; same lines, so doing it now would conflict
- Source: https://github.com/pydantic/pydantic-ai/issues/12896
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · skip: NAME_MAX on encoded diff names · iter -
- Decision: Skip: a path whose encoded name exceeds 255 bytes aborts the gather
- Why: No real path reaches the limit (longest tracked path encodes to 163 bytes), and a crafted overlong path aborts the gather (fails closed) on main too
- Source: https://github.com/pydantic/pydantic-ai/issues/12896
- Session: cf2ce080-49f1-4629-944e-b229219a889d
2026-11-09 · #12859 decodes the @tsv path column · iter -
- Decision: Whichever of #12859 and #12894 merges second makes #12859's runner decode the @tsv column 1 of changed-files.txt
- Why: This PR builds douwebot's index with @tsv, so a path with a backslash, tab, newline or CR appears escaped in column 1, which #12859 compares to API filenames
- Source: https://github.com/pydantic/pydantic-ai/pull/12859
- Session: cf2ce080-49f1-4629-944e-b229219a889d
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.