1
0
Fork 0

strip leading dot + '*' match all + testcases

pull/1223/head
Felix Luthman 2022-10-30 16:39:56 +01:00
parent da7e8df206
commit 586ad49adf
No known key found for this signature in database
GPG Key ID: 4082CB7A71002C3A
2 changed files with 35 additions and 1 deletions

View File

@ -145,6 +145,30 @@ describe('proxy', () => {
expect(bypass).toBeFalsy() expect(bypass).toBeFalsy()
}) })
it('checkBypass returns true if host with subdomain in no_proxy', () => {
process.env['no_proxy'] = 'myserver.com'
const bypass = pm.checkBypass(new URL('https://sub.myserver.com'))
expect(bypass).toBeTruthy()
})
it('checkBypass returns true if host with leading dot in no_proxy', () => {
process.env['no_proxy'] = '.myserver.com'
const bypass = pm.checkBypass(new URL('https://myserver.com'))
expect(bypass).toBeTruthy()
})
it('checkBypass returns false if no_proxy is subdomain', () => {
process.env['no_proxy'] = 'myserver.com'
const bypass = pm.checkBypass(new URL('https://myserver.com.evil.org'))
expect(bypass).toBeFalsy()
})
it('checkBypass returns true if no_proxy is "*"', () => {
process.env['no_proxy'] = '*'
const bypass = pm.checkBypass(new URL('https://anything.whatsoever.com'))
expect(bypass).toBeTruthy()
})
it('HttpClient does basic http get request through proxy', async () => { it('HttpClient does basic http get request through proxy', async () => {
process.env['http_proxy'] = _proxyUrl process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient() const httpClient = new httpm.HttpClient()

View File

@ -30,6 +30,11 @@ export function checkBypass(reqUrl: URL): boolean {
return false return false
} }
// '*' match all hosts (https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#standardizing-no_proxy)
if (noProxy === '*') {
return true
}
// Determine the request port // Determine the request port
let reqPort: number | undefined let reqPort: number | undefined
if (reqUrl.port) { if (reqUrl.port) {
@ -50,8 +55,13 @@ export function checkBypass(reqUrl: URL): boolean {
for (const upperNoProxyItem of noProxy for (const upperNoProxyItem of noProxy
.split(',') .split(',')
.map(x => x.trim().toUpperCase()) .map(x => x.trim().toUpperCase())
.map(x => (x.startsWith('.') ? x.substring(1) : x)) // Strip leading dot (https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#standardizing-no_proxy)
.filter(x => x)) { .filter(x => x)) {
if (upperReqHosts.some(x => x.includes(upperNoProxyItem))) { if (
upperReqHosts.some(
x => x === upperNoProxyItem || x.endsWith(`.${upperNoProxyItem}`)
)
) {
return true return true
} }
} }