Skip to content

Commit d0ce99d

Browse files
authored
fix: remove duplicate slash in tus upload url generator (#801)
* fix: remove deuplicate slash in tus upload url generator * removing prefix trailing slash from prefix in S3 handler
1 parent fbf3248 commit d0ce99d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/http/routes/tus/lifecycle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export function generateUrl(
126126

127127
const forwardedPath = req.headers['x-forwarded-prefix']
128128
if (requestAllowXForwardedPrefix && typeof forwardedPath === 'string') {
129-
basePath = forwardedPath + path
129+
// Remove trailing slash from forwardedPath to avoid double slashes
130+
basePath = forwardedPath.replace(/\/+$/, '') + path
130131
}
131132

132133
const isSigned = req.url?.endsWith(SIGNED_URL_SUFFIX)
@@ -264,7 +265,7 @@ export async function onUploadFinish(rawReq: Request, upload: Upload) {
264265
if (upload.metadata?.metadata) {
265266
try {
266267
customMd = JSON.parse(upload.metadata.metadata)
267-
} catch (e) {
268+
} catch {
268269
// no-op
269270
}
270271
}

src/storage/protocols/s3/signature-v4.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ export class SignatureV4 {
424424
signedHeaders: string[]
425425
) {
426426
const method = request.method
427-
const canonicalUri = new URL(`http://localhost:8080${request.prefix || ''}${request.url}`)
428-
.pathname
427+
const prefix = request.prefix ? request.prefix.replace(/\/+$/, '') : ''
428+
const canonicalUri = new URL(`http://localhost:8080${prefix}${request.url}`).pathname
429429
const canonicalQueryString = this.constructCanonicalQueryString(request.query || {})
430430
const canonicalHeaders = this.constructCanonicalHeaders(request, signedHeaders)
431431
const signedHeadersString = signedHeaders.sort().join(';')

0 commit comments

Comments
 (0)