Skip to content

Commit fca0fed

Browse files
committed
Validate upload URL before initiating large file upload
There seems to be a situation where a large file upload can be marked as non-local and attempt to POST file contents to an invalid URL (in this case, the name of the local upload directory). This obviously results in an error. This change ensures that the designated upload URL is actually a valid URL, otherwise it forces the local-only "dummy" mode to be enabled. See #14
1 parent 15186c1 commit fca0fed

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

backend/server/transfer/upload.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"github.com/benbusby/b2"
66
"log"
7+
"net/url"
78
db "yeetfile/backend/db"
89
"yeetfile/backend/service"
910
"yeetfile/backend/utils"
@@ -155,12 +156,22 @@ func InitLargeB2Upload(filename string, upload db.B2Upload) error {
155156
return err
156157
}
157158

159+
isDummy := info.Dummy
160+
if !isDummy {
161+
// Ensure that the dummy option is enabled if the request URI
162+
// is not actually valid
163+
_, err = url.ParseRequestURI(upload.UploadURL)
164+
if err != nil {
165+
isDummy = true
166+
}
167+
}
168+
158169
return db.UpdateUploadValues(
159170
upload.MetadataID,
160171
info.UploadURL,
161172
info.AuthorizationToken,
162173
info.FileID, // Multi-chunk files use the file ID for uploading
163-
info.Dummy)
174+
isDummy)
164175
}
165176

166177
func ResetLargeUpload(b2FileID string, metadataID string) (b2.FilePartInfo, error) {

0 commit comments

Comments
 (0)