mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-01 18:23:16 +08:00
Bypass proxy on loopback IPs (localhost, 127.*, ::1 etc) (#1361)
* Bypass proxy on loopback IPs * Expect empty array instead of undefined * Restore accidentally deleted test * Fix formatting * Fix linting * Update proxy.ts * Better ipv6 definitions * Fix linting * Update proxy.test.ts
This commit is contained in:
@@ -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
|
||||
@@ -67,3 +72,13 @@ export function checkBypass(reqUrl: URL): boolean {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function isLoopbackAddress(host: string): boolean {
|
||||
const hostLower = host.toLowerCase()
|
||||
return (
|
||||
hostLower === 'localhost' ||
|
||||
hostLower.startsWith('127.') ||
|
||||
hostLower.startsWith('[::1]') ||
|
||||
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user