mirror of https://github.com/actions/toolkit
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.tspull/1005/merge
parent
d47e0bac60
commit
94ab8de5f3
|
@ -242,6 +242,31 @@ describe('proxy', () => {
|
||||||
expect(_proxyConnects).toHaveLength(0)
|
expect(_proxyConnects).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => {
|
||||||
|
// setup a server listening on localhost:8091
|
||||||
|
const server = http.createServer((request, response) => {
|
||||||
|
response.writeHead(200)
|
||||||
|
request.pipe(response)
|
||||||
|
})
|
||||||
|
server.listen(8091)
|
||||||
|
try {
|
||||||
|
process.env['http_proxy'] = _proxyUrl
|
||||||
|
const httpClient = new httpm.HttpClient()
|
||||||
|
let res = await httpClient.get('http://localhost:8091')
|
||||||
|
expect(res.message.statusCode).toBe(200)
|
||||||
|
res = await httpClient.get('http://127.0.0.1:8091')
|
||||||
|
expect(res.message.statusCode).toBe(200)
|
||||||
|
|
||||||
|
// no support for ipv6 for now
|
||||||
|
expect(httpClient.get('http://[::1]:8091')).rejects.toThrow()
|
||||||
|
|
||||||
|
// proxy at _proxyUrl was ignored
|
||||||
|
expect(_proxyConnects).toEqual([])
|
||||||
|
} finally {
|
||||||
|
server.close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {
|
it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {
|
||||||
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
|
|
|
@ -25,6 +25,11 @@ export function checkBypass(reqUrl: URL): boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reqHost = reqUrl.hostname
|
||||||
|
if (isLoopbackAddress(reqHost)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
|
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
|
||||||
if (!noProxy) {
|
if (!noProxy) {
|
||||||
return false
|
return false
|
||||||
|
@ -67,3 +72,13 @@ export function checkBypass(reqUrl: URL): boolean {
|
||||||
|
|
||||||
return false
|
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]')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue