From 92c4bf3106b13ca9d5ad1b5fb5b5ade9c365fb99 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 03:37:32 +0000 Subject: [PATCH] chore(deps): bump github.com/tus/tusd/v2 in /server Bumps [github.com/tus/tusd/v2](https://github.com/tus/tusd) from 2.10.0 to 2.10.4. - [Release notes](https://github.com/tus/tusd/releases) - [Commits](https://github.com/tus/tusd/compare/v2.10.0...v2.10.4) --- updated-dependencies: - dependency-name: github.com/tus/tusd/v2 dependency-version: 2.10.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- server/go.mod | 4 +- server/go.sum | 20 ++--- .../tus/tusd/v2/pkg/filestore/filestore.go | 89 +++++++++++++++++- .../tus/tusd/v2/pkg/handler/config.go | 1 + .../tus/tusd/v2/pkg/handler/datastore.go | 5 +- .../tusd/v2/pkg/handler/unrouted_handler.go | 90 +++++++++++++++---- server/vendor/modules.txt | 4 +- 7 files changed, 174 insertions(+), 39 deletions(-) diff --git a/server/go.mod b/server/go.mod index bef16ab..810ae05 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,6 +1,6 @@ module github.com/nimzshafie/airgap-devkit/server -go 1.26.6 +go 1.26.11 require ( github.com/go-chi/chi/v5 v5.5.0 @@ -8,6 +8,6 @@ require ( ) require ( - github.com/tus/tusd/v2 v2.10.0 + github.com/tus/tusd/v2 v2.10.4 golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa ) diff --git a/server/go.sum b/server/go.sum index 53fc639..22ef008 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,22 +1,18 @@ github.com/Acconut/go-httptest-recorder v1.0.0 h1:TAv2dfnqp/l+SUvIaMAUK4GeN4+wqb6KZsFFFTGhoJg= github.com/Acconut/go-httptest-recorder v1.0.0/go.mod h1:CwQyhTH1kq/gLyWiRieo7c0uokpu3PXeyF/nZjUNtmM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-chi/chi/v5 v5.5.0 h1:xdKQ1dJmVJsmgahrXSKhUx8NyVPzpwdlyrrQFpMPJgg= github.com/go-chi/chi/v5 v5.5.0/go.mod h1:d1IG7GtKPSjPyBP365PH8sAGVHk3qfB/IhjFNRH1wWM= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/tus/tusd/v2 v2.10.0 h1:2yOGmkrDl9RQmRIt/00DR2WvYWOoiEu3CoygILb+WRw= -github.com/tus/tusd/v2 v2.10.0/go.mod h1:T/OuJHIAC2NHpkEUyQyyaoWyDNRDcQVpJzWl8tX5GY4= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/tus/tusd/v2 v2.10.4 h1:6TxbzJsZTa5cPH6ZxALnR0jsb7go+GUi9y9uK9cnZuU= +github.com/tus/tusd/v2 v2.10.4/go.mod h1:BFgbSn1hpv3ESo+B2Q7NI2LeFbxcnCINZQZPcpnr2a8= +go.yaml.in/yaml/v3 v3.0.6 h1:zcDfvjXEqTQmpjniUBLc91xYJMB2c4QOFxEF/LCEckM= +go.yaml.in/yaml/v3 v3.0.6/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk= golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM= -golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= -golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= +golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= +golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/server/vendor/github.com/tus/tusd/v2/pkg/filestore/filestore.go b/server/vendor/github.com/tus/tusd/v2/pkg/filestore/filestore.go index 096cd69..70d1d03 100644 --- a/server/vendor/github.com/tus/tusd/v2/pkg/filestore/filestore.go +++ b/server/vendor/github.com/tus/tusd/v2/pkg/filestore/filestore.go @@ -22,6 +22,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "github.com/tus/tusd/v2/internal/uid" "github.com/tus/tusd/v2/pkg/handler" @@ -34,6 +35,12 @@ const ( StorageKeyInfoPath = "InfoPath" ) +const infoExtension = ".info" + +var errInvalidUploadID = errors.New("filestore: upload ID must not point outside of the storage directory") + +var errBinPathIsInfoFile = handler.NewError("ERR_INVALID_UPLOAD_PATH", "upload data must not be stored in a file ending in "+infoExtension, http.StatusInternalServerError) + const DefaultDirPerm = 0775 const DefaultFilePerm = 0664 @@ -84,7 +91,10 @@ func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (ha } // The .info file's location can directly be deduced from the upload ID - infoPath := store.infoPath(info.ID) + infoPath, ok := store.infoPath(info.ID) + if !ok { + return nil, errInvalidUploadID + } // The binary file's location might be modified by the pre-create hook. var binPath string if info.Storage != nil && info.Storage[StorageKeyPath] != "" { @@ -100,6 +110,12 @@ func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (ha binPath = store.defaultBinPath(info.ID) } + // Uploaded content must not be readable as another upload's .info file, or a + // client could control that upload's metadata, including its binary path. + if store.isInfoPathCandidate(binPath) { + return nil, errBinPathIsInfoFile + } + info.Storage = map[string]string{ "Type": "filestore", StorageKeyPath: binPath, @@ -128,7 +144,12 @@ func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (ha } func (store FileStore) GetUpload(ctx context.Context, id string) (handler.Upload, error) { - infoPath := store.infoPath(id) + infoPath, ok := store.infoPath(id) + if !ok { + // An ID which would place the .info file outside of the storage + // directory cannot belong to an existing upload. + return nil, handler.ErrNotFound + } data, err := os.ReadFile(infoPath) if err != nil { if os.IsNotExist(err) { @@ -197,8 +218,68 @@ func (store FileStore) defaultBinPath(id string) string { } // infoPath returns the path to the .info file storing the file's info. -func (store FileStore) infoPath(id string) string { - return filepath.Join(store.Path, id+".info") +// The second return value is false if the .info file would not be located +// inside the storage directory, for example because the ID contains ".." +// segments or is an absolute path. +func (store FileStore) infoPath(id string) (string, bool) { + name := id + infoExtension + if !filepath.IsLocal(name) { + return "", false + } + return filepath.Join(store.Path, name), true +} + +// isInfoPathCandidate reports whether binPath could be mistaken for an upload's .info +// file. The extension check ignores case and trailing dots/spaces, since some file +// systems (macOS, Windows) treat such names as equivalent. +func (store FileStore) isInfoPathCandidate(binPath string) bool { + name := strings.ToLower(strings.TrimRight(filepath.Base(binPath), ". ")) + if !strings.HasSuffix(name, infoExtension) { + return false + } + + storeDir, err := resolvePath(store.Path) + if err != nil { + return true // Err on the side of caution. + } + binDir, err := resolvePath(filepath.Dir(binPath)) + if err != nil { + return true + } + + // binDir is inside storeDir if the relative path between them doesn't escape via "..". + rel, err := filepath.Rel(storeDir, binDir) + if err != nil { + return true + } + return filepath.IsLocal(rel) +} + +// resolvePath returns the absolute path of p with symlinks resolved. p may not exist +// yet, so only its longest existing prefix is resolved. +func resolvePath(p string) (string, error) { + p, err := filepath.Abs(p) + if err != nil { + return "", err + } + + var rest []string + for { + resolved, err := filepath.EvalSymlinks(p) + if err == nil { + return filepath.Join(append([]string{resolved}, rest...)...), nil + } + if !errors.Is(err, fs.ErrNotExist) { + return "", err + } + + parent := filepath.Dir(p) + if parent == p { + return "", err + } + rest = append([]string{filepath.Base(p)}, rest...) + p = parent + } } type fileUpload struct { diff --git a/server/vendor/github.com/tus/tusd/v2/pkg/handler/config.go b/server/vendor/github.com/tus/tusd/v2/pkg/handler/config.go index 4efa435..785aec3 100644 --- a/server/vendor/github.com/tus/tusd/v2/pkg/handler/config.go +++ b/server/vendor/github.com/tus/tusd/v2/pkg/handler/config.go @@ -117,6 +117,7 @@ type CorsConfig struct { // AllowOrigin is a regular expression used to check if a request is allowed to participate in the // CORS protocol. If the request's Origin header matches the regular expression, CORS is allowed. // If not, a 403 Forbidden response is sent, rejecting the CORS request. + // The expression can match any part of the header, so anchor it, e.g. `^https://example\.com$`. AllowOrigin *regexp.Regexp // AllowCredentials defines whether the `Access-Control-Allow-Credentials: true` header should be // included in CORS responses. This allows clients to share credentials using the Cookie and diff --git a/server/vendor/github.com/tus/tusd/v2/pkg/handler/datastore.go b/server/vendor/github.com/tus/tusd/v2/pkg/handler/datastore.go index 5243834..e91d331 100644 --- a/server/vendor/github.com/tus/tusd/v2/pkg/handler/datastore.go +++ b/server/vendor/github.com/tus/tusd/v2/pkg/handler/datastore.go @@ -77,8 +77,9 @@ type FileInfoChanges struct { // If Storage is not nil, it is passed to the data store to allow for minor adjustments // to the upload storage (e.g. destination file name). The details are specific for each // data store and should be looked up in their respective documentation. - // Please be aware that this behavior is currently not supported by any data store in - // the github.com/tus/tusd package. + // Within the github.com/tus/tusd package, only filestore supports this, using the + // "Path" key to set the location of the upload's data file. The other data stores + // ignore this field. Storage map[string]string } diff --git a/server/vendor/github.com/tus/tusd/v2/pkg/handler/unrouted_handler.go b/server/vendor/github.com/tus/tusd/v2/pkg/handler/unrouted_handler.go index 3053c7d..d26949e 100644 --- a/server/vendor/github.com/tus/tusd/v2/pkg/handler/unrouted_handler.go +++ b/server/vendor/github.com/tus/tusd/v2/pkg/handler/unrouted_handler.go @@ -9,6 +9,7 @@ import ( "math" "mime" "net/http" + "net/url" "regexp" "strconv" "strings" @@ -80,8 +81,12 @@ type UnroutedHandler struct { composer *StoreComposer isBasePathAbs bool basePath string - logger *slog.Logger - extensions string + // basePathPath is the path component of basePath. It equals basePath, + // unless basePath is an absolute URL (e.g. https://example.com/files/), + // in which case it is only the path (e.g. /files/). + basePathPath string + logger *slog.Logger + extensions string // CompleteUploads is used to send notifications whenever an upload is // completed by a user. The HookEvent will contain information about this @@ -136,10 +141,22 @@ func NewUnroutedHandler(config Config) (*UnroutedHandler, error) { extensions += ",creation-defer-length" } + // The base path has already been validated and normalized by config.validate, + // so an absolute URL ends with a slash and its path is at least "/". + basePathPath := config.BasePath + if config.isAbs { + uri, err := url.Parse(config.BasePath) + if err != nil { + return nil, err + } + basePathPath = uri.Path + } + handler := &UnroutedHandler{ config: config, composer: config.StoreComposer, basePath: config.BasePath, + basePathPath: basePathPath, isBasePathAbs: config.isAbs, CompleteUploads: make(chan HookEvent), TerminatedUploads: make(chan HookEvent), @@ -306,7 +323,7 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) } // Parse Upload-Concat header - isPartial, isFinal, partialUploadIDs, err := parseConcat(concatHeader, handler.basePath) + isPartial, isFinal, partialUploadIDs, err := parseConcat(concatHeader, handler.basePathPath) if err != nil { handler.sendError(c, err) return @@ -341,8 +358,8 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) } // Test whether the size is still allowed - if handler.config.MaxSize > 0 && size > handler.config.MaxSize { - handler.sendError(c, ErrMaxSizeExceeded) + if err := handler.validateMaxSize(size); err != nil { + handler.sendError(c, err) return } @@ -484,6 +501,13 @@ func (handler *UnroutedHandler) PostFileV2(w http.ResponseWriter, r *http.Reques return } + // Enforce MaxSize for known lengths. Deferred uploads (size 0 here) are + // bounded later in writeChunk. + if err := handler.validateMaxSize(size); err != nil { + handler.sendError(c, err) + return + } + if !sizeIsDeferred { info.Size = size } else { @@ -815,8 +839,10 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request handler.sendError(c, ErrInvalidUploadLength) return } - uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64) - if err != nil || uploadLength < 0 || uploadLength < info.Offset || (handler.config.MaxSize > 0 && uploadLength > handler.config.MaxSize) { + uploadLength, err := parseUploadLength(r.Header.Get("Upload-Length")) + if err != nil || uploadLength < info.Offset || handler.validateMaxSize(uploadLength) != nil { + // Keep ErrInvalidUploadLength for PATCH length declaration failures, + // including MaxSize violations, to preserve existing client-facing behavior. handler.sendError(c, ErrInvalidUploadLength) return } @@ -893,8 +919,10 @@ func (handler *UnroutedHandler) writeChunk(c *httpContext, resp HTTPResponse, up maxSize = math.MaxInt64 } } + // Cap by Content-Length when present, but never raise the limit above the + // MaxSize/remaining-size clamp computed above (see #1032). if length > 0 { - maxSize = length + maxSize = min(maxSize, length) } c.log.InfoContext(c, "ChunkWriteStart", "maxSize", maxSize, "offset", offset) @@ -1416,6 +1444,23 @@ func (handler *UnroutedHandler) sizeOfUploads(ctx context.Context, ids []string) return } +// parseUploadLength parses an Upload-Length header value and rejects negative lengths. +func parseUploadLength(header string) (int64, error) { + uploadLength, err := strconv.ParseInt(header, 10, 64) + if err != nil || uploadLength < 0 { + return 0, ErrInvalidUploadLength + } + return uploadLength, nil +} + +// validateMaxSize returns ErrMaxSizeExceeded if size is larger than the configured maximum. +func (handler *UnroutedHandler) validateMaxSize(size int64) error { + if handler.config.MaxSize > 0 && size > handler.config.MaxSize { + return ErrMaxSizeExceeded + } + return nil +} + // Verify that the Upload-Length and Upload-Defer-Length headers are acceptable for creating a // new upload func (handler *UnroutedHandler) validateNewUploadLengthHeaders(uploadLengthHeader string, uploadDeferLengthHeader string) (uploadLength int64, uploadLengthDeferred bool, err error) { @@ -1432,10 +1477,7 @@ func (handler *UnroutedHandler) validateNewUploadLengthHeaders(uploadLengthHeade } else if lengthIsDeferred { uploadLengthDeferred = true } else { - uploadLength, err = strconv.ParseInt(uploadLengthHeader, 10, 64) - if err != nil || uploadLength < 0 { - err = ErrInvalidUploadLength - } + uploadLength, err = parseUploadLength(uploadLengthHeader) } return @@ -1549,9 +1591,9 @@ func getIETFDraftUploadLength(r *http.Request) (length int64, lengthIsDeferred b uploadLengthStr := r.Header.Get("Upload-Length") if uploadLengthStr != "" { var err error - lengthFromUploadLength, err = strconv.ParseInt(uploadLengthStr, 10, 64) + lengthFromUploadLength, err = parseUploadLength(uploadLengthStr) if err != nil { - return 0, false, ErrInvalidUploadLength + return 0, false, err } hasLengthFromUploadLength = true @@ -1680,12 +1722,26 @@ func extractIDFromPath(path string) (string, error) { } // extractIDFromURL extracts the upload ID from a full URL or a full path -// (including the base path). For example: +// (including the base path). For example, with the base path /files/: // // https://example.com/files/1234/5678 -> 1234/5678 +// https://example.com/files/1234?x=1 -> 1234 +// https://example.com/api/files/1234 -> 1234 // /files/1234/5678 -> 1234/5678 -func extractIDFromURL(url string, basePath string) (string, error) { - _, id, ok := strings.Cut(url, basePath) +// +// The value is parsed as a URL and only its path is considered, so the scheme, +// host, query and fragment never become part of the ID. basePath must be a +// path (e.g. /files/), not an absolute URL; see UnroutedHandler.basePathPath. +// Anything in front of the base path (e.g. a prefix added by a reverse proxy) +// is ignored. Note that the path is cut at the first occurrence of the base +// path, so such a prefix must not contain the base path itself. +func extractIDFromURL(value string, basePath string) (string, error) { + u, err := url.Parse(value) + if err != nil { + return "", ErrNotFound + } + + _, id, ok := strings.Cut(u.Path, basePath) if !ok { return "", ErrNotFound } diff --git a/server/vendor/modules.txt b/server/vendor/modules.txt index d992914..576d590 100644 --- a/server/vendor/modules.txt +++ b/server/vendor/modules.txt @@ -1,8 +1,8 @@ # github.com/go-chi/chi/v5 v5.5.0 ## explicit; go 1.24 github.com/go-chi/chi/v5 -# github.com/tus/tusd/v2 v2.10.0 -## explicit; go 1.25.8 +# github.com/tus/tusd/v2 v2.10.4 +## explicit; go 1.26.11 github.com/tus/tusd/v2/internal/uid github.com/tus/tusd/v2/pkg/filestore github.com/tus/tusd/v2/pkg/handler