From 1f4b3fac06b689186037c0a52e1e876e18de521d Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Wed, 1 Mar 2023 13:48:44 +0000 Subject: [PATCH] Revert "Bypass proxy on loopback IPs" This reverts commit 8d92c9c90351cb195ff8bb3c61da483d61db39e7. --- packages/http-client/__tests__/proxy.test.ts | 26 ++++++-------------- packages/http-client/src/proxy.ts | 10 -------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/packages/http-client/__tests__/proxy.test.ts b/packages/http-client/__tests__/proxy.test.ts index 368e0d29..ccbceec2 100644 --- a/packages/http-client/__tests__/proxy.test.ts +++ b/packages/http-client/__tests__/proxy.test.ts @@ -223,29 +223,19 @@ describe('proxy', () => { expect(_proxyConnects).toEqual(['httpbin.org:443']) }) -it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => { - // setup a server listening on localhost:8091 - var server = http.createServer(function (request, response) { - response.writeHead(200); - request.pipe(response); - }); - await server.listen(8091) - try { - process.env['http_proxy'] = _proxyUrl + it('HttpClient does basic https get request when bypass proxy', async () => { + process.env['https_proxy'] = _proxyUrl + process.env['no_proxy'] = 'httpbin.org' const httpClient = new httpm.HttpClient() const res: httpm.HttpClientResponse = await httpClient.get( - 'http://localhost:8091' + 'https://httpbin.org/get' ) expect(res.message.statusCode).toBe(200) const body: string = await res.readBody() - expect(body).toEqual(''); - // proxy at _proxyUrl was ignored - expect(_proxyConnects).toEqual(undefined) - } - finally { - await server.close() - } -}) + const obj = JSON.parse(body) + expect(obj.url).toBe('https://httpbin.org/get') + expect(_proxyConnects).toHaveLength(0) + }) it('proxyAuth not set in tunnel agent when authentication is not provided', async () => { process.env['https_proxy'] = 'http://127.0.0.1:8080' diff --git a/packages/http-client/src/proxy.ts b/packages/http-client/src/proxy.ts index e4a3e49a..e4e43a54 100644 --- a/packages/http-client/src/proxy.ts +++ b/packages/http-client/src/proxy.ts @@ -25,11 +25,6 @@ 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 @@ -71,8 +66,3 @@ 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') -}