fix: only block ".." in file names if it is used to break out of the base directory#952
Merged
schollz merged 2 commits intoschollz:mainfrom Aug 12, 2025
Merged
fix: only block ".." in file names if it is used to break out of the base directory#952schollz merged 2 commits intoschollz:mainfrom
schollz merged 2 commits intoschollz:mainfrom
Conversation
schollz
requested changes
Aug 12, 2025
| for i, fi := range c.FilesToTransfer { | ||
| // Issues #593 - sanitize the sender paths and prevent ".." from being used | ||
| c.FilesToTransfer[i].FolderRemote = filepath.Clean(fi.FolderRemote) | ||
| if strings.Contains(c.FilesToTransfer[i].FolderRemote, "../") { |
Contributor
Author
There was a problem hiding this comment.
If I understand the behaviour of filepath.IsLocal correctly, these lines should be more or less redundant.
It kind of depends on wheter or not you want to allow /../ when it doesn't break out of the base directory, for example some/path/to/../a/file = some/path/a/file (although this case would already be shortened by filepath.Clean).
Also, these lines incorrectly catch safe cases like relative/..path/to/file.
Owner
There was a problem hiding this comment.
Thanks! Forgot that filepath.Clean was there.
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.
Currently, trying to send a file with ".." anywhere in the filename results in an error.
I'm not sure if this is a regression or if #796 was not actually fixed by #811
I believe this change should handle all edgecases, but I'm not familiar with the codebase, so there might be some cases I missed, especially when it comes to cross-OS-operations
filepath.IsLocalalso tests if the path is absolute, so thefilepath.IsAbscheck above it is technically also redundant, but I chose to leave it in to allow for more fine-grained error messages