mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-12 19:18:30 +00:00
Merge pull request #1177 from Error-Gap/portbinding-fixes
Portbinding fixes
This commit is contained in:
@@ -52,20 +52,26 @@ export async function exchangeSession(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { requestToken, host, requestIp } = parsedBody.data;
|
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 clientIp = requestIp?.split(":")[0];
|
||||||
|
|
||||||
const [resource] = await db
|
const [resource] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(resources)
|
.from(resources)
|
||||||
.where(eq(resources.fullDomain, host))
|
.where(eq(resources.fullDomain, cleanHost))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.NOT_FOUND,
|
HttpCode.NOT_FOUND,
|
||||||
`Resource with host ${host} not found`
|
`Resource with host ${cleanHost} not found`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,11 +121,10 @@ export async function verifyResourceSession(
|
|||||||
logger.debug("Client IP:", { clientIp });
|
logger.debug("Client IP:", { clientIp });
|
||||||
|
|
||||||
let cleanHost = host;
|
let cleanHost = host;
|
||||||
// if the host ends with :443 or :80 remove it
|
// if the host ends with :port, strip it
|
||||||
if (cleanHost.endsWith(":443")) {
|
if (cleanHost.match(/:[0-9]{1,5}$/)) {
|
||||||
cleanHost = cleanHost.slice(0, -4);
|
let matched = ''+cleanHost.match(/:[0-9]{1,5}$/);
|
||||||
} else if (cleanHost.endsWith(":80")) {
|
cleanHost = cleanHost.slice(0, -1*matched.length);
|
||||||
cleanHost = cleanHost.slice(0, -3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const resourceCacheKey = `resource:${cleanHost}`;
|
const resourceCacheKey = `resource:${cleanHost}`;
|
||||||
|
|||||||
@@ -59,9 +59,14 @@ export default async function ResourceAuthPage(props: {
|
|||||||
try {
|
try {
|
||||||
const serverResourceHost = new URL(authInfo.url).host;
|
const serverResourceHost = new URL(authInfo.url).host;
|
||||||
const redirectHost = new URL(searchParams.redirect).host;
|
const redirectHost = new URL(searchParams.redirect).host;
|
||||||
|
const redirectPort = new URL(searchParams.redirect).port;
|
||||||
|
const serverResourceHostWithPort = `${serverResourceHost}:${redirectPort}`;
|
||||||
|
|
||||||
|
|
||||||
if (serverResourceHost === redirectHost) {
|
if (serverResourceHost === redirectHost) {
|
||||||
redirectUrl = searchParams.redirect;
|
redirectUrl = searchParams.redirect;
|
||||||
|
} else if ( serverResourceHostWithPort === redirectHost ) {
|
||||||
|
redirectUrl = searchParams.redirect;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user