Skip to content

Commit 57d06cf

Browse files
committed
docs: Warn against collisions from custom upload IDs
See tus#1109
1 parent fa5f966 commit 57d06cf

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Diff for: docs/_advanced-topics/hooks.md

+9
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ Below you can find an annotated, JSON-ish encoded example of a hook response:
175175
// path component according to RFC 3986 (https://datatracker.ietf.org/doc/html/rfc3986#section-3.3).
176176
// These are: A-Z a-z 0-9 - . _ ~ % ! $ ' ( ) * + , ; = / : @
177177
// In addition, IDs must not begin or end with a forward slash (/).
178+
//
179+
// When a custom upload ID is specified, it is the hook's responsibility to
180+
// ensure that the upload ID will not cause collisions with resources from other
181+
// uploads. Tusd does not check for collisions. Collisions happen frequently when
182+
// the upload ID is mainly derived from the filename, which can be prevented by including
183+
// a random part (e.g. a UUID) in the upload ID. In addition, be aware that some storage
184+
// backends, such as the S3 store, save additional objects using `.info` and `.part`
185+
// extensions. If you set a custom upload ID, ensure that this ID will also not collide
186+
// with these additional objects.
178187
"ID": "my-custom-upload-id",
179188
// Set custom meta data that is saved with the upload and also accessible to
180189
// all future hooks. Note that this information is also visible to the client

Diff for: pkg/handler/datastore.go

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func (f FileInfo) StopUpload(response HTTPResponse) {
5454
// can be done using the PreUploadCreateCallback to modify certain properties before
5555
// an upload is created. Properties which should not be modified (e.g. Size or Offset)
5656
// are intentionally left out here.
57+
//
58+
// Please also consult the documentation for the `ChangeFileInfo` property at
59+
// https://tus.github.io/tusd/advanced-topics/hooks/#hook-requests-and-responses.
5760
type FileInfoChanges struct {
5861
// If ID is not empty, it will be passed to the data store, allowing
5962
// hooks to influence the upload ID. Be aware that a data store is not required to

Diff for: pkg/handler/unrouted_handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ func getRequestId(r *http.Request) string {
15451545
return reqId
15461546
}
15471547

1548-
// validateUploadId checks whether an ID included in a FileInfoChange struct is allowed.
1548+
// validateUploadId checks whether an ID included in a FileInfoChanges struct is allowed.
15491549
func validateUploadId(newId string) error {
15501550
if newId == "" {
15511551
// An empty ID from FileInfoChanges is allowed. The store will then

0 commit comments

Comments
 (0)