# Trailing * in a host pattern matches attacker-controlled suffixes

Source: https://findproxyforurl.net/rules/shexpmatch-trailing-asterisk/ · last updated 2026-10-12

Rule PAC-X002 (`shexpmatch-trailing-asterisk`), severity high, category: Security and fail-safety, top 20 #3.

shExpMatch(host, "example.com*") matches example.com.evil.test and example.comms.test. Anyone who controls a domain can append the trusted name as a subdomain label and inherit the rule.

## Why it matters

`shExpMatch` is a glob over the whole string. A trailing `*` after a hostname does not mean
"this domain"; it means "any string that starts with these characters". `example.com*`
matches `example.com.evil.test` (lab, 2026-05-20), `example.com-cdn.test` and
`example.comms.test`. Registering such names requires no cooperation from the owner of
`example.com`. If the rule grants DIRECT or a privileged proxy, an attacker gets the same
treatment for a host they control. A trailing `*` after an IP prefix (`192.168.1.1*`) has
the same problem and additionally matches `192.168.1.10` through `192.168.1.19`.

Trailing `*` is legitimate in URL patterns after a slash (`http://intranet.corp.example/*`)
where it stands for the path. It is also accepted when an `isInNet` call on the same host,
in the same `&&` condition, confirms the match: `shExpMatch(host, "build*") &&
isInNet(host, "10.0.0.0", "255.0.0.0")` only matches hosts whose address is inside that network. Joined with
`||`, or with isInNet testing something else, the pattern is still reported.


## How to fix

Match the domain exactly (host == "example.com") and its subdomains with "*.example.com" or dnsDomainIs(host, ".example.com"); end a host pattern with * only when isInNet on the same host confirms it in the same && condition.

## Bad

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

## Good

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

## Engine behaviour

- pacparser: "example.com*" matches example.com.evil.test (source: lab, verified 2026-05-20)
