# isInNet called with a hostname

Source: https://findproxyforurl.net/rules/isinnet-on-hostname/ · last updated 2026-10-14

Rule PAC-P002 (`isinnet-on-hostname`), severity medium, category: Performance, top 20 #16.

isInNet resolves its first argument when it is not an IP address. Unguarded, it makes every non-IP request depend on DNS. The first request to a name waits, every request waits when DNS does not answer, a failed lookup fails open, and only one of several addresses is checked.

## Why it matters

`isInNet(host, "10.0.0.0", "255.0.0.0")` looks like a cheap arithmetic test but is
`isInNet(dnsResolve(host), ...)` in disguise whenever `host` is a name. If the name has
several A records, only one is compared, and which one is engine-dependent. If resolution
fails, the test is false and the request falls through. The intended check ("is this an
address in our range") is cheap and deterministic when applied only to IP literals.

A guard is a cheap test that lets only address-like hosts reach isInNet. It has to test the
same value as isInNet (`host` in `isInNet(host, ...)`) and come before the call: earlier in
the same `&&` condition, in an enclosing `if`, or as an early exit at the start of the function.
These guards are accepted:
- a regular expression that only accepts addresses, such as `/^\d+\.\d+\.\d+\.\d+$/`,
  `/^\d{1,3}(\.\d{1,3}){3}$/` or `/^[0-9.]+$/`, written as `re.test(host)`, `host.match(re)`,
  `RegExp("...").test(host)`, `host.match(re) != null`, or through a variable that holds the
  expression;
- the result of such a test kept in a variable that is not changed later, such as
  `var isIp = /^\d+\.\d+\.\d+\.\d+$/.test(host); if (isIp && isInNet(host, ...))`, also as an
  early exit `if (!isIp) return "PROXY ...";`;
- a function in the file that returns such a test of its argument, such as `isIpV4(host)`;
- an early exit: `if (!/^\d+\.\d+\.\d+\.\d+$/.test(host)) return "PROXY ...";` before the
  isInNet rules;
- a text prefix of the range, such as `shExpMatch(host, "10.*") && isInNet(host, "10.0.0.0", "255.0.0.0")`.
  A name that happens to start with the same digits, such as `10.foo.example`, is still looked
  up, but ordinary host names are not.

Tests that let ordinary names through are not accepted, because names still reach isInNet:
`shExpMatch(host, "*.*.*.*")` and `host.split(".").length == 4` (every name with four labels),
`shExpMatch(host, "[0-9]*")` and a test of the first character (every name that starts with a
digit). `re.test(host) != null` is no guard either: test() gives true or false, never null, so
the comparison is always true.

If names must be resolved, do it once and explicitly (PAC-P004) after all string rules.


## How to fix

Guard isInNet so it only sees addresses, e.g. /^\d+\.\d+\.\d+\.\d+$/.test(host) && isInNet(host, "10.0.0.0", "255.0.0.0") or shExpMatch(host, "10.*") && isInNet(host, "10.0.0.0", "255.0.0.0"); or resolve once explicitly and compare the result.

## Bad

```js
function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".corp.example")) {
    return "DIRECT";
  }
  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 (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: isInNet resolves a non-literal first argument via dnsResolve in the helper library. (source: code, verified 2026-10-04)
