PAC-P001 · dns-function-on-hot-path

DNS function on the path of every request

high · Performance · Top 20 #13

dnsResolve, isResolvable and isInNet on a hostname make the route depend on DNS. The engines cache answers, so only the first request to a name waits; when DNS does not answer, every request waits (about 12 s per call on Windows). Most PACs can decide on the hostname alone.

Why it matters

Every connection runs FindProxyForURL, and a DNS call there can make the connection wait for the resolver. Caches hide most of the cost: only the first request for a name sends a DNS query, and repeats are answered from the browser’s or the system’s cache until the answer expires. The cost shows when DNS is slow or cannot be reached, for example on a laptop outside the company network: then each lookup waits for a timeout, about 12 seconds on Windows 11 (lab, 2026-10-14), and Chrome, Edge and Windows (WinHTTP) do not remember such a failure for the next request. Each different name is a lookup of its own, and Chrome and Edge run the script again for every new name. The dependency is binary: one DNS call makes the PAC depend on DNS, zero calls do not; “minimising” lookups does not remove the dependency. DNS answers are also the one input an attacker on a hostile network controls, and a failed lookup returns a null-like value that makes isInNet false, so the request silently takes the default route.

Order the function so that string rules (isPlainHostName, dnsDomainIs, shExpMatch, IP-literal isInNet) return first, and keep DNS-dependent rules for the few cases that cannot be expressed on the hostname, after everything else.

How to fix

Decide on hostname patterns; if an address check is unavoidable, first make sure the host is an IP address, then call isInNet (for example shExpMatch(host, "10.*") && isInNet(host, "10.0.0.0", "255.0.0.0"), or /^[0-9.]+$/.test(host) && isInNet(...), the same test kept in a variable or helper function, host.match(...) != null, or an early return for hosts that are not addresses); otherwise place the check after all string rules and hoist the dnsResolve result.

Examples

Bad

function FindProxyForURL(url, host) {
  if (isInNet(host, "10.0.0.0", "255.0.0.0")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open bad example in checker

Good

function FindProxyForURL(url, host) {
  if (isPlainHostName(host) || dnsDomainIs(host, ".corp.example")) {
    return "DIRECT";
  }
  if (/^\d+\.\d+\.\d+\.\d+$/.test(host) && isInNet(host, "10.0.0.0", "255.0.0.0")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open good example in checker

Engine behaviour

EngineBehaviourSource
chromiumEach name whose answer is not at hand stops the script; it runs again from the start once the answer is in. Answers of one request are kept in a table, at most 20 different names.code, verified 2026-10-14 · ref
firefoxdnsResolve blocks the PAC thread until the browser's DNS service answers; there is no table in the PAC engine, the browser's DNS cache answers repeats.code, verified 2026-10-14 · ref
winhttpThe script waits on every DNS call. When the DNS server does not answer, each call waits about 12 s and the failure is not kept, not even inside one run (Windows 11, lab).lab, verified 2026-10-16

Source: code = read in the engine's source, doc = vendor documentation, lab = observed in a lab run, expert = practitioner knowledge, not yet verified.

The PAC functions this rule is about

  • isResolvable(): True if the host name resolves in DNS. The script waits for the resolver, which usually answers from a cache.
  • isInNet(): True if the IP address of host is in the network pattern/mask. Resolves host via DNS if it is not an IP literal.
  • dnsResolve(): Resolves a host name to an IP address string, or null when the name does not resolve (false in Windows). The script waits for the answer; repeats for the same name come from a cache.

Related rules

References

Last updated: