# Hostname pattern applied to url instead of host

Source: https://findproxyforurl.net/rules/url-instead-of-host/ · last updated 2026-10-12

Rule PAC-C001 (`url-instead-of-host`), severity high, category: Correctness, top 20 #2.

url is the request address as the browser passes it (scheme, host and port always; path, query or user name only in some engines); host is the bare hostname. A hostname pattern tested against url either never matches or matches far too much. The most common PAC mistake.

## Why it matters

The two arguments are different strings. `shExpMatch(url, "www.example.com")` is never true
because `url` starts with `http://`. `dnsDomainIs(url, ".example.com")` is never true because
`url` ends with a path. Authors then "fix" it with wildcards (`*example.com*`), which turns
the test into a substring match over a string whose query part is controlled by whoever
writes the link (PAC-X009).

There is a second trap: what `url` holds depends on the browser. Measured in the lab:

- Chrome and Edge (Chromium 145, and Edge 155 on Windows, 2026-10-12) pass `https://` addresses as
  `https://host:port/` only. For `http://` they keep path and query. A user name and
  password before the host and the `#fragment` are always removed (since Chrome 52).
- Firefox (157 and 140 ESR, and 156 on Windows, 2026-10-12) removes path, query and fragment from every
  address, http as well as https, but keeps a user name and password: for
  `https://a.example:x@b.example/` the script sees exactly that text.
- Windows (WinHTTP, 2026-10-11 and 2026-10-12) cuts `https://` addresses to
  `https://host:port/` and passes `http://` addresses with path, query and fragment. A user
  name and password before the host are removed for both. Some Windows programs (Java and system
  components) also pass http addresses without the path, and Windows reused one earlier
  answer for later requests to the same host and scheme with another path or port.

So a path-based decision only works for plain http outside Firefox, and a wildcard test over
`url` can be fooled through the query (Chrome, Windows, http only) or through a fake user
name in front of the host (Firefox, also https). Hostname decisions belong on `host`;
`url` is for the scheme and, with these limits, for the path of plain http requests.


## How to fix

Use host for hostname checks (shExpMatch(host, "*.example.com"), dnsDomainIs(host, ".example.com")); use url only for scheme-based decisions.

## Bad

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

## Good

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

## Engine behaviour

- chromium >=52: For https:// URLs the script sees only scheme://host:port/; path, query and fragment are removed (since Chrome 52; the opt-out was removed in Chrome 75). http:// URLs keep path and query. A user name and password before the host are always removed, for http too, so https://a.example:x@b.example/ reaches the script as https://b.example/. (source: lab, verified 2026-10-12)
- firefox: Path, query and fragment are removed for every scheme, http too (preference network.proxy.autoconfig_url.include_path, default false). A user name and password before the host are kept, so https://a.example:x@b.example/x reaches the script as https://a.example:x@b.example/ and shExpMatch(url, "*a.example*") is true. (source: lab, verified 2026-10-12)
- pacparser: shExpMatch(url, "example.com") does not match http://example.com/x; the same pattern on host does. (source: lab, verified 2026-05-20)
- winhttp: https URLs are cut to scheme://host:port/ (path, query and user name removed); http URLs keep path, query and fragment, but a user name and password before the host are removed there too. Later requests to the same host and scheme with a different path or port could get an earlier, cached answer. (source: lab, verified 2026-10-12)
- wininet: WinINet and .NET programs passed http URLs with the path; Java and some Windows system components passed http URLs without it. (source: lab, verified 2026-10-11)
