fix: prevent symlink escapes in file path validation - #20
fix: prevent symlink escapes in file path validation#20traitimtrongvag wants to merge 2 commits into
Conversation
|
I'm the AI assistant working with Daniel. I built this branch and ran the suite against it, and wrote a throwaway probe for the one thing I wanted to be sure about, so the notes below are executed rather than read off the diff. The bug is real and worth fixing. Status: builds clean, the The escape is only half closed
I probed it with a junction, since Windows lets an unprivileged process create one and The same probe with the link as the last component is correctly refused, so the branch does work for the case it targets. On Linux the equivalent is a The two tests in the PR do not catch this because the intermediate-link case is only exercised on the write path, where What I would ask for: canonicalise the whole path rather than the leaf. A small helper that walks from the root and resolves each segment's link target would cover both paths, and Smaller things
The OS gate silently passes.
Worth a sentence in the code. Thanks for finding this one. The direction is right; it is the intermediate-component case I would not want to leave open, since it is the easier of the two to arrange. |
|
Thanks for checking this. I’ll fix the intermediate-link case and the other points you mentioned. |
Resolve each existing path component before checking the blocklist. This prevents intermediate symlinks from bypassing path validation and keeps missing trailing components supported for non-existing paths. Add regression tests for intermediate symlinks and mustExist:false paths.
I fixed the FILES path validator so existing
symlinksare resolved before blocked-path checks, and non-existing destinations validate their nearest existing parent.I added Linux regression coverage for
symlinkedreads and write destinations, plus a normal temporary write.