# IP range matched as a text prefix

Source: https://findproxyforurl.net/rules/rfc1918-string-pattern/ · last updated 2026-10-12

Rule PAC-X006 (`rfc1918-string-pattern`), severity high, category: Security and fail-safety, top 20 #9.

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 example
  `shExpMatch(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 `host` is 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.

## Bad

```js
function FindProxyForURL(url, host) {
  if (shExpMatch(host, "172.*") || shExpMatch(host, "127.*")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```

## Good

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

## Engine behaviour

- pacparser: "127.*" matches the hostname 127.foo.evil.test; "127example.test" does not (the dot is required). (source: lab, verified 2026-05-20)
