Repository navigation
Commit eb3f692
fix(security): frozen-tree symlink detection (TOCTOU-closed, closes #15)
Redesign after Codex+Claude review found the two-phase --raw detection in the
prior commit was TOCTOU-exploitable: patch was generated from the mutable index,
then a separate --raw check read the index again — a background process (a
compromised Codex run that can write to the worktree) mutated the index between
the two calls, so the patch carried a symlink while --raw reported clean, and
git apply replayed the symlink into repoRoot. Demonstrated at ~15% reliability
with a plain bash busy-poll. In-scope for #15's threat model (the worktree IS
the Codex workspace; Codex has write access and can spawn processes).
Fix: freeze the staged index into an IMMUTABLE tree via git write-tree, then
derive BOTH the patch and the symlink verdict from <baseCommit>..<tree> — never
from the mutable index. The two reads now reference the same immutable object, so
no window exists between them. Also add --no-ext-diff/--no-textconv so a poisoned
diff.external driver (writable via the linked-worktree shared commondir) cannot
affect patch generation.
Symlink detection: git diff-tree -r --raw on the frozen tree reports modes for
every changed entry; reject if either old or new mode column is 120000. Catches
new/retargeted/mode-changed/renamed symlinks uniformly; not subject to
diff.external/.gitattributes (structural mode data, not rendered text).
Leave-branch invariant preserved (worktree stays on refusal).
Regression tests (3, all green):
- existing tracked symlink retargeted → applied:false (the #19 bypass).
- new symlink (mode 120000) → caught.
- regular file whose content mentions "mode 120000" → applied (no false positive).
Verified: worktree 16/16; full npm test 159 pass / 4 pre-existing.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_0189cGaohsYdpkB4otKZnpAt1 parent 011ccc0 commit eb3f692
2 files changed
Lines changed: 57 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
375 | 382 | | |
376 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
377 | 387 | | |
378 | 388 | | |
379 | 389 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
390 | 398 | | |
391 | 399 | | |
392 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
0 commit comments