Bypass proxy on loopback IPs

This commit is contained in:
Ferenc Hammerl
2023-03-01 13:45:12 +00:00
parent 0db3029fcf
commit 8d92c9c903
2 changed files with 28 additions and 8 deletions

View File

@@ -25,6 +25,11 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
const reqHost = reqUrl.hostname
if (isLoopbackAddress(reqHost)) {
return true
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
if (!noProxy) {
return false
@@ -66,3 +71,8 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
return hostUpper === 'LOCALHOST' || hostUpper.startsWith('127.') || hostUpper.startsWith('::1')
}