Repository navigation
fix(freeze): canonicalize non-existent subdirectories, intermediate symlinks, and tilde paths in check-freeze.sh - #3624
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
…ymlinks, and tilde paths in check-freeze.sh
795a6d7 to
03edff4
Compare
|
Thank you for this fix. A crew lane is picking it up to land on current main with Co-authored-by credit to you. |
|
Thanks @Quinnod345. Your idea of walking every path component is what shipped. We rewrote it on current main as #3758 so it also fails closed on symlink loops, long link chains and Windows path forms. That merged as 510dd07 in v1.92.9.0 and credits you with Co-authored-by. Closing this one as superseded. |
|
Thanks @capy-ai! Glad the path traversal approach helped secure the freeze boundary, and appreciate the Co-authored-by credit in v1.92.9.0! |
Fixes #3623
Why (in your own words)
/freezeis supposed to keep edits inside one directory, but_resolve_pathinfreeze/bin/check-freeze.shonly canonicalizes the parent directory when it already exists. When a Write targets a directory that does not exist yet, the raw string goes to the prefix check, so<boundary>/../outside/new-dir/x,<boundary>/out-link/new-dir/x(whereout-linkpoints outside) and<boundary>/..are all allowed. The same gap falsely denies a new subdirectory when the boundary sits under a symlinked parent like macOS/tmp. Separately,file_pathnever gets the~expansion that the freeze dir gets, so~/.zshrcis joined onto cwd and allowed whenever cwd is inside the boundary.This PR makes
_resolve_pathwalk the path one component at a time (collapsing./..and following symlinks at any depth, same 40-hop cap), then runpwd -Pon the deepest directory that exists and reattach the rest. It also expands a leading~onfile_pathand swapssed 's|/\+|/|g'forsed 's|//*|/|g', because BSD sed reads\+as a literal+.Live evidence
Script: a boundary at
$T/home/proj/src($Tis the physical temp dir, since/tmpitself is a symlink on macOS), anout-linksymlink inside it pointing at$T/outside, andHOME=$T/home. Each line is the hook's decision for a Write to that path.The last line is the boundary saved as
/tmp/fz/home/proj/src, so it only reproduces on macOS. BSD sed on macOS 27.2:Tests:
The 3 new tests in
test/hook-scripts.test.tsfail on main (3 of 3 new tests fail; running both suites against main'sfreeze/bin/check-freeze.shon macOS gives310 pass, 2 skip, 5 fail) and pass here. The 2 skips are the existing Windows-only tests.Scope
_resolve_pathand the~expansion / sed line infreeze/bin/check-freeze.sh, plus 3 tests intest/hook-scripts.test.ts. The resolved paths now go into_RESOLVED_FILE/_RESOLVED_FREEZE, so the deny message shows the path as the tool sent it (after~expansion) instead of the resolved one...and~tests are not, sowindows-free-testswill be their first Windows run.Liveness proof (required for external contributors)
Checklist
GSTACK PRtyped live into a real surface) or PR author is @garrytan (owner exemption)