Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69c76d11cc | ||
|
|
6b04cbf5e9 | ||
|
|
503fd6b01f | ||
|
|
35db07d015 | ||
|
|
19514367ad | ||
|
|
cdd666fc95 | ||
|
|
103acd15fe | ||
|
|
f5e0c4e2e1 | ||
|
|
ca019ae7d9 |
@@ -2,6 +2,30 @@
|
||||
|
||||
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)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* check if share is within scope when creating ([ca019ae](https://github.com/filebrowser/filebrowser/commit/ca019ae7d966a7c28de2b2341271cd13e3458ae6))
|
||||
|
||||
## [2.63.7](https://github.com/filebrowser/filebrowser/compare/v2.63.6...v2.63.7) (2026-06-03)
|
||||
|
||||
|
||||
|
||||
+11
-1
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
fberrors "github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/files"
|
||||
"github.com/filebrowser/filebrowser/v2/share"
|
||||
)
|
||||
|
||||
@@ -106,6 +107,16 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
|
||||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
// Refuse to create a share whose on-disk target escapes the user's scope
|
||||
// (e.g. via a symlink), mirroring the read/write guards. The public serve
|
||||
// path already rejects these, but blocking creation avoids dangling shares.
|
||||
if ok, err := files.WithinScope(d.user.Fs, r.URL.Path); err != nil || !ok {
|
||||
if err != nil {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
var s *share.Link
|
||||
var body share.CreateBody
|
||||
if r.Body != nil {
|
||||
|
||||
Reference in New Issue
Block a user