Skip to content

Commit a349a92

Browse files
committed
handler: Allow quotes Forwarded header
Fixes tus#809
1 parent e0a7b60 commit a349a92

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

pkg/handler/post_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,44 @@ func TestPost(t *testing.T) {
319319
}).Run(handler, t)
320320
})
321321

322+
SubTest(t, "RespectForwardedWithQuotes", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
323+
// See https://github.com/tus/tusd/issues/809
324+
ctrl := gomock.NewController(t)
325+
defer ctrl.Finish()
326+
upload := NewMockFullUpload(ctrl)
327+
328+
gomock.InOrder(
329+
store.EXPECT().NewUpload(context.Background(), FileInfo{
330+
Size: 300,
331+
MetaData: map[string]string{},
332+
}).Return(upload, nil),
333+
upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{
334+
ID: "foo",
335+
Size: 300,
336+
MetaData: map[string]string{},
337+
}, nil),
338+
)
339+
340+
handler, _ := NewHandler(Config{
341+
StoreComposer: composer,
342+
BasePath: "/files/",
343+
RespectForwardedHeaders: true,
344+
})
345+
346+
(&httpTest{
347+
Method: "POST",
348+
ReqHeader: map[string]string{
349+
"Tus-Resumable": "1.0.0",
350+
"Upload-Length": "300",
351+
"Forwarded": `Forwarded: for=192.168.10.112;host="upload.example.tld:8443";proto=https`,
352+
},
353+
Code: http.StatusCreated,
354+
ResHeader: map[string]string{
355+
"Location": "https://upload.example.tld:8443/files/foo",
356+
},
357+
}).Run(handler, t)
358+
})
359+
322360
SubTest(t, "FilterForwardedProtocol", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
323361
ctrl := gomock.NewController(t)
324362
defer ctrl.Finish()

pkg/handler/unrouted_handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const UploadLengthDeferred = "1"
1919

2020
var (
2121
reExtractFileID = regexp.MustCompile(`([^/]+)\/?$`)
22-
reForwardedHost = regexp.MustCompile(`host=([^;]+)`)
22+
reForwardedHost = regexp.MustCompile(`host="?([^;"]+)`)
2323
reForwardedProto = regexp.MustCompile(`proto=(https?)`)
2424
reMimeType = regexp.MustCompile(`^[a-z]+\/[a-z0-9\-\+\.]+$`)
2525
)
@@ -802,7 +802,7 @@ var mimeInlineBrowserWhitelist = map[string]struct{}{
802802
"audio/webm": struct{}{},
803803
"video/webm": struct{}{},
804804
"audio/ogg": struct{}{},
805-
"video/ogg": struct{}{},
805+
"video/ogg": struct{}{},
806806
"application/ogg": struct{}{},
807807
}
808808

0 commit comments

Comments
 (0)