Skip to content

Commit

Permalink
fix: check for existance of port on host (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos authored Sep 10, 2024
1 parent 040871f commit 1abf34e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/http/routes/object/getObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/routes/object/getObjectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/http/routes/tus/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']}`)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/storage/protocols/s3/signature-v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1abf34e

Please sign in to comment.