# DNS function on the path of every request

Source: https://findproxyforurl.net/rules/dns-function-on-hot-path/ · last updated 2026-10-16

Rule PAC-P001 (`dns-function-on-hot-path`), severity high, category: 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.

## Bad

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

## Good

```js
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";
}
```

## Engine behaviour

- chromium: Each 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. (source: code, verified 2026-10-14)
- firefox: dnsResolve 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. (source: code, verified 2026-10-14)
- winhttp: The 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). (source: lab, verified 2026-10-16)
