IP range matched as a text prefix
high
shExpMatch(host, "127.*") or "10.*" compares characters, not addresses. On its own it matches the hostname 127.foo.evil.test and, for "172.*", every public 172.x address. Use isInNet with a mask, or confirm the text match with isInNet on the same host in the same && condition.
Why it matters
host is a string. shExpMatch(host, "127.*") is true for 127.0.0.1 but also for the
hostname 127.foo.evil.test (lab, 2026-05-20) and any name starting with 127.. "172.*" covers
172.16.0.0/12 and the public ranges 172.0.0.0-172.15.255.255 and
172.32.0.0-172.255.255.255. "192.168.*" matches 192.168.evil.test. A DIRECT branch
written this way can be reached by anyone who controls a hostname starting with digits.
The address test is isInNet(host, "127.0.0.0", "255.0.0.0"). Two forms are accepted:
- the text prefix confirmed by isInNet in the same
&&condition, for exampleshExpMatch(host, "10.*") && isInNet(host, "10.0.0.0", "255.0.0.0"). The cheap text test runs first, so isInNet (which can trigger a DNS lookup, PAC-P002) only runs for hosts that start with the right digits, and isInNet makes sure the host really is in the range; - a test that
hostis an IP address in front of the pattern or of isInNet, for example/^\d+\.\d+\.\d+\.\d+$/.test(host) && isInNet(host, "10.0.0.0", "255.0.0.0"). Then no host name reaches the pattern and no DNS lookup is triggered. The page of PAC-P002 lists every form of this test that is accepted, including an early return for hosts that are not addresses.
The pattern is still reported when isInNet is joined with || instead of &&, when it tests
something other than the same host, or when the pattern stands alone.
How to fix
Confirm the pattern with isInNet on the same host in the same && condition, e.g. shExpMatch(host, "10.*") && isInNet(host, "10.0.0.0", "255.0.0.0"); keep "localhost" as a string comparison.
Examples
Bad
function FindProxyForURL(url, host) {
if (shExpMatch(host, "172.*") || shExpMatch(host, "127.*")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (host == "localhost") {
return "DIRECT";
}
if ((shExpMatch(host, "172.*") && isInNet(host, "172.16.0.0", "255.240.0.0")) ||
(shExpMatch(host, "127.*") && isInNet(host, "127.0.0.0", "255.0.0.0"))) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| pacparser | "127.*" matches the hostname 127.foo.evil.test; "127example.test" does not (the dot is required). | lab, verified 2026-05-20 |
The PAC functions this rule is about
shExpMatch(): Shell-glob match of str against pattern; * matches any sequence, ? one character. The whole string must match.
Related rules
- String prefix used to match an IP range PAC-X007
- RFC 1918 range with the wrong mask PAC-C007
- Only 127.0.0.1 excluded instead of 127.0.0.0/8 PAC-C008
- isInNet called with a hostname PAC-P002