add contain_symlinks option to prevent symlink escape attacks#361
Merged
abhinavagarwal07 merged 1 commit intoMay 29, 2026
Merged
Conversation
A malicious SFTP server can return symlink targets that the local kernel VFS resolves outside the mount root, enabling local file reads or writes through ordinary operations like cp following a symlink. Add a contain_symlinks option (default on) that rejects absolute symlink targets and any target containing a `..` component, returning EPERM. Users who need legacy pass-through for trusted servers can opt out with -o no_contain_symlinks. The check is purely lexical and deliberately strict: in an adversarial filesystem the server controls intermediate path components, so any non-`..` component could be a symlink anywhere, making lexical depth tracking unreliable. Rejecting absolute and any `..` is the simplest rule that is provably complete against the threat model. transform_symlinks composes poorly with containment because transformed results often contain `..`; a warning is emitted when both are enabled. Tests cover default-on containment (readlink + open/stat traversal), opt-out behavior, transform_symlinks interaction (both arms), and option precedence.
h4sh5
approved these changes
May 29, 2026
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.
A malicious SFTP server can return symlink targets that SSHFS passes to the kernel unchanged. The kernel resolves those targets on the client’s local filesystem, allowing local file read/write through ordinary operations such as cp.
Add -o contain_symlinks, enabled by default, to reject symlink targets that are absolute or contain .. path components. Blocked symlinks return EPERM. The check is intentionally strict: rejecting any .. component closes the reported absolute-path, relative-traversal, and intermediate-symlink-assisted variants without relying on unsafe lexical normalization.
Users who need raw symlink pass-through for trusted servers can opt out with -o no_contain_symlinks.