Skip to content

Commit d45b05d

Browse files
committed
fix(security): ignore a malformed CIDR NO_PROXY entry
10.0.0.0/8/junk parsed as /8. An entry with extra segments is dropped like any other unparseable entry, and the TSDoc says IP entries match within their address family.
1 parent 9fcf4a2 commit d45b05d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎apps/sim/lib/core/network/environment-proxy.server.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ describe('proxy selection from the environment', () => {
389389
target: 'https://11.0.0.1/',
390390
proxy: 'http://p:3128/',
391391
},
392+
{
393+
case: 'a malformed CIDR NO_PROXY entry is ignored rather than read as its first prefix',
394+
env: { HTTPS_PROXY: 'http://p:3128', NO_PROXY: '10.0.0.0/8/junk' },
395+
target: 'https://10.20.30.40/',
396+
proxy: 'http://p:3128/',
397+
},
392398
{
393399
case: 'an IPv6 CIDR NO_PROXY entry excludes addresses inside the range',
394400
env: { HTTP_PROXY: 'http://p:3128', NO_PROXY: 'fd00::/8' },

‎packages/security/src/environment-proxy.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ function parseNoProxyEntry(entry: string): NoProxyRule | null {
4141
host = withPort[1]
4242
port = Number(withPort[2])
4343
}
44-
const [address, prefix] = host.split('/')
44+
const [address, prefix, ...rest] = host.split('/')
4545
const family = ipFamily(address)
46+
if (rest.length > 0) return null
4647
if (!family) return { kind: 'domain', domain: host.replace(/^\*?\./, '').toLowerCase(), port }
4748
const addresses = new BlockList()
4849
try {
@@ -74,7 +75,7 @@ function noProxyRules(raw: string): NoProxyRule[] {
7475
* Whether `NO_PROXY` sends this destination direct, with curl's matching: `*` matches
7576
* everything; `example.com`, `.example.com` and `*.example.com` all match the domain and
7677
* every subdomain; `host:port` and `[v6]:port` match only that port; IP entries match any
77-
* spelling of the address; and `10.0.0.0/8` or `fd00::/8` match IP-literal destinations in
78+
* spelling of the address in the same address family; and `10.0.0.0/8` or `fd00::/8` match IP-literal destinations in
7879
* the range (never a hostname, which is not resolved here).
7980
*/
8081
function isExcludedByNoProxy(hostname: string, port: number): boolean {

0 commit comments

Comments
 (0)