Compare commits

..
7 Commits
Author SHA1 Message Date
Henrique Dias 69c76d11cc chore(release): 2.63.10 2026-06-03 15:42:27 +02:00
Henrique Dias 6b04cbf5e9 fix: allow writes when user scope resolves to filesystem root
WithinScope compared targets against root+separator, which produced
"//" when the scope resolved to "/". No path matched, so every write
was rejected with os.ErrPermission (HTTP 403), breaking saves and
uploads for root-scoped installs. Skip the appended separator when root
already ends in one.
2026-06-03 15:40:26 +02:00
Henrique Dias 503fd6b01f chore(release): 2.63.9 2026-06-03 13:13:03 +02:00
Henrique Dias 35db07d015 fix: set X-Content-Type-Options: nosniff on raw file responses
Prevents browsers from MIME-sniffing uploaded files into a renderable type.
2026-06-03 12:21:23 +02:00
Henrique Dias 19514367ad fix: use constant-time comparison for share access token
Compare the share token with subtle.ConstantTimeCompare instead of ==.
2026-06-03 12:21:23 +02:00
Henrique Dias cdd666fc95 fix: prevent symlink scope escape in copy/move/rename
Check WithinScope for src and dst in resourcePatchHandler before
fileutils.Copy/MoveFile, which follow symlinks and bypassed the
stat()/writeFile() guards (GHSA-239w-m3h6-ch8v).
2026-06-03 12:21:23 +02:00
mehmet turacandGitHub 103acd15fe fix: force octet-stream for attachment downloads (#5942) 2026-06-03 11:59:17 +02:00
7 changed files with 136 additions and 2 deletions
+17
View File
@@ -2,6 +2,23 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [2.63.10](https://github.com/filebrowser/filebrowser/compare/v2.63.9...v2.63.10) (2026-06-03)
### Bug Fixes
* allow writes when user scope resolves to filesystem root ([6b04cbf](https://github.com/filebrowser/filebrowser/commit/6b04cbf5e9db1f5b9c0b1624843607ce2881cfc4))
## [2.63.9](https://github.com/filebrowser/filebrowser/compare/v2.63.8...v2.63.9) (2026-06-03)
### Bug Fixes
* force octet-stream for attachment downloads ([#5942](https://github.com/filebrowser/filebrowser/issues/5942)) ([103acd1](https://github.com/filebrowser/filebrowser/commit/103acd15fe57554fe0246bfe70a49b6cb4ae0c51))
* prevent symlink scope escape in copy/move/rename ([cdd666f](https://github.com/filebrowser/filebrowser/commit/cdd666fc95f569ad583c32391e45646fed676dfd))
* set X-Content-Type-Options: nosniff on raw file responses ([35db07d](https://github.com/filebrowser/filebrowser/commit/35db07d0159c520a6b3c969ac52033593914fadd))
* use constant-time comparison for share access token ([1951436](https://github.com/filebrowser/filebrowser/commit/19514367adf2d9fe5be2b7666e397979ea679b94))
## [2.63.8](https://github.com/filebrowser/filebrowser/compare/v2.63.7...v2.63.8) (2026-06-03)
+11 -1
View File
@@ -217,7 +217,17 @@ func WithinScope(fsys afero.Fs, p string) (bool, error) {
return false, err
}
return resolved == root || strings.HasPrefix(resolved, root+string(filepath.Separator)), nil
// Compare against root with a trailing separator so a sibling like
// "/srvother" is not treated as being inside "/srv". When root is itself
// the filesystem boundary (e.g. "/"), it already ends in a separator, so
// avoid producing "//" — which no path would match — and accept any path
// under it.
prefix := root
if !strings.HasSuffix(prefix, string(filepath.Separator)) {
prefix += string(filepath.Separator)
}
return resolved == root || strings.HasPrefix(resolved, prefix), nil
}
// Checksum checksums a given File for a given User, using a specific
+83
View File
@@ -0,0 +1,83 @@
package files
import (
"os"
"path/filepath"
"testing"
"github.com/spf13/afero"
)
func TestWithinScope(t *testing.T) {
t.Run("non-scoped filesystem is a no-op", func(t *testing.T) {
ok, err := WithinScope(afero.NewOsFs(), "/anything")
if err != nil || !ok {
t.Fatalf("expected (true, nil), got (%v, %v)", ok, err)
}
})
t.Run("path inside a nested scope is allowed", func(t *testing.T) {
scope := t.TempDir()
if err := os.WriteFile(filepath.Join(scope, "file.txt"), []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
bfs := afero.NewBasePathFs(afero.NewOsFs(), scope)
ok, err := WithinScope(bfs, "/file.txt")
if err != nil || !ok {
t.Fatalf("expected (true, nil), got (%v, %v)", ok, err)
}
})
t.Run("new file inside scope is allowed", func(t *testing.T) {
scope := t.TempDir()
bfs := afero.NewBasePathFs(afero.NewOsFs(), scope)
ok, err := WithinScope(bfs, "/does-not-exist-yet.txt")
if err != nil || !ok {
t.Fatalf("expected (true, nil), got (%v, %v)", ok, err)
}
})
// Regression for #5975: when the scope resolves to the filesystem root,
// root+separator used to be "//", which no path matched, so every write
// was rejected with os.ErrPermission (HTTP 403).
t.Run("filesystem root scope allows writes", func(t *testing.T) {
f := filepath.Join(t.TempDir(), "file.txt")
if err := os.WriteFile(f, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
bfs := afero.NewBasePathFs(afero.NewOsFs(), "/")
ok, err := WithinScope(bfs, f)
if err != nil || !ok {
t.Fatalf("expected (true, nil) for a path under root scope, got (%v, %v)", ok, err)
}
})
t.Run("sibling of a nested scope is rejected", func(t *testing.T) {
base := t.TempDir()
scope := filepath.Join(base, "srv")
sibling := filepath.Join(base, "srvother")
for _, d := range []string{scope, sibling} {
if err := os.MkdirAll(d, 0o755); err != nil {
t.Fatal(err)
}
}
// A symlink lexically inside the scope pointing at a sibling directory
// must not be followed.
link := filepath.Join(scope, "escape")
if err := os.Symlink(sibling, link); err != nil {
t.Fatal(err)
}
bfs := afero.NewBasePathFs(afero.NewOsFs(), scope)
ok, err := WithinScope(bfs, "/escape")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ok {
t.Fatal("expected escaping symlink to a sibling directory to be rejected")
}
})
}
+2 -1
View File
@@ -1,6 +1,7 @@
package fbhttp
import (
"crypto/subtle"
"errors"
"net/http"
"net/url"
@@ -136,7 +137,7 @@ func authenticateShareRequest(r *http.Request, l *share.Link) (int, error) {
return 0, nil
}
if r.URL.Query().Get("token") == l.Token {
if subtle.ConstantTimeCompare([]byte(r.URL.Query().Get("token")), []byte(l.Token)) == 1 {
return 0, nil
}
+2
View File
@@ -77,6 +77,7 @@ func setContentDisposition(w http.ResponseWriter, r *http.Request, file *files.F
} else {
// As per RFC6266 section 4.3
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(file.Name))
w.Header().Set("Content-Type", "application/octet-stream")
}
}
@@ -224,6 +225,7 @@ func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo
setContentDisposition(w, r, file)
w.Header().Add("Content-Security-Policy", `script-src 'none';`)
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "private")
http.ServeContent(w, r, file.Name, file.ModTime, fd)
return 0, nil
+8
View File
@@ -70,6 +70,14 @@ func TestSetContentDisposition(t *testing.T) {
if got != tc.expected {
t.Errorf("Content-Disposition = %q, want %q", got, tc.expected)
}
contentType := recorder.Header().Get("Content-Type")
if tc.inline && contentType != "" {
t.Errorf("Content-Type = %q, want empty", contentType)
}
if !tc.inline && contentType != "application/octet-stream" {
t.Errorf("Content-Type = %q, want application/octet-stream", contentType)
}
})
}
}
+13
View File
@@ -228,6 +228,19 @@ func resourcePatchHandler(fileCache FileCache) handleFunc {
return http.StatusForbidden, nil
}
// Refuse to copy/move through a symlink that escapes the user's scope,
// for either the source (read escape) or the destination (write
// escape). fileutils.Copy/MoveFile operate on the raw afero FS and
// follow symlinks, so they bypass the guards in stat()/writeFile().
for _, p := range []string{src, dst} {
if ok, scopeErr := files.WithinScope(d.user.Fs, p); scopeErr != nil || !ok {
if scopeErr != nil {
return errToStatus(scopeErr), scopeErr
}
return http.StatusForbidden, nil
}
}
err = checkParent(src, dst)
if err != nil {
return http.StatusBadRequest, err