fix(http): delete abandoned TUS uploads through the scoped filesystem

The in-memory upload cache deleted expired incomplete uploads with a raw
os.Remove on the absolute path it had stored, bypassing ScopedFs entirely.
Because the stored path is only lexically cleaned (no symlink evaluation) and
os.Remove resolves symlinked parent directories, a Create-only user could
register an upload and then, within the 3-minute TTL, swap an in-scope
ancestor directory for a symlink so the eviction deleted an arbitrary file
outside their scope.

Carry a removal callback with each cache entry and invoke it on eviction
instead of os.Remove. For TUS uploads the callback deletes via the uploading
user's scoped filesystem, whose Remove is guarded by the same within() check
that CVE-2026-55667 added, so eviction can no longer follow a symlink out of
scope. The redis backend ignores the callback (it never deleted partial files).

Refs GHSA-m9f5-2232-frp6
This commit is contained in:
Henrique Dias committed 2026-07-25 08:16:18 +02:00
1 parent 6c69b5cd89
commit 9bd79c3aae
3 files changed
+36 -13

No files matched your search

+7 -2
View File
@@ -109,8 +109,13 @@ func tusPostHandler(cache UploadCache) handleFunc {
return http.StatusBadRequest, fmt.Errorf("invalid upload length: %w", err)
}
// Enables the user to utilize the PATCH endpoint for uploading file data
cache.Register(file.RealPath(), uploadLength)
// Enables the user to utilize the PATCH endpoint for uploading file data.
// The removal callback deletes an abandoned upload through the user's
// scoped filesystem, so eviction cannot follow a symlink out of scope.
uploadPath := r.URL.Path
cache.Register(file.RealPath(), uploadLength, func() error {
return d.user.Fs.Remove(uploadPath)
})
basePath := "/" + strings.Trim(strings.TrimSpace(d.server.BaseURL), "/")
if basePath == "/" {