Skip to content

Fix symlink escape in Gopher public file resolver#86

Closed
eouzoe wants to merge 1 commit into
profullstack:mainfrom
eouzoe:main
Closed

Fix symlink escape in Gopher public file resolver#86
eouzoe wants to merge 1 commit into
profullstack:mainfrom
eouzoe:main

Conversation

@eouzoe

@eouzoe eouzoe commented Jul 9, 2026

Copy link
Copy Markdown

Fixes #84

Problem

The Gopher resolver confined selectors with filepath.Clean and HasPrefix checks (line 308-311), but called os.Stat/os.ReadFile on the unresolved path. A symlink created inside a member's public area pointing outside would pass the lexical checks and leak external content.

Fix

Added a symlink escape guard using filepath.EvalSymlinks after the path check (line 314-320). If the resolved real path escapes the member's area, the request is refused with "forbidden".

Test added

TestSymlinkEscapeRefused in gopher_test.go verifies:

  • Symlink pointing outside the member area is rejected
  • Symlink pointing to another file within the area is still allowed

The userTree function confined selectors with path cleaning and HasPrefix
checks, but called os.Stat/os.ReadFile on the unresolved path. A symlink
created inside a member's public area pointing outside would pass the
lexical checks and leak external content.

Fix: resolve symlinks with filepath.EvalSymlinks after the path check
and reject the request if the real path escapes the member's area.

Adds TestSymlinkEscapeRefused to verify both rejection of external
symlinks and acceptance of symlinks within the member area.
@eouzoe eouzoe closed this by deleting the head repository Jul 9, 2026
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.

Bug: Gopher public file resolver follows symlink escapes

1 participant