From 1abf34e2fc5b5792339a76b52802c2e69f98f35f Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 10 Sep 2024 11:26:59 +0200 Subject: [PATCH] fix: check for existance of port on host (#545) --- src/http/routes/object/getObject.ts | 2 +- src/http/routes/object/getObjectInfo.ts | 2 +- src/http/routes/tus/lifecycle.ts | 6 +++++- src/storage/protocols/s3/signature-v4.ts | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/http/routes/object/getObject.ts b/src/http/routes/object/getObject.ts index 93c40dcc..05005b0e 100644 --- a/src/http/routes/object/getObject.ts +++ b/src/http/routes/object/getObject.ts @@ -54,7 +54,7 @@ async function requestHandler( if (!request.isAuthenticated) { // The bucket must be public to access its content if (!bucket?.public) { - throw ERRORS.AccessDenied('Access denied to this bucket') + throw ERRORS.NoSuchBucket(bucketName) } } diff --git a/src/http/routes/object/getObjectInfo.ts b/src/http/routes/object/getObjectInfo.ts index d46504d8..48abc3ce 100644 --- a/src/http/routes/object/getObjectInfo.ts +++ b/src/http/routes/object/getObjectInfo.ts @@ -46,7 +46,7 @@ async function requestHandler( // Not Authenticated flow if (!request.isAuthenticated) { if (!bucket?.public) { - throw ERRORS.AccessDenied('Access denied to this bucket') + throw ERRORS.NoSuchBucket(bucketName) } } diff --git a/src/http/routes/tus/lifecycle.ts b/src/http/routes/tus/lifecycle.ts index 1fda1e21..5769d995 100644 --- a/src/http/routes/tus/lifecycle.ts +++ b/src/http/routes/tus/lifecycle.ts @@ -99,7 +99,11 @@ export function generateUrl( const port = req.headers['x-forwarded-port'] if (typeof port === 'string' && port && !['443', '80'].includes(port)) { - host += `:${req.headers['x-forwarded-port']}` + if (!host.includes(':')) { + host += `:${req.headers['x-forwarded-port']}` + } else { + host = host.replace(/:\d+$/, `:${req.headers['x-forwarded-port']}`) + } } } diff --git a/src/storage/protocols/s3/signature-v4.ts b/src/storage/protocols/s3/signature-v4.ts index c7d13eec..e627013d 100644 --- a/src/storage/protocols/s3/signature-v4.ts +++ b/src/storage/protocols/s3/signature-v4.ts @@ -329,7 +329,11 @@ export class SignatureV4 { const host = `host:${xForwardedHost.toLowerCase()}` if (port && !['443', '80'].includes(port)) { - return host + ':' + port + if (!host.includes(':')) { + return host + ':' + port + } else { + return host.replace(/:\d+$/, `:${port}`) + } } return host }