Repository navigation
fix(trash): reject POSIX-absolute names on Windows too - #347
Merged
Merged
Conversation
validateTrashName blocks absolute trash names with filepath.IsAbs, but that predicate is platform-dependent: on Windows "/absolute/path" carries no volume, so IsAbs reports false and MoveToTrash accepted a name the guard documents as rejected. A leading separator is never a valid trash name on any platform, so reject it explicitly. The security helper compared filepath.Rel output against a slash-form allow-list, which never matches on Windows, so every case in TestMoveToTrash_RejectsTraversal also reported the untouched canary file as "written outside base"; normalizing with filepath.ToSlash keeps the assertion truthful on both platforms.
Owner
|
@codex review |
runkids
approved these changes
Oct 3, 2026
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two Windows-only defects in
internal/trash, both from separator/IsAbsassumptions.1.
validateTrashNamelets an absolute name through. It rejects absolute names withfilepath.IsAbs, but that predicate is platform-dependent — on Windows/etc/passwdcarries novolume, so
IsAbssays it is relative.MoveToTrashthen accepted a name the guard documents asrejected. A leading
/is never a valid trash name on any platform, so it is now rejectedexplicitly; on Unix
IsAbsalready covered it, making the change a no-op there.2. The security test helper never matches on Windows. It compares
filepath.Reloutputagainst a slash-form allow-list, and
filepath.Relreturns OS-native separators, so on Windowsoutside\canary.txtnever equals"outside/canary.txt". The result inverts the assertion: thehelper's own expected canary file is reported as an escape, so three tests fail with
unexpected file outside basepointing at a path that is inside the base — includingTestMoveAgentToTrash_AllowsNestedName, a positive case that has nothing to do with traversal.Normalizing with
filepath.ToSlashrestores the intended comparison.Part of #344.
Tests
On a
windows/amd64build of./internal/trash, stock7043ca3areports:TestMoveToTrash_RejectsTraversal/TestRestoreAgent_RejectsTraversal—expected error for traversal entry nameon theAbsolutePathcases (defect 1)TestMoveAgentToTrash_AllowsNestedName,TestCleanup_PathTraversal—unexpected file outside basefor a file inside the base (defect 2)With this commit the package is green on Windows and unchanged on Linux.