# Pattern with leading and trailing * is a substring match

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

Rule PAC-X009 (`unanchored-substring-pattern`), severity high, category: Security and fail-safety.

shExpMatch(host, "*example.com*") or shExpMatch(url, "*abc*") is true for any string that contains the characters anywhere. Over url this includes query strings an attacker controls; over host it includes look-alike domains.

## Why it matters

A glob that starts and ends with `*` is a contains-test. `shExpMatch(url, "*example.com*")`
matches `http://evil.test/?r=example.com`; whoever controls a link controls the query
string, so the branch (typically DIRECT) is reachable for any destination. Over `host`,
`*abc*` matches `abc.test`, `xyzabc.example` and `example.com.abc-attacker.test`.

Which trick works depends on what the browser puts into `url` (lab, 2026-10-12):

- A query or path that contains the text (`http://evil.test/?r=example.com`,
  `http://evil.test/x.example.com`) works in Chrome, Edge and Windows for http addresses.
  For https they pass only `https://host:port/`, and Firefox removes path and query
  everywhere, so there it does nothing.
- A fake user name in front of the host (`https://example.com:x@evil.test/`) works in
  Firefox for http and https, because Firefox keeps user name and password in `url`.
  Chrome, Edge and Windows remove them, from http and https addresses alike.

So every major browser has at least one way to reach the branch, and the finding stays.

Patterns that contain `://` or end in `/*` are anchored at the scheme or path boundary and
are not flagged. The grade is capped at C because the bypass is externally triggerable
without any control over DNS or the network.


## How to fix

Anchor the pattern: use host with "*.example.com" / host == "example.com", or a URL pattern with scheme and path boundaries ("http://www.example.com/*").

## Bad

```js
function FindProxyForURL(url, host) {
  if (shExpMatch(url, "*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

- chromium >=52: The query and path trick works for http (path and query reach the script); for https only https://host:port/ reaches it. The user-name trick does not work; user name and password are removed for http and https. (source: lab, verified 2026-10-12)
- firefox: The user-name trick works for http and https (https://example.com:x@evil.test/ reaches the script unchanged). The query and path trick does not; path and query are removed for every scheme. (source: lab, verified 2026-10-12)
- winhttp: The query and path trick works for http (path and query reach the script). The user-name trick does not work; https URLs are cut to https://host:port/, and a user name and password are removed from http URLs too. (source: lab, verified 2026-10-12)
