Skip to content

fix(trash): reject POSIX-absolute names on Windows too - #347

Merged
runkids merged 1 commit into
runkids:mainfrom
star-nebula:fix/trash-abs-name-on-windows
Oct 3, 2026
Merged

runkids merged 1 commit into
runkids:mainfrom
star-nebula:fix/trash-abs-name-on-windows

Conversation

@star-nebula

Copy link
Copy Markdown
Contributor

What

Two Windows-only defects in internal/trash, both from separator/IsAbs assumptions.

1. validateTrashName lets an absolute name through. It rejects absolute names with
filepath.IsAbs, but that predicate is platform-dependent — on Windows /etc/passwd carries no
volume, so IsAbs says it is relative. MoveToTrash then accepted a name the guard documents as
rejected. A leading / is never a valid trash name on any platform, so it is now rejected
explicitly; on Unix IsAbs already covered it, making the change a no-op there.

2. The security test helper never matches on Windows. It compares filepath.Rel output
against a slash-form allow-list, and filepath.Rel returns OS-native separators, so on Windows
outside\canary.txt never equals "outside/canary.txt". The result inverts the assertion: the
helper's own expected canary file is reported as an escape, so three tests fail with
unexpected file outside base pointing at a path that is inside the base — including
TestMoveAgentToTrash_AllowsNestedName, a positive case that has nothing to do with traversal.
Normalizing with filepath.ToSlash restores the intended comparison.

Part of #344.

Tests

On a windows/amd64 build of ./internal/trash, stock 7043ca3a reports:

  • TestMoveToTrash_RejectsTraversal / TestRestoreAgent_RejectsTraversal — expected error for traversal entry name on the AbsolutePath cases (defect 1)
  • TestMoveAgentToTrash_AllowsNestedName, TestCleanup_PathTraversal — unexpected file outside base for a file inside the base (defect 2)

With this commit the package is green on Windows and unchanged on Linux.

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.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner

@codex review

@runkids
runkids merged commit 968e321 into runkids:main Oct 3, 2026
7 checks passed
@star-nebula
star-nebula deleted the fix/trash-abs-name-on-windows branch October 3, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants