Skip to content

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
paulmiro:main
Aug 12, 2025
Merged

fix: only block ".." in file names if it is used to break out of the base directory#952
schollz merged 2 commits intoschollz:mainfrom
paulmiro:main

Conversation

@paulmiro
Copy link
Copy Markdown
Contributor

@paulmiro paulmiro commented Aug 11, 2025

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.IsLocal also tests if the path is absolute, so the filepath.IsAbs check above it is technically also redundant, but I chose to leave it in to allow for more fine-grained error messages

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, "../") {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why were these lines removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Forgot that filepath.Clean was there.

@schollz schollz merged commit aaa39f9 into schollz:main Aug 12, 2025
1 check passed
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