Summary
When a user creates a public share link for a directory, the withHashFile middleware in http/public.go (line 59) uses filepath.Dir(link.Path) to compute the BasePathFs root. This sets the filesystem root to the parent directory instead of the shared directory itself, allowing anyone with the share link to browse and download files from all sibling directories.
Details
In http/public.go lines 52-64, the withHashFile function handles public share link requests:
basePath := link.Path // e.g. "/documents/shared"
filePath := ""
if file.IsDir {
basePath = filepath.Dir(basePath) // BUG: becomes "/documents" (parent!)
filePath = ifPath
}
d.user.Fs = afero.NewBasePathFs(d.user.Fs, basePath)
When a directory at /documents/shared is shared, filepath.Dir("/documents/shared") evaluates to "/documents". The BasePathFs is then rooted at the parent directory /documents/, giving the share link access to everything under /documents/ - not just the intended /documents/shared/.
This affects both publicShareHandler (directory listing via /api/public/share/{hash}) and publicDlHandler (file download via /api/public/dl/{hash}/path).
PoC
- Set up filebrowser with a user whose scope contains:
-
/documents/shared/public-file.txt (intended to be shared)
-
/documents/secrets/passwords.txt (NOT intended to be shared)
-
/documents/private/financial.csv (NOT intended to be shared)