Repository navigation
fix(review): pin the verified git identity across the residue probe (#9557) #9742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
cd727ad
44d50bb
d11aaa8
a439a36
cdbe6aa
8bc9c49
28bad8a
59f6b88
c80763e
6bdbf17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,10 +474,18 @@ interface IgnoreRule { | |
| function ignoreSourcesOf( | ||
| cwd: string, | ||
| paths: string[], | ||
| anchor: readonly string[] = [], | ||
| ): Map<string, IgnoreRule> | null { | ||
| const r = spawnSync( | ||
| 'git', | ||
| [...pipelineExcludeArgs(), 'check-ignore', '-z', '-v', '--stdin'], | ||
| [ | ||
| ...anchor, | ||
| ...pipelineExcludeArgs(), | ||
| 'check-ignore', | ||
| '-z', | ||
| '-v', | ||
| '--stdin', | ||
| ], | ||
| { | ||
| cwd, | ||
| input: `${paths.join('\0')}\0`, | ||
|
|
@@ -539,13 +547,17 @@ function hidesEverything(pattern: string): boolean { | |
| * out of the worktree is not asked about at all — `ls-files` would reject the | ||
| * pathspec, and unknown provenance is untrusted provenance. | ||
| */ | ||
| function trackedIgnoreSources(cwd: string, sources: Set<string>): Set<string> { | ||
| function trackedIgnoreSources( | ||
| cwd: string, | ||
| sources: Set<string>, | ||
| anchor: readonly string[] = [], | ||
| ): Set<string> { | ||
| const inside = [...sources].filter( | ||
| (s) => | ||
| s.length > 0 && !isAbsolute(s) && !s.split('/').some((p) => p === '..'), | ||
| ); | ||
| if (inside.length === 0) return new Set(); | ||
| const r = spawnSync('git', ['ls-files', '-z', '--', ...inside], { | ||
| const r = spawnSync('git', [...anchor, 'ls-files', '-z', '--', ...inside], { | ||
| cwd, | ||
| encoding: 'utf8', | ||
| maxBuffer: 64 * 1024 * 1024, | ||
|
|
@@ -557,6 +569,80 @@ function trackedIgnoreSources(cwd: string, sources: Set<string>): Set<string> { | |
| return new Set(r.stdout.split('\0').filter((p) => p.length > 0)); | ||
| } | ||
|
|
||
| /** | ||
| * The repo-local `filter.<name>` COMMANDS, when any are defined. | ||
| * | ||
| * Every checkout in this pipeline EXECUTES these — the scratch tree's reset and | ||
| * rebuild, and the probe tree's per-run restore — hooks being disabled covers | ||
| * hooks and not filters. The planting surface is two plain writes a probe can | ||
| * make into the COMMON dir this command's report calls shared: | ||
| * `git config filter.evil.smudge CMD` and one line appended to | ||
| * `$(git rev-parse --git-path info/attributes)`. discard and cleanup never | ||
| * wipe the common dir, so a filter planted while reviewing one PR fires on | ||
| * every later matching checkout of the user's OWN repository — persistence | ||
| * planted by reviewing a malicious PR, measured live. The two local config | ||
| * files are checked with `--file` rather than merged config because filters | ||
| * in the user's global config (git-lfs is the common one) are the user's own | ||
| * contract, exactly like any git command they run — while a probe's planting | ||
| * surface is the repo-local files. The state cannot be told apart from a | ||
| * filter the user set deliberately, and cannot be safely wiped, so a hit is a | ||
| * refusal upstream, not a cleanup here. | ||
| */ | ||
| export function localFilterCommands(worktree: string): string[] { | ||
| const files = spawnSync( | ||
| 'git', | ||
| ['rev-parse', '--git-common-dir', '--git-dir'], | ||
| { cwd: worktree, encoding: 'utf8', env: sanitizedGitEnv() }, | ||
| ); | ||
| if (files.error || files.status !== 0 || typeof files.stdout !== 'string') { | ||
| return []; | ||
| } | ||
| const [commonDir, gitDir] = files.stdout.trim().split('\n'); | ||
| const common = resolve(worktree, commonDir); | ||
| const candidates = [ | ||
| join(common, 'config'), | ||
| join(resolve(worktree, gitDir), 'config.worktree'), | ||
| ]; | ||
| // Every OTHER worktree's per-worktree config too. This screen runs against | ||
| // the review worktree, but the checkout it authorises runs in the SCRATCH | ||
| // tree, whose own `<common>/worktrees/<label>/config.worktree` is honored | ||
| // once `extensions.worktreeConfig` is on and was never read here — a filter | ||
| // planted there executed during the reset while this function reported the | ||
| // repository clean. The admin directory is one `readdir`, and a filter in | ||
| // any of these is a plant whichever tree carries it. | ||
| try { | ||
| for (const entry of readdirSync(join(common, 'worktrees'))) { | ||
| candidates.push(join(common, 'worktrees', entry, 'config.worktree')); | ||
| } | ||
| } catch { | ||
| // No linked worktrees registered: the two candidates above are all of it. | ||
| } | ||
| const found: string[] = []; | ||
| for (const file of candidates) { | ||
| if (!existsSync(file)) continue; | ||
| const r = spawnSync( | ||
| 'git', | ||
| [ | ||
| 'config', | ||
| '--file', | ||
| file, | ||
| '--get-regexp', | ||
| // `process` beside the pair: it is the third executable key (a | ||
| // long-running filter git speaks a protocol to), and enumerating two | ||
| // of three is how the first cut of this screen read as complete. | ||
| '^filter\\..*\\.(smudge|clean|process)$', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferred to the follow-up queue with R1-4. Verified: after this round dropped the dead export, this PR owns no filter-screen code at all — the only live copy is scratch-tree.ts's private two-key function, which predates this commit and is exercised by no test (scratch-tree.test.ts reaches it only through smudge keys). The prescribed tests — 中文说明与 R1-4 一并延迟到后续队列。已验证:本轮移除死导出后,本 PR 完全不再拥有过滤器筛查代码——唯一的活副本是 scratch-tree.ts 的私有两键函数,它早于本提交且没有任何测试覆盖(scratch-tree.test.ts 只经由 smudge 键触及它)。规定的测试——在三个候选位置(common config、本树的 config.worktree、兄弟 worktree 的 config.worktree)各植入一个 |
||
| ], | ||
| { cwd: worktree, encoding: 'utf8', env: sanitizedGitEnv() }, | ||
| ); | ||
| if (r.error || r.status !== 0 || typeof r.stdout !== 'string') continue; | ||
| for (const line of r.stdout.split('\n')) { | ||
| const key = line.split(/\s+/)[0]; | ||
| if (key && !found.includes(key)) found.push(key); | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
|
|
||
| /** | ||
| * The paths a tree carries that its HEAD commit does not — probe residue, seen | ||
| * from the reading side (#9207). | ||
|
|
@@ -652,20 +738,73 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| // add`, a cleanup whose `rmSync` failed — `status` exits 0 against the | ||
| // enclosing user checkout: the wrong tree's dirty state answered as this | ||
| // one's. Fail closed the way a loud git failure below does. | ||
| const top = spawnSync('git', ['rev-parse', '--show-toplevel'], { | ||
| cwd, | ||
| encoding: 'utf8', | ||
| env: sanitizedGitEnv(), | ||
| }); | ||
| const top = spawnSync( | ||
| 'git', | ||
| ['rev-parse', '--path-format=absolute', '--show-toplevel', '--git-dir'], | ||
| { cwd, encoding: 'utf8', env: sanitizedGitEnv() }, | ||
| ); | ||
| let isWorktree = false; | ||
| let anchor: string[] = []; | ||
| try { | ||
| const [toplevel, gitDir] = (top.stdout ?? '').trim().split('\n'); | ||
| isWorktree = | ||
| !top.error && | ||
| top.status === 0 && | ||
| typeof top.stdout === 'string' && | ||
| realpathSync(top.stdout.trim()) === realpathSync(cwd); | ||
| realpathSync(toplevel) === realpathSync(cwd); | ||
| if (isWorktree) { | ||
| // And the gitfile must name an admin entry that names this tree BACK. | ||
| // The pin below closes the window between this gate and the commands | ||
| // after it; it cannot help when the swap is already in place when the | ||
| // probe starts, because then the gate resolves the plant too — a | ||
| // repository whose `core.worktree` points here answers `--show-toplevel` | ||
| // with this path. `scratch-tree` gates its own reset on the round-trip | ||
| // for the same reason, and a planted standalone repo has no admin entry | ||
| // to round-trip at all. | ||
| // Its own try: a plant has no `gitdir` file to read, and letting that | ||
| // ENOENT fall into the outer catch reported it as "not a git worktree", | ||
| // which is a different and much vaguer thing than what was found. | ||
| let pointsBack = false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferred to the follow-up queue. The three divergent spellings are verified, and the cross-file dedup is the right end state — but it requires editing scratch-tree.ts, which this PR has never touched, so it is recorded for the follow-up that already owns that file (the filter-copy cluster above). One divergence is deliberate and worth pinning now so that dedup does not flatten it: 中文说明延迟到后续队列。三处分歧写法已验证,跨文件去重是正确的最终形态——但它需要修改本 PR 从未触碰过的 scratch-tree.ts,因此记入已经负责该文件的后续工作(上方的过滤器副本簇)。其中一处分歧是刻意的,现在钉住以免去重时把它抹平: |
||
| try { | ||
| const backpointer = readFileSync(join(gitDir, 'gitdir'), 'utf8').trim(); | ||
| pointsBack = | ||
| realpathSync(dirname(resolve(gitDir, backpointer))) === | ||
| realpathSync(cwd); | ||
| } catch { | ||
| // No admin entry at all — a standalone repository answering for this | ||
| // path, which is exactly the shape being refused. | ||
| } | ||
| if (!pointsBack) { | ||
| return { | ||
| paths: [], | ||
| total: 0, | ||
| unmeasured: | ||
| 'the .git gitfile names an admin entry that does not point back ' + | ||
| 'at this tree — the commands below would measure whichever ' + | ||
| 'repository it does name', | ||
| }; | ||
| } | ||
| // PIN the identity this gate just verified, for every spawn below. | ||
| // Without it the gate is one-shot: each later command re-discovers the | ||
| // repository through the same `.git` file the check read, and that file | ||
| // is writable by anything running as this user — so a gitfile swapped in | ||
| // afterwards, pointing at a repo whose index already holds the | ||
| // contamination, answers a clean `status` for a dirty tree. Measured: | ||
| // through discovery the swap certifies a mutant clean deterministically, | ||
| // with no race; pinned, the same tree still reports ` M a.ts` and the | ||
| // untracked probe file. Measured too, because a WRONG pin would be worse | ||
| // than none: across a standalone checkout, a linked worktree, a | ||
| // superproject with an initialised submodule and a worktree reached | ||
| // through a symlinked ancestor, all five commands below return | ||
| // byte-identical output pinned and unpinned. | ||
| anchor = [ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and deferred — with one open question for a maintainer. Confirmed at this commit: scratch-tree.ts and base-tree.ts have 0 changed lines, so issue 9557 would close at one third of its named scope. Extending the pin to both helpers is a multi-file change (gates, pins, tests, and for scratch-tree a non-circular sha source, which its caller can only get through new CLI plumbing) beyond this PR's declared single-commit scope — it is recorded in the follow-up queue so it is not lost at merge. The remaining half is not the bot's to do: should the PR body's 中文说明已验证并延迟——另有一个留给维护者的开放问题。本提交确认:scratch-tree.ts 与 base-tree.ts 改动行数均为 0,issue 9557 会在其点名范围的三分之一处被关闭。把固定扩展到这两个辅助模块是多文件改动(门、固定、测试,以及 scratch-tree 需要一个非循环的 sha 来源——其调用方只能通过新的 CLI 参数获得),超出本 PR 声明的单一提交范围——已记入后续队列,合并时不会丢失。剩下一半不是机器人能做的:合并前是否应把 PR 正文的 |
||
| `--git-dir=${realpathSync(gitDir)}`, | ||
| `--work-tree=${realpathSync(toplevel)}`, | ||
| ]; | ||
|
Comment on lines
+856
to
+859
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The overclaim is fixed in code: the round-trip and sha-pin comment blocks no longer say the pin "closes the window" — they now say it freezes NAMES, that a writer active between the pin and the measurement can still rewrite the pinned admin entry's HEAD/index/commondir or swap the tree path itself, and that this raises the attack's cost rather than closing it, with the structural close (a gate-time snapshot or a sandbox boundary) named as #9556. The trailing re-verification is NOT implemented this round: 中文说明过度声明已在代码中修正:round-trip 与 sha 固定的注释块不再声称 pin"关闭了窗口"——现在明确写明它冻结的是名字(NAMES),活跃在"固定→测量"窗口内的写入者仍可改写被固定 admin 条目的 HEAD/index/commondir,或掉包树路径本身;这只是提高攻击成本,并非关闭该类攻击,结构性关闭(门时快照或沙箱边界)指向 #9556。尾部再验证本轮未实现:
Comment on lines
+856
to
+859
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same disposition as the round-2 thread: the overclaim is fixed in code (the comments now state the pin freezes names, raises the attack's cost, and does not close the in-window class — the structural close is the sandbox boundary, #9556). The trailing re-verification is not implemented this round: the probe is fully synchronous, so no deterministic vitest witness can exercise the window, and an unwitnessed guard violates this repository's mutation-witness rule. If a maintainer wants the cost-raising re-check anyway, say so here and it comes back as a follow-up. 中文说明与第 2 轮线程的处置相同:过度声明已在代码中修正(注释现在写明 pin 冻结的是名字、只提高攻击成本、并不关闭窗口内类别——结构性关闭是沙箱边界,见 #9556)。尾部再验证本轮未实现:探针全程同步,vitest 中无法确定性演练该窗口,无见证的守卫违反本仓库的突变见证规则。若维护者仍希望加上这个提高成本的复查,请在此说明,将作为后续跟进项处理。 |
||
| } | ||
| } catch { | ||
| // A cwd that no longer resolves is not a tree this probe can measure. | ||
| isWorktree = false; | ||
| } | ||
| if (!isWorktree) { | ||
| return { | ||
|
|
@@ -679,6 +818,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| const r = spawnSync( | ||
| 'git', | ||
| [ | ||
| ...anchor, | ||
| ...pipelineExcludeArgs(), | ||
| // The measurement must not itself become the execution: `core.fsmonitor` | ||
| // runs a command on `status`, and this tree's config is writable by | ||
|
|
@@ -749,7 +889,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| // from the name. | ||
| const others = spawnSync( | ||
| 'git', | ||
| ['-c', 'core.fsmonitor=', 'ls-files', '--others', '-z'], | ||
| [...anchor, '-c', 'core.fsmonitor=', 'ls-files', '--others', '-z'], | ||
| { | ||
| cwd, | ||
| encoding: 'utf8', | ||
|
|
@@ -780,7 +920,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| extras.push(rec); | ||
| } | ||
| if (extras.length > 0) { | ||
| const hiddenBy = ignoreSourcesOf(cwd, extras); | ||
| const hiddenBy = ignoreSourcesOf(cwd, extras, anchor); | ||
| if (hiddenBy === null) { | ||
| return { | ||
| paths: paths.slice(0, cap), | ||
|
|
@@ -793,6 +933,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| const fromTheCommit = trackedIgnoreSources( | ||
| cwd, | ||
| new Set([...hiddenBy.values()].map((rule) => rule.source)), | ||
| anchor, | ||
| ); | ||
| for (const rec of extras) { | ||
| const rule = hiddenBy.get(rec); | ||
|
|
@@ -826,7 +967,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| // gitlink is certified clean. | ||
| const stage = spawnSync( | ||
| 'git', | ||
| ['-c', 'core.fsmonitor=', 'ls-files', '-s', '-z'], | ||
| [...anchor, '-c', 'core.fsmonitor=', 'ls-files', '-s', '-z'], | ||
| { | ||
| cwd, | ||
| encoding: 'utf8', | ||
|
|
@@ -884,7 +1025,7 @@ export function worktreeResidue(cwd: string, cap = 12): WorktreeResidue { | |
| // read as "no bits found" and fell through to a clean verdict. | ||
| const bits = spawnSync( | ||
| 'git', | ||
| ['-c', 'core.fsmonitor=', 'ls-files', '-v', '-z'], | ||
| [...anchor, '-c', 'core.fsmonitor=', 'ls-files', '-v', '-z'], | ||
| { | ||
| cwd, | ||
| encoding: 'utf8', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deferred to the follow-up queue (verified, not declined). The claim reproduces with real git:
git config --file <f> --get-regexpexits 1 on an[include]-plantedfilter.evil.smudgethat--includessurfaces, so the screen is blind to exactly the plant the checkout executes. This round dropped the deadlocalFilterCommandsexport from this PR per the review's request, so the PR no longer carries any filter-screen code — the hole lives in scratch-tree.ts's pre-existing live private copy, which is outside this PR's footprint. The--includesfix is recorded in the follow-up queue together with theprocesskey and the tests this copy still owes, so they land as one coherent change.中文说明
延迟到后续队列(已验证,非拒绝)。该论断用真实 git 复现成立:
git config --file <f> --get-regexp对经[include]植入的filter.evil.smudge返回 exit 1,而加上--includes即可见——筛查对 checkout 恰恰会执行的那种植入是盲的。本轮按评审要求把死导出localFilterCommands从本 PR 移除,因此本 PR 不再携带任何过滤器筛查代码——漏洞在 scratch-tree.ts 既有的活私有副本里,超出本 PR 足迹。--includes修复已与process键以及该副本仍欠的测试一并记入后续队列,作为一次完整的改动落地。