Skip to content

sshfs: add -o follow_inside_symlinks option - #385

Open
hlein wants to merge 1 commit into
libfuse:masterfrom
hlein:follow_inside_symlinks
Open

hlein wants to merge 1 commit into
libfuse:masterfrom
hlein:follow_inside_symlinks

Conversation

@hlein

@hlein hlein commented Sep 5, 2026

Copy link
Copy Markdown

Middle ground between contain_symlinks (default, strict) and no_contain_symlinks (permissive). Allows relative symlinks whose target lexically resolves within sshfs.base_path while rejecting anything that escapes. The motivating case:

share/bar/fizz -> ../foo/yada   # allowed: stays inside the share
share/link     -> ../../etc/passwd  # EPERM: escapes the share

Absolute targets are always rejected: the kernel resolves them on the local filesystem, not via FUSE, so even an in-base absolute path could expose local files. Combine with transform_symlinks to handle absolute in-base remote symlinks safely (transform runs first, converting them to relative form before the inside check).

sshfs_readlink() has two separate branches for follow_inside_symlinks and the existing contain_symlinks logic. New tests cover the motivating case, deep nesting, escapes, and the transform interaction.

Refs: #378

Middle ground between contain_symlinks (default, strict) and
no_contain_symlinks (permissive).  Allows relative symlinks whose
target lexically resolves within sshfs.base_path while rejecting
anything that escapes.  The motivating case:

    share/bar/fizz -> ../foo/yada   # allowed: stays inside the share
    share/link     -> ../../etc/passwd  # EPERM: escapes the share

Absolute targets are always rejected: the kernel resolves them on
the local filesystem, not via FUSE, so even an in-base absolute path
could expose local files.  Combine with transform_symlinks to handle
absolute in-base remote symlinks safely (transform runs first,
converting them to relative form before the inside check).

sshfs_readlink() has two separate branches for follow_inside_symlinks
and the existing contain_symlinks logic.  New tests cover the
motivating case, deep nesting, escapes, and the transform interaction.

Refs: libfuse#378

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hlein

hlein commented Sep 5, 2026

Copy link
Copy Markdown
Author

Note while I reference #378 this does not exactly implement what that was asking for; this only does "allow symlinks if they resolve to within the same sshfs share".

@hlein

hlein commented Oct 5, 2026

Copy link
Copy Markdown
Author

@h4sh5 requesting a review please, thanks!

@michael-berg

Copy link
Copy Markdown

I'm not reviewing the implementation details in this comment. I just stumbled across this patch while looking for basically this feature.

However, based on the description and consistency with the existing option names, I think this should feature set should be named contain_outside_symlinks instead of follow_inside_symlinks.

  • contain_symlinks exposes symlinks to the client as symlinks, but blocks symlinks to absolute paths and anything with .. as a path component (which is often too strict).
  • no_contain_symlinks exposes symlinks to the client as symlinks, and doesn't block anything (which isn't strict enough).
  • follow_symlinks follows symlinks on the server, exposing them to the client as regular files (not as symlinks).
  • The proposed follow_outside_symlinks in Add -o follow_outside_symlinks #378 only does the follow_symlinks "follow on server and expose to client as a regular file" thing on symlinks outside the mounted remote directory.

Based on those other option names, I would expect that:

  • follow_inside_symlinks does the follow_symlinks "follow on server and expose to client as a regular file" thing on symlinks inside the mounted remote directory, and then blocks anything outside the mounted remote directory -- which wouldn't expose inside symlinks to the client as symlinks and isn't what you described in this patch.
  • contain_outside_symlinks only does contain_symlinks blocking on symlinks that are outside the mounted remote directory -- which is what you described in this patch as a middle ground between contain_symlinks and no_contain_symlinks.

@hlein

hlein commented Nov 22, 2026

Copy link
Copy Markdown
Author

I don't care much what this is called, that said, your suggestions don't make sense to me.

How about just allow_inside_symlinks ?

The default behavior is to disallow any symlink with a ../ element, period.

This patch adds the option to permit symlinks that contain ../ as long as they resolve inside the current sshfs mount.

Why is follow_inside_symlinks - literally "follow symlinks when they are inside the mount" not a suitable name? ...Ah, because the existing follow_symlinks isn't about allowing them to be followed, it's about translating them to non-symlinks. So it's misleading in that way. In fact the behavior change proposed in follow_outside_symlinks seems even more counterintuitive or POLA-violating to me.

contain_outside_symlinks sounds like a new control that prevented symlinks that point outside the share. But that is already denied. Having that have the side effect of allowing inside links also seems like a POLA violation. Maybe you are also proposing changing the default behavior to allow ~all symlinks and add contain_outside_symlinks to allow blocking of only symlinks outside the fs; I don't want to change default behavior like that.

Or no_contain_inside_symlinks gets added with the contain_inside_... variant being documented as the default behavior?

@michael-berg

Copy link
Copy Markdown

@hlein, I'm not stuck on any particular names. However, I strongly believe that names should use consistent terminology within a project to avoid confusion. sshfs (for better or worse) has an established history of follow_* meaning that the SERVER follows the symlinks to the real files (and so those symlinks are not exposed to the client as symlinks). I was just pointing out that your use of follow_* conflicted with that well established meaning and would cause confusion.

allow_inside_symlinks would work and doesn't conflict with other established option name meanings.

All that said, I am not an sshfs maintainer and can't sign off on anything. I was just pointing out some likely confusion that I saw when I stumbled across this patch.

@hlein

hlein commented Nov 22, 2026

Copy link
Copy Markdown
Author

@hlein, I'm not stuck on any particular names. However, I strongly believe that names should use consistent terminology within a project to avoid confusion. sshfs (for better or worse) has an established history of follow_* meaning that the SERVER follows the symlinks to the real files (and so those symlinks are not exposed to the client as symlinks). I was just pointing out that your use of follow_* conflicted with that well established meaning and would cause confusion.

allow_inside_symlinks would work and doesn't conflict with other established option name meanings.

All that said, I am not an sshfs maintainer and can't sign off on anything. I was just pointing out some likely confusion that I saw when I stumbled across this patch.

Understood - you talked me out of follow_... since there's an existing (weird?) meaning to that, and this is not doing what that does. But contain_... also seems weird. I'll change to allow_...

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