handler: Allow quotes Forwarded header

Fixes https://github.com/tus/tusd/issues/809
This commit is contained in:
Marius 2022-10-05 00:06:17 +02:00
parent e0a7b6035b
commit a349a9296a
2 changed files with 40 additions and 2 deletions

View File

@ -319,6 +319,44 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "RespectForwardedWithQuotes", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
// See https://github.com/tus/tusd/issues/809
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(context.Background(), FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
BasePath: "/files/",
RespectForwardedHeaders: true,
})
(&httpTest{
Method: "POST",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
"Upload-Length": "300",
"Forwarded": `Forwarded: for=192.168.10.112;host="upload.example.tld:8443";proto=https`,
},
Code: http.StatusCreated,
ResHeader: map[string]string{
"Location": "https://upload.example.tld:8443/files/foo",
},
}).Run(handler, t)
})
SubTest(t, "FilterForwardedProtocol", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -19,7 +19,7 @@ const UploadLengthDeferred = "1"
var (
reExtractFileID = regexp.MustCompile(`([^/]+)\/?$`)
reForwardedHost = regexp.MustCompile(`host=([^;]+)`)
reForwardedHost = regexp.MustCompile(`host="?([^;"]+)`)
reForwardedProto = regexp.MustCompile(`proto=(https?)`)
reMimeType = regexp.MustCompile(`^[a-z]+\/[a-z0-9\-\+\.]+$`)
)
@ -802,7 +802,7 @@ var mimeInlineBrowserWhitelist = map[string]struct{}{
"audio/webm": struct{}{},
"video/webm": struct{}{},
"audio/ogg": struct{}{},
"video/ogg": struct{}{},
"video/ogg": struct{}{},
"application/ogg": struct{}{},
}