Repository navigation
fix(review): screen content filters before the probe tree's restore too (#9558) #9741
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 2 commits
971494d
a25e8e6
1fe2fae
49ba19a
c06aab3
4c5bff7
c959a08
c137f03
deba877
8cfb0ab
5258b5e
c9cec1e
eb6a46b
1567ea0
7e65377
ad017a8
526575b
832ad51
776e147
377ec3a
4c4eca3
90e1494
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 |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
|
|
||
| import { spawnSync } from 'node:child_process'; | ||
| import { | ||
| accessSync, | ||
| constants, | ||
| existsSync, | ||
| lstatSync, | ||
| mkdtempSync, | ||
|
|
@@ -34,6 +36,7 @@ import { | |
| } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { basename, dirname, isAbsolute, join, resolve, sep } from 'node:path'; | ||
| import { inertPath } from './paths.js'; | ||
| import { readWorkspacePackages } from './workspaces.js'; | ||
|
|
||
| export type SweepResult = ReturnType<typeof spawnSync>; | ||
|
|
@@ -557,6 +560,164 @@ function trackedIgnoreSources(cwd: string, sources: Set<string>): Set<string> { | |
| return new Set(r.stdout.split('\0').filter((p) => p.length > 0)); | ||
| } | ||
|
|
||
| /** | ||
| * The refusal for a checkout about to run through a repo-local content filter — | ||
| * or through a repo-local config file the screen could not read — and null | ||
| * when the screen came back clean. `checkout` is the noun phrase naming the | ||
| * checkout being authorised ("this tree's restore", "the revert checkout"); it | ||
| * lands in the message verbatim. | ||
| * | ||
| * Every checkout in this pipeline EXECUTES these filters — the scratch tree's | ||
| * reset and rebuild, the probe tree's creation, per-run restore and revert | ||
| * checkouts — 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 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. `--file` likewise does not expand | ||
|
Comment on lines
+757
to
+759
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 next round with the plan fixed: snapshot the reviewer's global config before the first suite run, redirect 中文说明延后到下一轮,方案已确定:在第一次套件运行前快照审阅者的全局配置,在每个管线 git spawn 上把 |
||
| * `include.path`/`includeIf.*.path`, so a filter planted behind an include is | ||
| * invisible here; the origin-scoped follow-up tracked on this PR closes that — | ||
|
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. Still deferred, as this PR documents — the mechanism is unchanged at this round's commit and the fix (an origin-scoped merged read via 中文说明仍然推迟,与本 PR 的记载一致——该机制在本轮提交上未变,修复(按来源限定的
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. Still open and tracked, unchanged this round — the interim fail-closed treatment stands: any 中文说明本线程仍然开放且处于跟踪状态,本轮未变——过渡期的失败关闭处理保持不变:屏蔽候选文件中的任何 |
||
| * `--includes` or merged config would follow the include into the user's | ||
| * global config and re-import `filter.lfs.clean`, the permanent-refusal | ||
| * failure. 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 localFilterRefusal( | ||
| worktree: string, | ||
| checkout: string, | ||
| ): string | null { | ||
| 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 null; | ||
| } | ||
| const [commonDir, gitDir] = files.stdout.trim().split('\n'); | ||
| const common = resolve(worktree, commonDir); | ||
|
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 next round — this round's batch was capped at the seven Critical findings (plus the two Suggestions entangled with them). The 中文说明推迟到下一轮——本轮批次以七个 Critical 发现(加上与其纠缠的两个 Suggestion)为上限。带换行路径见证的 |
||
| 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 can run in ANOTHER | ||
| // tree — the SCRATCH tree, the probe 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 filters: Array<{ key: string; file: string }> = []; | ||
| // Neither a config key nor a path can carry NUL, so the pair separator is | ||
| // unambiguous — and an O(1) dedup, because a padded config can hand this | ||
| // loop tens of thousands of keys. | ||
| const seen = new Set<string>(); | ||
| const unreadable: Array<{ file: string; detail: string }> = []; | ||
| for (const file of candidates) { | ||
| if (!existsSync(file)) continue; | ||
| // An unreadable file fails the screen CLOSED, asked directly: git answers | ||
| // an unreadable `--file` with the SAME exit 1 as "no keys matched" (and a | ||
| // warning on stderr), so the exit code cannot tell the two apart — and a | ||
| // screen that could not read a file cannot certify the checkout that will. | ||
| try { | ||
| accessSync(file, constants.R_OK); | ||
| } catch (e) { | ||
|
Comment on lines
+928
to
+940
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 next round — this round's batch was capped at the seven Critical findings (plus the two Suggestions entangled with them). The 中文说明推迟到下一轮——本轮批次以七个 Critical 发现(加上与其纠缠的两个 Suggestion)为上限。 |
||
| unreadable.push({ | ||
| file, | ||
| detail: e instanceof Error ? e.message : String(e), | ||
| }); | ||
| continue; | ||
| } | ||
| const r = spawnSync( | ||
| 'git', | ||
| [ | ||
| 'config', | ||
| '--file', | ||
|
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, in line with this finding's own framing. The gap is real and was reproduced here too: 中文说明按该发现本身的定位,推迟到后续队列处理。缺口真实存在,本轮也已复现:
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. Still open and tracked, unchanged this round — the interim fail-closed treatment stands: any 中文说明本线程仍然开放且处于跟踪状态,本轮未变——过渡期的失败关闭处理保持不变:屏蔽候选文件中的任何 |
||
| file, | ||
| '--get-regexp', | ||
|
Comment on lines
+950
to
+959
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. Still open and tracked, unchanged this round — the interim fail-closed treatment stands: any 中文说明本线程仍然开放且处于跟踪状态,本轮未变——过渡期的失败关闭处理保持不变:屏蔽候选文件中的任何 |
||
| // `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)$', | ||
| ], | ||
| { | ||
| cwd: worktree, | ||
| encoding: 'utf8', | ||
| // Padding beside a planted key pushes the output past spawnSync's | ||
| // 1 MiB default: ENOBUFS, and the `continue` that used to follow | ||
| // certified — and ran — a checkout the screen had never read. The | ||
| // 64 MiB ceiling the other readers in these files already use. | ||
| maxBuffer: 64 * 1024 * 1024, | ||
| env: sanitizedGitEnv(), | ||
| }, | ||
| ); | ||
| // Exit 1 is the legitimate "no keys matched"; every other failure on a | ||
| // file that EXISTS and was readable — a spawn error, a malformed config | ||
| // git exits 128 on — is a read the screen cannot vouch for. | ||
| if (r.status === 1) continue; | ||
| if (r.error || r.status !== 0 || typeof r.stdout !== 'string') { | ||
| unreadable.push({ | ||
| file, | ||
| detail: r.error | ||
| ? r.error.message | ||
| : (r.stderr ?? '').toString().trim() || | ||
| `git config exited ${r.status}`, | ||
| }); | ||
| continue; | ||
| } | ||
| for (const line of r.stdout.split('\n')) { | ||
| const key = line.split(/\s+/)[0]; | ||
| const pair = `${file}\u0000${key}`; | ||
| if (key && !seen.has(pair)) { | ||
| // The defining file rides along: with `extensions.worktreeConfig` a | ||
| // filter can live only in a SIBLING worktree's config.worktree, and a | ||
| // refusal that lists keys alone points at nothing the oncall's first | ||
| // move — `git config --local --get-regexp '^filter\.'` in the review | ||
| // worktree — can see. | ||
| seen.add(pair); | ||
| filters.push({ key, file }); | ||
| } | ||
| } | ||
| } | ||
| if (filters.length === 0 && unreadable.length === 0) return null; | ||
| // Keys and paths arrive from config files a probe can write, so both go | ||
| // through `inertPath` the way `scratch-tree`'s note always has: a caught | ||
| // attacker still controls the bytes naming the catch, and they reach the | ||
| // terminal and the report the next agent treats as authoritative. | ||
| const parts: string[] = []; | ||
| if (filters.length > 0) { | ||
| parts.push( | ||
| `the repository's local config defines content filter(s) ${filters | ||
| .map((f) => `${inertPath(f.key)} (in ${inertPath(f.file)})`) | ||
|
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 next round — this round's batch was capped at the seven Critical findings (plus the two Suggestions entangled with them). The control-character witness for the 中文说明推迟到下一轮——本轮批次以七个 Critical 发现(加上与其纠缠的两个 Suggestion)为上限。 |
||
| .join(', ')} — ${checkout} would EXECUTE them`, | ||
|
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 next round — this round's batch was capped at the seven Critical findings (plus the two Suggestions entangled with them), and implementing the bounded enumeration with its own witness did not make the cut. It is first in the queue for the next round. 中文说明推迟到下一轮——本轮批次以七个 Critical 发现(加上与其纠缠的两个 Suggestion)为上限,实现带上限的枚举及其自身见证未能排入。它是下一轮队列中的第一项。 |
||
| ); | ||
| } | ||
| if (unreadable.length > 0) { | ||
| parts.push( | ||
| `the repository's local config could not be read (${unreadable | ||
|
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. Partially addressed this round. The unreadable-list join is now capped at 中文说明本轮已部分处理。unreadable 列表的 join 现在以 |
||
| .map((u) => `${inertPath(u.file)}: ${inertPath(u.detail)}`) | ||
| .join( | ||
| '; ', | ||
| )}), so the screen cannot certify that ${checkout} would not EXECUTE a content filter`, | ||
| ); | ||
| } | ||
| return parts.join('; '); | ||
| } | ||
|
|
||
| /** | ||
| * The paths a tree carries that its HEAD commit does not — probe residue, seen | ||
| * from the reading side (#9207). | ||
|
|
||
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.
Not implemented this round — explicitly deferred to the next. The fix (snapshotting the reviewer's global config before the first suite run and redirecting
GIT_CONFIG_GLOBALto the snapshot on every pipeline git spawn, withGIT_CONFIG_NOSYSTEM=1) touches every pipeline spawn's env plumbing and needs its own careful batch with witnesses for both the snapshot and the redirect; the round batch was bounded at ~8 findings. The erroneous premise in the docstring ('a probe's planting surface is the repo-local files') will be corrected together with that fix. The thread stays open.中文说明
本轮未实现——显式延后到下一轮。修复方案(在第一个套件运行前快照评审者的全局配置,并让每个管线 git spawn 把
GIT_CONFIG_GLOBAL重定向到该快照、附带GIT_CONFIG_NOSYSTEM=1)触及每个管线 spawn 的环境管道,需要自己独立的一批,并为快照与重定向各自配见证;本轮批次以约 8 条发现为上限。docstring 里的错误前提('探针的植入面是仓库本地文件')将随该修复一并更正。线程保持开放。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 next round with the plan fixed: snapshot the reviewer's global config before the first suite run, redirect
GIT_CONFIG_GLOBALto the snapshot on every pipeline git spawn, and setGIT_CONFIG_NOSYSTEM=1. This round's batch was bounded (~8 findings, Critical-first); this fix touches the environment of every pipeline git spawn and warrants its own round rather than a squeezed implementation. Not declined — the gap is real and remains tracked.中文说明
延后到下一轮,方案已确定:在第一次套件运行前快照审阅者的全局配置,在每个管线 git spawn 上把
GIT_CONFIG_GLOBAL重定向到该快照,并设置GIT_CONFIG_NOSYSTEM=1。本轮批次受限(约 8 项、Critical 优先);该修复触及每个管线 git spawn 的环境,值得单独一轮而非仓促实现。不是拒绝——缺口真实存在并继续被跟踪。