Fully rewrite relay

This commit is contained in:
Danny Morabito 2025-06-04 12:43:23 +02:00
parent 190e38dfc1
commit 20ffbd4c6d
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 7CC8056A5A04557E
47 changed files with 3489 additions and 128 deletions

39
src/utils/isLocalhost.ts Normal file
View file

@ -0,0 +1,39 @@
export function isLocalhost(
req: Request,
connInfo?: Deno.ServeHandlerInfo,
): boolean {
if (connInfo?.remoteAddr) {
const remoteAddr = connInfo.remoteAddr;
if (remoteAddr.transport === 'tcp') {
const hostname = remoteAddr.hostname;
return hostname === '127.0.0.1' || hostname === '::1';
}
if (remoteAddr.transport === 'unix') {
return true;
}
}
const url = new URL(req.url);
const hostname = url.hostname;
if (hostname === '127.0.0.1' || hostname === '::1') {
return true;
}
if (hostname === 'localhost') {
const suspiciousHeaders = [
'x-forwarded-for',
'x-forwarded-host',
'x-real-ip',
'cf-connecting-ip',
'x-cluster-client-ip',
];
for (const header of suspiciousHeaders) {
if (req.headers.get(header)) {
return false;
}
}
return true;
}
return false;
}