PAC-X009 · unanchored-substring-pattern

Pattern with leading and trailing * is a substring match

high · 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/*").

Examples

Bad

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

Good

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

Engine behaviour

EngineBehaviourSource
chromium >=52The 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.lab, verified 2026-10-12
firefoxThe 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.lab, verified 2026-10-12
winhttpThe 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.lab, verified 2026-10-12

Source: code = read in the engine's source, doc = vendor documentation, lab = observed in a lab run, expert = practitioner knowledge, not yet verified.

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

References

Last updated: