Merge pull request #1177 from Error-Gap/portbinding-fixes

Portbinding fixes
This commit is contained in:
Owen Schwartz
2025-08-03 11:37:30 -07:00
committed by GitHub
3 changed files with 17 additions and 7 deletions

View File

@@ -52,20 +52,26 @@ export async function exchangeSession(
try {
const { requestToken, host, requestIp } = parsedBody.data;
let cleanHost = host;
// if the host ends with :port
if (cleanHost.match(/:[0-9]{1,5}$/)) {
let matched = ''+cleanHost.match(/:[0-9]{1,5}$/);
cleanHost = cleanHost.slice(0, -1*matched.length);
}
const clientIp = requestIp?.split(":")[0];
const [resource] = await db
.select()
.from(resources)
.where(eq(resources.fullDomain, host))
.where(eq(resources.fullDomain, cleanHost))
.limit(1);
if (!resource) {
return next(
createHttpError(
HttpCode.NOT_FOUND,
`Resource with host ${host} not found`
`Resource with host ${cleanHost} not found`
)
);
}

View File

@@ -121,11 +121,10 @@ export async function verifyResourceSession(
logger.debug("Client IP:", { clientIp });
let cleanHost = host;
// if the host ends with :443 or :80 remove it
if (cleanHost.endsWith(":443")) {
cleanHost = cleanHost.slice(0, -4);
} else if (cleanHost.endsWith(":80")) {
cleanHost = cleanHost.slice(0, -3);
// if the host ends with :port, strip it
if (cleanHost.match(/:[0-9]{1,5}$/)) {
let matched = ''+cleanHost.match(/:[0-9]{1,5}$/);
cleanHost = cleanHost.slice(0, -1*matched.length);
}
const resourceCacheKey = `resource:${cleanHost}`;

View File

@@ -59,9 +59,14 @@ export default async function ResourceAuthPage(props: {
try {
const serverResourceHost = new URL(authInfo.url).host;
const redirectHost = new URL(searchParams.redirect).host;
const redirectPort = new URL(searchParams.redirect).port;
const serverResourceHostWithPort = `${serverResourceHost}:${redirectPort}`;
if (serverResourceHost === redirectHost) {
redirectUrl = searchParams.redirect;
} else if ( serverResourceHostWithPort === redirectHost ) {
redirectUrl = searchParams.redirect;
}
} catch (e) {}
}