Skip to content

add contain_symlinks option to prevent symlink escape attacks#361

Merged
abhinavagarwal07 merged 1 commit into
libfuse:masterfrom
abhinavagarwal07:contain-symlinks
May 29, 2026
Merged

add contain_symlinks option to prevent symlink escape attacks#361
abhinavagarwal07 merged 1 commit into
libfuse:masterfrom
abhinavagarwal07:contain-symlinks

Conversation

@abhinavagarwal07
Copy link
Copy Markdown
Collaborator

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.

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.
@abhinavagarwal07 abhinavagarwal07 requested a review from h4sh5 May 29, 2026 22:59
@abhinavagarwal07 abhinavagarwal07 merged commit 6893c3a into libfuse:master May 29, 2026
6 checks passed
@abhinavagarwal07 abhinavagarwal07 deleted the contain-symlinks branch May 29, 2026 23:07
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