✨ Fully rewrite relay
This commit is contained in:
parent
190e38dfc1
commit
20ffbd4c6d
47 changed files with 3489 additions and 128 deletions
39
src/utils/isLocalhost.ts
Normal file
39
src/utils/isLocalhost.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue