Fix path traversal in download_dir via server-controlled filenames#81
Merged
OscarAkaElvis merged 1 commit intoJun 1, 2026
Merged
Conversation
download_dir() uses filenames from Get-ChildItem stdout directly in File.join() to construct local paths. A rogue server can return names containing ../ sequences, writing files outside the download directory. Use File.basename() on server-supplied filenames for the local path to strip directory components while preserving the original name for the remote download path.
Collaborator
|
Thanks for the PR and for reporting this issue. Could you please re-submit the PR against the Once it is opened against Thanks again for the contribution. |
Author
|
Done -- rebased the PR to target |
Member
|
I've been doing some tests and everything looks good to me. Merging. |
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.
Summary
download_dir()parses filenames fromGet-ChildItemstdout and passes them directly toFile.join()to build local file paths../sequences (e.g.../../.ssh/authorized_keys), causing files to be written outside the intended download directoryFile.joindoes not sanitize traversal sequences:File.join("/home/user/loot", "../../.ssh/authorized_keys")resolves to/home/user/.ssh/authorized_keysFix
Use
File.basename()on server-supplied filenames for the local path construction only. The remote download path still uses the original filename so the correct file is fetched. Entries that resolve to empty,., or..are skipped.Steps to reproduce
Get-ChildItemdownload C:\loot\*../../.ssh/authorized_keys~/.ssh/authorized_keysinstead of the download directory