DNS-dependent rule placed before string rules
low
Rules execute in source order and the first match returns. When a DNS-dependent rule precedes string rules, requests that a later cheap rule would have decided still depend on DNS. The first request to each name waits for the lookup, and every request waits when DNS does not answer.
Why it matters
isPlainHostName, literal comparisons, shExpMatch and dnsDomainIs cost microseconds;
dnsResolve, isResolvable and isInNet on a name cost a resolver round trip. Putting
the cheap, frequently matching rules first means most requests never reach the expensive
ones. This is the ordering rule; PAC-P001 is the stronger statement that the expensive rules
should ideally not exist.
How to fix
Move isPlainHostName, host == and suffix/glob rules above any DNS-dependent rule. An isInNet call that only runs after a test that the host is an IP address (shExpMatch(host, "10.*") &&, an anchored regular expression such as /^[0-9.]+$/, the same test kept in a variable or helper function, or host.match(...) != null) does no DNS lookup for ordinary names and is not reported.
Examples
Bad
function FindProxyForURL(url, host) {
var ip = dnsResolve(host);
if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
return "DIRECT";
}
if (isPlainHostName(host)) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (isPlainHostName(host)) {
return "DIRECT";
}
var ip = dnsResolve(host);
if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checker