Hostname pattern applied to url instead of host
high
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 ashttps://host:port/only. Forhttp://they keep path and query. A user name and password before the host and the#fragmentare 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 tohttps://host:port/and passeshttp://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.
Examples
Bad
function FindProxyForURL(url, host) {
if (shExpMatch(url, "*.corp.example")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*.corp.example")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| chromium | 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/. | 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. | lab, verified 2026-10-12 |
| pacparser | shExpMatch(url, "example.com") does not match http://example.com/x; the same pattern on host does. | 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. | 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. | lab, verified 2026-10-11 |
The PAC functions this rule is about
shExpMatch(): Shell-glob match of str against pattern; * matches any sequence, ? one character. The whole string must match.
Related rules
- Pattern with leading and trailing * is a substring match PAC-X009
- isPlainHostName called with url PAC-C005
- URL pattern pinned to http:// only PAC-C015
- Port matched as a substring of the URL PAC-X008