Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 1 | # Proxy support in Chrome |
| 2 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 3 | This document establishes basic proxy terminology and describes Chrome-specific |
| 4 | proxy behaviors. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 5 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 6 | [TOC] |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 7 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 8 | ## Proxy server identifiers |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 9 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 10 | A proxy server is an intermediary used for network requests. A proxy server can |
| 11 | be described by its address, along with the proxy scheme that should be used to |
| 12 | communicate with it. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 13 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 14 | This can be written as a string using either the "PAC format" or the "URI |
| 15 | format". |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 16 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 17 | The PAC format is how one names a proxy server in [Proxy |
| 18 | auto-config](https://en.wikipedia.org/wiki/Proxy_auto-config) scripts. For |
| 19 | example: |
| 20 | * `PROXY foo:2138` |
| 21 | * `SOCKS5 foo:1080` |
| 22 | * `DIRECT` |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 23 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 24 | The "URI format" instead encodes the information as a URL. For example: |
| 25 | * `foo:2138` |
| 26 | * `http://foo:2138` |
| 27 | * `socks5://foo:1080` |
| 28 | * `direct://` |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 29 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 30 | The port number is optional in both formats. When omitted, a per-scheme default |
| 31 | is used. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 32 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 33 | See the [Proxy server schemes](#Proxy-server-schemes) section for details on |
| 34 | what schemes Chrome supports, and how to write them in the PAC and URI formats. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 35 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 36 | Most UI surfaces in Chrome (including command lines and policy) expect URI |
| 37 | formatted proxy server identifiers. However outside of Chrome, proxy servers |
| 38 | are generally identified less precisely by just an address -- the proxy |
| 39 | scheme is assumed based on context. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 40 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 41 | In Windows' proxy settings there are host and port fields for the |
| 42 | "HTTP", "Secure", "FTP", and "SOCKS" proxy. With the exception of "SOCKS", |
| 43 | those are all identifiers for insecure HTTP proxy servers (proxy scheme is |
| 44 | assumed as HTTP). |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 45 | |
| 46 | ## Proxy resolution |
| 47 | |
| 48 | Proxying in Chrome is done at the URL level. |
| 49 | |
| 50 | When the browser is asked to fetch a URL, it needs to decide which IP endpoint |
| 51 | to send the request to. This can be either a proxy server, or the target host. |
| 52 | |
| 53 | This is called proxy resolution. The input to proxy resolution is a URL, and |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 54 | the output is an ordered list of [proxy server |
| 55 | identifiers](#Proxy-server-identifiers). |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 56 | |
| 57 | What proxies to use can be described using either: |
| 58 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 59 | * [Manual proxy settings](#Manual-proxy-settings) - proxy resolution is defined |
| 60 | using a declarative set of rules. These rules are expressed as a mapping from |
| 61 | URL scheme to proxy server identifier(s), and a list of proxy bypass rules for |
| 62 | when to go DIRECT instead of using the mapped proxy. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 63 | |
| 64 | * PAC script - proxy resolution is defined using a JavaScript program, that is |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 65 | invoked whenever fetching a URL to get the list of proxy server identifiers |
| 66 | to use. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 67 | |
| 68 | * Auto-detect - the WPAD protocol is used to probe the network (using DHCP/DNS) |
| 69 | and possibly discover the URL of a PAC script. |
| 70 | |
| 71 | ## Proxy server schemes |
| 72 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 73 | When using an explicit proxy in the browser, multiple layers of the network |
| 74 | request are impacted, depending on the scheme that is used. Some implications |
| 75 | of the proxy scheme are: |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 76 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 77 | * Is communication to the proxy done over a secure channel? |
| 78 | * Is name resolution (ex: DNS) done client side, or proxy side? |
| 79 | * What authentication schemes to the proxy server are supported? |
| 80 | * What network traffic can be sent through the proxy? |
| 81 | |
| 82 | Chrome supports these proxy server schemes: |
| 83 | |
| 84 | * [DIRECT](#DIRECT-proxy-scheme) |
| 85 | * [HTTP](#HTTP-proxy-scheme) |
| 86 | * [HTTPS](#HTTPS-proxy-scheme) |
| 87 | * [SOCKSv4](#SOCKSv4-proxy-scheme) |
| 88 | * [SOCKSv5](#SOCKSv5-proxy-scheme) |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 89 | |
| 90 | ### DIRECT proxy scheme |
| 91 | |
| 92 | * Default port: N/A (neither host nor port are applicable) |
| 93 | * Example identifier (PAC): `DIRECT` |
| 94 | * Example identifier (URI): `direct://` |
| 95 | |
| 96 | This is a pseudo proxy scheme that indicates instead of using a proxy we are |
| 97 | sending the request directly to the target server. |
| 98 | |
| 99 | It is imprecise to call this a "proxy server", but it is a convenient abstraction. |
| 100 | |
| 101 | ### HTTP proxy scheme |
| 102 | |
| 103 | * Default port: 80 |
| 104 | * Example identifier (PAC): `PROXY proxy:8080`, `proxy` (non-standard; don't use) |
| 105 | * Example identifiers (URI): `http://proxy:8080`, `proxy:8080` (can omit scheme) |
| 106 | |
| 107 | Generally when one refers to a "proxy server" or "web proxy", they are talking |
| 108 | about an HTTP proxy. |
| 109 | |
| 110 | When using an HTTP proxy in Chrome, name resolution is always deferred to the |
| 111 | proxy. HTTP proxies can proxy `http://`, `https://`, `ws://` and `wss://` URLs. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 112 | |
| 113 | Communication to HTTP proxy servers is insecure, meaning proxied `http://` |
| 114 | requests are sent in the clear. When proxying `https://` requests through an |
| 115 | HTTP proxy, the TLS exchange is forwarded through the proxy using the `CONNECT` |
| 116 | method, so end-to-end encryption is not broken. However when establishing the |
| 117 | tunnel, the hostname of the target URL is sent to the proxy server in the |
| 118 | clear. |
| 119 | |
| 120 | HTTP proxies in Chrome support the same HTTP authentiation schemes as for |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 121 | target servers: Basic, Digest, Negotiate, NTLM. |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 122 | |
| 123 | ### HTTPS proxy scheme |
| 124 | |
| 125 | * Default port: 443 |
| 126 | * Example identifier (PAC): `HTTPS proxy:8080` |
| 127 | * Example identifier (URI): `https://proxy:8080` |
| 128 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 129 | This works like an [HTTP proxy](#HTTP-proxy-scheme), except the |
| 130 | communication to the proxy server is protected by TLS, and may negotiate |
Eric Roman | 77bc14c | 2019-06-05 20:40:52 | [diff] [blame] | 131 | HTTP/2 (but not QUIC). |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 132 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 133 | Because the connection to the proxy server is secure, https:// requests |
| 134 | sent through the proxy are not sent in the clear as with an HTTP proxy. |
| 135 | Similarly, since CONNECT requests are sent over a protected channel, the |
| 136 | hostnames for proxied https:// URLs is also not revealed. |
| 137 | |
| 138 | In addition to the usual HTTP authentication methods, HTTPS proxies also |
| 139 | support client certificates. |
| 140 | |
| 141 | HTTPS proxies using HTTP/2 can offer better performance in Chrome than a |
| 142 | regular HTTP proxy due to higher connection limits (HTTP/1.1 proxies in Chrome |
| 143 | are limited to 32 simultaneous connections across all domains). |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 144 | |
Eric Roman | c4abf6ca | 2019-06-06 21:29:20 | [diff] [blame] | 145 | Chrome, Firefox, and Opera support HTTPS proxies; however, most older HTTP |
| 146 | stacks do not. |
| 147 | |
| 148 | Specifying an HTTPS proxy is generally not possible through system proxy |
| 149 | settings. Instead, one must use either a PAC script or a Chrome proxy setting |
| 150 | (command line, extension, or policy). |
| 151 | |
| 152 | See the dev.chromium.org document on [secure web |
| 153 | proxies](http://dev.chromium.org/developers/design-documents/secure-web-proxy) |
| 154 | for tips on how to run and test against an HTTPS proxy. |
| 155 | |
Eric Roman | 5ee3be2 | 2019-05-23 17:09:27 | [diff] [blame] | 156 | ### SOCKSv4 proxy scheme |
| 157 | |
| 158 | * Default port: 1080 |
| 159 | * Example identifiers (PAC): `SOCKS4 proxy:8080`, `SOCKS proxy:8080` |
| 160 | * Example identifier (URI): `socks4://proxy:8080` |
| 161 | |
| 162 | SOCKSv4 is a simple transport layer proxy that wraps a TCP socket. Its use |
| 163 | is transparent to the rest of the protocol stack; after an initial |
| 164 | handshake when connecting the TCP socket (to the proxy), the rest of the |
| 165 | loading stack is unchanged. |
| 166 | |
| 167 | No proxy authentication methods are supported for SOCKSv4. |
| 168 | |
| 169 | When using a SOCKSv4 proxy, name resolution for target hosts is always done |
| 170 | client side, and moreover must resolve to an IPv4 address (SOCKSv4 encodes |
| 171 | target address as 4 octets, so IPv6 targets are not possible). |
| 172 | |
| 173 | There are extensions to SOCKSv4 that allow for proxy side name resolution, and |
| 174 | IPv6, namely SOCKSv4a. However Chrome does not allow configuring, or falling |
| 175 | back to v4a. |
| 176 | |
| 177 | A better alternative is to just use the newer version of the protocol, SOCKSv5 |
| 178 | (which is still 20+ years old). |
| 179 | |
| 180 | ### SOCKSv5 proxy scheme |
| 181 | |
| 182 | * Default port: 1080 |
| 183 | * Example identifier (PAC): `SOCKS5 proxy:8080` |
| 184 | * Example identifiers (URI): `socks://proxy:8080`, `socks5://proxy:8080` |
| 185 | |
| 186 | [SOCKSv5](https://tools.ietf.org/html/rfc1928) is a transport layer proxy that |
| 187 | wraps a TCP socket, and allows for name resolution to be deferred to the proxy. |
| 188 | |
| 189 | In Chrome when a proxy's scheme is set to SOCKSv5, name resolution is always |
| 190 | done proxy side (even though the protocol allows for client side as well). In |
| 191 | Firefox client side vs proxy side name resolution can be configured with |
| 192 | `network.proxy.socks_remote_dns`; Chrome has no equivalent option and will |
| 193 | always use proxy side resolution. |
| 194 | |
| 195 | No authentication methods are supported for SOCKSv5 in Chrome (although some do |
| 196 | exist for the protocol). |
| 197 | |
| 198 | A handy way to create a SOCKSv5 proxy is with `ssh -D`, which can be used to |
| 199 | tunnel web traffic to a remote host over SSH. |
| 200 | |
| 201 | In Chrome SOCKSv5 is only used to proxy TCP-based URL requests. It cannot be |
| 202 | used to relay UDP traffic. |
| 203 | |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 204 | ## Manual proxy settings |
| 205 | |
| 206 | The simplest way to configure proxy resolution is by providing a static list of |
| 207 | rules comprised of: |
| 208 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 209 | 1. A mapping of URL schemes to [proxy server identifiers](#Proxy-server-identifiers). |
| 210 | 2. A list of [proxy bypass rules](#Proxy-bypass-rules) |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 211 | |
| 212 | We refer to this mode of configuration as "manual proxy settings". |
| 213 | |
| 214 | Manual proxy settings can succinctly describe setups like: |
| 215 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 216 | * Use proxy `http://foo:8080` for all requests |
| 217 | * Use proxy `http://foo:8080` for all requests except those to a `google.com` |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 218 | subdomain. |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 219 | * Use proxy `http://foo:8080` for all `https://` requests, and proxy |
| 220 | `socsk5://mysocks:90` for everything else |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 221 | |
| 222 | Although manual proxy settings are a ubiquituous way to configure proxies |
| 223 | across platforms, there is no standard representation or feature set. |
| 224 | |
| 225 | Chrome's manual proxy settings most closely resembles that of WinInet. But it |
| 226 | also supports idioms from other platforms -- for instance KDE's notion of |
| 227 | reversing the bypass list, or Gnome's interpretation of bypass patterns as |
| 228 | suffix matches. |
| 229 | |
| 230 | When defining manual proxy settings in Chrome, we specify three (possibly |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 231 | empty) lists of [proxy server identifiers](#Proxy-server-identifiers). |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 232 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 233 | * proxies for HTTP - A list of proxy server identifiers to use for `http://` |
| 234 | requests, if non-empty. |
| 235 | * proxies for HTTPS - A list of proxy server identifiers to use for |
| 236 | `https://` requests, if non-empty. |
| 237 | * other proxies - A list of proxy server identifiers to use for everything |
| 238 | else (whatever isn't matched by the other two lists) |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 239 | |
| 240 | There are a lot of ways to end up with manual proxy settings in Chrome |
| 241 | (discussed in other sections). |
| 242 | |
| 243 | The following examples will use the command line method. Launching Chrome with |
| 244 | `--proxy-server=XXX` (and optionally `--proxy-bypass-list=YYY`) |
| 245 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 246 | Example: To use proxy `http://foo:8080` for all requests we can launch |
| 247 | Chrome with `--proxy-server="http://foo:8080"`. This translates to: |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 248 | |
| 249 | * proxies for HTTP - *empty* |
| 250 | * proxies for HTTPS - *empty* |
| 251 | * other proxies - `http://foo:8080` |
| 252 | |
| 253 | With the above configuration, if the proxy server was unreachable all requests |
| 254 | would fail with `ERR_PROXY_CONNECTION_FAILED`. To address this we could add a |
| 255 | fallback to `DIRECT` by launching using |
| 256 | `--proxy-server="http://foo:8080,direct://"` (note the comma separated list). |
| 257 | This command line means: |
| 258 | |
| 259 | * proxies for HTTP - *empty* |
| 260 | * proxies for HTTPS - *empty* |
| 261 | * other proxies - `http://foo:8080`, `direct://` |
| 262 | |
| 263 | If instead we wanted to proxy only `http://` URLs through the |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 264 | HTTPS proxy `https://foo:443`, and have everything else use the SOCKSv5 proxy |
| 265 | `socks5://mysocks:1080` we could launch Chrome with |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 266 | `--proxy-server="http=https://foo:443;socks=socks5://mysocks:1080"`. This now |
| 267 | expands to: |
| 268 | |
| 269 | * proxies for HTTP - `https://foo:443` |
| 270 | * proxies for HTTPS - *empty* |
| 271 | * other proxies - `socks5://mysocks:1080` |
| 272 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 273 | The command line above uses WinInet's proxy map format, with some additional |
| 274 | features: |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 275 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 276 | * Instead of naming proxy servers by just a hostname:port, you can use Chrome's |
| 277 | URI format for proxy server identifiers. In other words, you can prefix the |
| 278 | proxy scheme so it doesn't default to HTTP. |
| 279 | * The `socks=` mapping is understood more broadly as "other proxies". The |
| 280 | subsequent proxy list can include proxies of any scheme, however if the |
| 281 | scheme is omitted it will be understood as SOCKSv4 rather than HTTP. |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 282 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 283 | ### Mapping WebSockets URLs to a proxy |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 284 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 285 | [Manual proxy settings](#Manual-proxy-settings) don't have mappings for `ws://` |
| 286 | or `wss://` URLs. |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 287 | |
| 288 | Selecting a proxy for these URL schemes is a bit different from other URL |
| 289 | schemes. The algorithm that Chrome uses is: |
| 290 | |
| 291 | * If "other proxies" is non-empty use it |
| 292 | * If "proxies for HTTPS" is non-empty use it |
| 293 | * Otherwise use "proxies for HTTP" |
| 294 | |
| 295 | This is per the recommendation in section 4.1.3 of [RFC |
| 296 | 6455](https://tools.ietf.org/html/rfc6455). |
| 297 | |
| 298 | It is possible to route `ws://` and `wss://` separately using a PAC script. |
| 299 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 300 | ### Proxy credentials in manual proxy settings |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 301 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 302 | Most platforms' [manual proxy settings](#Manual-proxy-settings) allow |
| 303 | specifying a cleartext username/password for proxy sign in. Chrome does not |
| 304 | implement this, and will not use any credentials embedded in the proxy |
| 305 | settings. |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 306 | |
| 307 | Proxy authentication will instead go through the ordinary flow to find |
| 308 | credentials. |
| 309 | |
| 310 | ## Proxy bypass rules |
| 311 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 312 | In addition to specifying three lists of [proxy server |
| 313 | identifiers](#proxy-server-identifiers), Chrome's [manual proxy |
| 314 | settings](#Manual-proxy-settings) lets you specify a list of "proxy bypass |
| 315 | rules". |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 316 | |
| 317 | This ruleset determines whether a given URL should skip use of a proxy all |
| 318 | together, even when a proxy is otherwise defined for it. |
| 319 | |
| 320 | This concept is also known by names like "exception list", "exclusion list" or |
| 321 | "no proxy list". |
| 322 | |
| 323 | Proxy bypass rules can be written as an ordered list of strings. Ordering |
| 324 | generally doesn't matter, but may when using subtractive rules. |
| 325 | |
| 326 | When manual proxy settings are specified from the command line, the |
| 327 | `--proxy-bypass-list="RULES"` switch can be used, where `RULES` is a semicolon |
| 328 | or comma separated list of bypass rules. |
| 329 | |
| 330 | Following are the string constructions for the bypass rules that Chrome |
| 331 | supports. They can be used when defining a Chrome manual proxy settings from |
| 332 | command line flags, extensions, or policy. |
| 333 | |
| 334 | When using system proxy settings, one should use the platform's rule format and |
| 335 | not Chrome's. |
| 336 | |
| 337 | ### Bypass rule: Hostname |
| 338 | |
| 339 | ``` |
| 340 | [ URL_SCHEME "://" ] HOSTNAME_PATTERN [ ":" <port> ] |
| 341 | ``` |
| 342 | |
| 343 | Matches a hostname using a wildcard pattern, and an optional scheme and port |
| 344 | restriction. |
| 345 | |
| 346 | Examples: |
| 347 | |
| 348 | * `foobar.com` - Matches URL of any scheme and port, whose normalized host is |
| 349 | `foobar.com` |
| 350 | * `*foobar.com` - Matches URL of any scheme and port, whose normalized host |
| 351 | ends with `foobar.com` (for instance `blahfoobar.com` and `foo.foobar.com`). |
| 352 | * `*.org:443` - Matches URLs of any scheme, using port 443 and whose top level |
| 353 | domain is `.org` |
| 354 | * `https://x.*.y.com:99` - Matches https:// URLs on port 99 whose normalized |
| 355 | hostname matches `x.*.y.com` |
| 356 | |
| 357 | ### Bypass rule: Subdomain |
| 358 | |
| 359 | ``` |
| 360 | [ URL_SCHEME "://" ] "." HOSTNAME_SUFFIX_PATTERN [ ":" PORT ] |
| 361 | ``` |
| 362 | |
| 363 | Hostname patterns that start with a dot are special cased to mean a subdomain |
| 364 | matches. `.foo.com` is effectively another way of writing `*.foo.com`. |
| 365 | |
| 366 | Examples: |
| 367 | |
| 368 | * `.google.com` - Matches `calendar.google.com` and `foo.bar.google.com`, but |
| 369 | not `google.com`. |
| 370 | * `http://.google.com` - Matches only http:// URLs that are a subdomain of `google.com`. |
| 371 | |
| 372 | ### Bypass rule: IP literal |
| 373 | |
| 374 | ``` |
| 375 | [ SCHEME "://" ] IP_LITERAL [ ":" PORT ] |
| 376 | ``` |
| 377 | |
| 378 | Matches URLs that are IP address literals, and optional scheme and port |
| 379 | restrictions. This is a special case of hostname matching that takes into |
| 380 | account IP literal canonicalization. For example the rules `[0:0:0::1]` and |
| 381 | `[::1]` are equivalent (both represent the same IPv6 address). |
| 382 | |
| 383 | Examples: |
| 384 | |
| 385 | * `127.0.0.1` |
| 386 | * `http://127.0.0.1` |
| 387 | * `[::1]` - Matches any URL to the IPv6 loopback address. |
| 388 | * `[0:0::1]` - Same as above |
| 389 | * `http://[::1]:99` - Matches any http:// URL to the IPv6 loopback on port 99 |
| 390 | |
| 391 | ### Bypass rule: IPv4 address range |
| 392 | |
| 393 | ``` |
| 394 | IPV4_LITERAL "/" PREFIX_LENGTH_IN_BITS |
| 395 | ``` |
| 396 | |
| 397 | Matches any URL whose hostname is an IPv4 literal, and falls between the given |
| 398 | address range. |
| 399 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 400 | Note this [only applies to URLs that are IP |
| 401 | literals](#Meaning-of-IP-address-range-bypass-rules). |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 402 | |
| 403 | Examples: |
| 404 | |
| 405 | * `192.168.1.1/16` |
| 406 | |
| 407 | ### Bypass rule: IPv6 address range |
| 408 | |
| 409 | ``` |
| 410 | IPV6_LITERAL "/" PREFIX_LENGTH_IN_BITS |
| 411 | ``` |
| 412 | |
| 413 | Matches any URL that is an IPv6 literal that falls between the given range. |
| 414 | Note that IPv6 literals must *not* be bracketed. |
| 415 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 416 | Note this [only applies to URLs that are IP |
| 417 | literals](#Meaning-of-IP-address-range-bypass-rules). |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 418 | |
| 419 | Examples: |
| 420 | |
| 421 | * `fefe:13::abc/33` |
| 422 | * `[fefe::]/40` -- WRONG! IPv6 literals must not be bracketed. |
| 423 | |
| 424 | ### Bypass rule: Simple hostnames |
| 425 | |
| 426 | ``` |
| 427 | <local> |
| 428 | ``` |
| 429 | |
| 430 | Matches hostnames without a period in them, and that are not IP literals. This |
| 431 | is a naive string search -- meaning that periods appearing *anywhere* count |
| 432 | (including trailing dots!). |
| 433 | |
| 434 | This rule corresponds to the "Exclude simple hostnames" checkbox on macOS and |
| 435 | the "Don't use proxy server for local (intranet) addresses" on Windows. |
| 436 | |
| 437 | The rule name comes from WinInet, and can easily be confused with the concept |
| 438 | of localhost. However the two concepts are completely orthogonal. In practice |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 439 | one wouldn't add rules to bypass localhost, as it is [already done |
| 440 | implicitly](#Implicit-bypass-rules). |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 441 | |
| 442 | ### Bypass rule: Subtract implicit rules |
| 443 | |
| 444 | ``` |
| 445 | <-loopback> |
| 446 | ``` |
| 447 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 448 | *Subtracts* the [implicit proxy bypass rules](#Implicit-bypass-rules) |
| 449 | (localhost and link local addresses). This is generally only needed for test |
David Benjamin | 2cbca1a | 2020-11-09 23:41:36 | [diff] [blame] | 450 | setups. Beware of the security implications to proxying localhost. |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 451 | |
| 452 | Whereas regular bypass rules instruct the browser about URLs that should *not* |
| 453 | use the proxy, this rule has the opposite effect and tells the browser to |
| 454 | instead *use* the proxy. |
| 455 | |
| 456 | Ordering may matter when using a subtractive rule, as rules will be evaluated |
| 457 | in a left-to-right order. `<-loopback>;127.0.0.1` has a subtly different effect |
| 458 | than `127.0.0.1;<-loopback>`. |
| 459 | |
| 460 | ### Meaning of IP address range bypass rules |
| 461 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 462 | The IP address range bypass rules in manual proxy settings applies only to URL |
| 463 | literals. This is not what one would intuitively expect. |
Eric Roman | a11e367d | 2019-05-24 22:08:34 | [diff] [blame] | 464 | |
| 465 | Example: |
| 466 | |
| 467 | Say we have have configured a proxy for all requests, but added a bypass rule |
| 468 | for `192.168.0.0.1/16`. If we now navigate to `http://foo` (which resolves |
| 469 | to `192.168.1.5` in our setup) will the browser connect directly (bypass proxy) |
| 470 | because we have indicated a bypass rule that includes this IP? |
| 471 | |
| 472 | It will go through the proxy. |
| 473 | |
| 474 | The bypass rule in this case is not applicable, since the browser never |
| 475 | actually does a name resolution for `foo`. Proxy resolution happens before |
| 476 | name resolution, and depending on what proxy scheme is subsequently chosen, |
| 477 | client side name resolution may never be performed. |
| 478 | |
| 479 | The usefulness of IP range proxy bypass rules is rather limited, as they only |
| 480 | apply to requests whose URL was explicitly an IP literal. |
| 481 | |
| 482 | If proxy decisions need to be made based on the resolved IP address(es) of a |
| 483 | URL's hostname, one must use a PAC script. |
| 484 | |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 485 | ## Implicit bypass rules |
| 486 | |
Eric Roman | 65019bb | 2019-05-03 20:56:15 | [diff] [blame] | 487 | Requests to certain hosts will not be sent through a proxy, and will instead be |
| 488 | sent directly. |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 489 | |
| 490 | We call these the _implicit bypass rules_. The implicit bypass rules match URLs |
| 491 | whose host portion is either a localhost name or a link-local IP literal. |
| 492 | Essentially it matches: |
| 493 | |
| 494 | ``` |
| 495 | localhost |
| 496 | *.localhost |
| 497 | [::1] |
| 498 | 127.0.0.1/8 |
| 499 | 169.254/16 |
| 500 | [FE80::]/10 |
| 501 | ``` |
| 502 | |
| 503 | The complete rules are slightly more complicated. For instance on |
Frédéric Wang | 71698e6 | 2020-12-10 06:13:52 | [diff] [blame] | 504 | Windows we will also recognize `loopback`. |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 505 | |
| 506 | This concept of implicit proxy bypass rules is consistent with the |
| 507 | platform-level proxy support on Windows and macOS (albeit with some differences |
| 508 | due to their implementation quirks - see compatibility notes in |
| 509 | `net::ProxyBypassRules::MatchesImplicitRules`) |
| 510 | |
| 511 | Why apply implicit proxy bypass rules in the first place? Certainly there are |
| 512 | considerations around ergonomics and user expectation, but the bigger problem |
| 513 | is security. Since the web platform treats `localhost` as a secure origin, the |
| 514 | ability to proxy it grants extra powers. This is [especially |
| 515 | problematic](https://bugs.chromium.org/p/chromium/issues/detail?id=899126) when |
| 516 | proxy settings are externally controllable, as when using PAC scripts. |
| 517 | |
| 518 | Historical support in Chrome: |
| 519 | |
Eric Roman | 3aa29ee | 2020-04-14 18:53:47 | [diff] [blame] | 520 | * Prior to M71 there were no implicit proxy bypass rules, except if using |
| 521 | [`--winhttp-proxy-resolver`](#winhttp_proxy_resolver-command-line-switch). |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 522 | * In M71 Chrome applied implicit proxy bypass rules to PAC scripts |
Eric Roman | 65019bb | 2019-05-03 20:56:15 | [diff] [blame] | 523 | * In M72 Chrome generalized the implicit proxy bypass rules to manually |
| 524 | configured proxies |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 525 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 526 | ### Overriding the implicit bypass rules |
Eric Roman | 591bb0d | 2019-05-02 20:57:17 | [diff] [blame] | 527 | |
| 528 | If you want traffic to `localhost` to be sent through a proxy despite the |
| 529 | security concerns, it can be done by adding the special proxy bypass rule |
| 530 | `<-loopback>`. This has the effect of _subtracting_ the implicit rules. |
| 531 | |
| 532 | For instance, launch Chrome with the command line flag: |
| 533 | |
| 534 | ``` |
| 535 | --proxy-bypass-list="<-loopback>" |
| 536 | ``` |
| 537 | |
| 538 | Note that there currently is no mechanism to disable the implicit proxy bypass |
| 539 | rules when using a PAC script. Proxy bypass lists only apply to manual |
| 540 | settings, so the technique above cannot be used to let PAC scripts decide the |
| 541 | proxy for localhost URLs. |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 542 | |
| 543 | ## Evaluating proxy lists (proxy fallback) |
| 544 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 545 | Proxy resolution results in a _list_ of [proxy server |
| 546 | identifiers](#Proxy-server-identifiers) to use for a |
| 547 | given request, not just a single proxy server identifier. |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 548 | |
| 549 | For instance, consider this PAC script: |
| 550 | |
| 551 | ``` |
| 552 | function FindProxyForURL(url, host) { |
| 553 | if (host == "www.example.com") { |
| 554 | return "PROXY proxy1; HTTPS proxy2; SOCKS5 proxy3"; |
| 555 | } |
| 556 | return "DIRECT"; |
| 557 | } |
| 558 | |
| 559 | ``` |
| 560 | |
| 561 | What proxy will Chrome use for connections to `www.example.com`, given that |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 562 | we have a choice of three separate proxy server identifiers to choose from |
| 563 | {`http://proxy1:80`, `https://proxy2:443`, `socks5://proxy3:1080`}? |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 564 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 565 | Initially, Chrome will try the proxies in order. This means first attempting |
| 566 | the request through `http://proxy1:80`. If that "fails", the request is |
| 567 | next attempted through `https://proxy2:443`. Lastly if that fails, the |
| 568 | request is attempted through `socks5://proxy3:1080`. |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 569 | |
| 570 | This process is referred to as _proxy fallback_. What constitutes a |
| 571 | "failure" is described later. |
| 572 | |
| 573 | Proxy fallback is stateful. The actual order of proxy attempts made be Chrome |
| 574 | is influenced by the past responsiveness of proxy servers. |
| 575 | |
Eric Roman | 65019bb | 2019-05-03 20:56:15 | [diff] [blame] | 576 | Let's say we request `http://www.example.com/`. Per the PAC script this |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 577 | resolves to a list of three proxy server identifiers: |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 578 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 579 | {`http://proxy1:80`, `https://proxy2:443`, `socks5://proxy3:1080`} |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 580 | |
| 581 | Chrome will first attempt to issue the request through these proxies in the |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 582 | left-to-right order. |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 583 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 584 | Let's say that the attempt through `http://proxy1:80` fails, but then the |
| 585 | attempt through `https://proxy2:443` succeeds. Chrome will mark |
| 586 | `http://proxy1:80` as _bad_ for the next 5 minutes. Being marked as _bad_ |
| 587 | means that `http://proxy1:80` is de-prioritized with respect to |
| 588 | other proxy server identifiers (including `direct://`) that are not marked as |
| 589 | bad. |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 590 | |
| 591 | That means the next time `http://www.example.com/` is requested, the effective |
| 592 | order for proxies to attempt will be: |
| 593 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 594 | {`https://proxy2:443`, `socks5://proxy3:1080`, `http://proxy1:80`} |
Eric Roman | 1c75136 | 2019-05-03 16:56:39 | [diff] [blame] | 595 | |
| 596 | Conceptually, _bad_ proxies are moved to the end of the list, rather than being |
| 597 | removed from consideration all together. |
| 598 | |
| 599 | What constitutes a "failure" when it comes to triggering proxy fallback depends |
| 600 | on the proxy type. Generally speaking, only connection level failures |
| 601 | are deemed eligible for proxy fallback. This includes: |
| 602 | |
| 603 | * Failure resolving the proxy server's DNS |
| 604 | * Failure connecting a TCP socket to the proxy server |
| 605 | |
| 606 | (There are some caveats for how HTTPS and QUIC proxies count failures for |
| 607 | fallback) |
| 608 | |
| 609 | Prior to M67, Chrome would consider failures establishing a |
| 610 | CONNECT tunnel as an error eligible for proxy fallback. This policy [resulted |
| 611 | in problems](https://bugs.chromium.org/p/chromium/issues/detail?id=680837) for |
| 612 | deployments whose HTTP proxies intentionally failed certain https:// requests, |
| 613 | since that necessitates inducing a failure during the CONNECT tunnel |
| 614 | establishment. The problem would occur when a working proxy fallback option |
| 615 | like DIRECT was given, since the failing proxy would then be marked as bad. |
| 616 | |
| 617 | Currently there are no options to configure proxy fallback (including disabling |
| 618 | the caching of bad proxies). Future versions of Chrome may [remove caching |
| 619 | of bad proxies](https://bugs.chromium.org/p/chromium/issues/detail?id=936130) |
| 620 | to make fallback predictable. |
| 621 | |
| 622 | To investigate issues relating to proxy fallback, one can [collect a NetLog |
| 623 | dump using |
| 624 | chrome://net-export/](https://dev.chromium.org/for-testers/providing-network-details). |
| 625 | These logs can then be loaded with the [NetLog |
| 626 | viewer](https://netlog-viewer.appspot.com/). |
| 627 | |
| 628 | There are a few things of interest in the logs: |
| 629 | |
| 630 | * The "Proxy" tab will show which proxies (if any) were marked as bad at the |
| 631 | time the capture ended. |
| 632 | * The "Events" tab notes what the resolved proxy list was, and what the |
| 633 | re-ordered proxy list was after taking into account bad proxies. |
| 634 | * The "Events" tab notes when a proxy is marked as bad and why (provided the |
| 635 | event occurred while capturing was enabled). |
| 636 | |
| 637 | When debugging issues with bad proxies, it is also useful to reset Chrome's |
| 638 | cache of bad proxies. This can be done by clicking the "Clear bad proxies" |
| 639 | button on |
| 640 | [chrome://net-internals/#proxy](chrome://net-internals/#proxy). Note the UI |
| 641 | will not give feedback that the bad proxies were cleared, however capturing a |
| 642 | new NetLog dump can confirm it was cleared. |
Eric Roman | 65019bb | 2019-05-03 20:56:15 | [diff] [blame] | 643 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 644 | ## Arguments passed to FindProxyForURL() in PAC scripts |
Eric Roman | 65019bb | 2019-05-03 20:56:15 | [diff] [blame] | 645 | |
| 646 | PAC scripts in Chrome are expected to define a JavaScript function |
| 647 | `FindProxyForURL`. |
| 648 | |
| 649 | The historical signature for this function is: |
| 650 | |
| 651 | ``` |
| 652 | function FindProxyForURL(url, host) { |
| 653 | ... |
| 654 | } |
| 655 | ``` |
| 656 | |
| 657 | Scripts can expect to be called with string arguments `url` and `host` such |
| 658 | that: |
| 659 | |
| 660 | * `url` is a *sanitized* version of the request's URL |
| 661 | * `host` is the unbracketed host portion of the origin. |
| 662 | |
| 663 | Sanitization of the URL means that the path, query, fragment, and identity |
| 664 | portions of the URL are stripped. Effectively `url` will be |
| 665 | limited to a `scheme://host:port/` style URL |
| 666 | |
| 667 | Examples of how `FindProxyForURL()` will be called: |
| 668 | |
| 669 | ``` |
| 670 | // Actual URL: https://www.google.com/Foo |
| 671 | FindProxyForURL('https://www.google.com/', 'www.google.com') |
| 672 | |
| 673 | // Actual URL: https://[dead::beef]/foo?bar |
| 674 | FindProxyForURL('https://[dead::beef]/', 'dead::beef') |
| 675 | |
| 676 | // Actual URL: https://www.example.com:8080#search |
| 677 | FindProxyForURL('https://www.example.com:8080/', 'example.com') |
| 678 | |
| 679 | // Actual URL: https://username:[email protected] |
| 680 | FindProxyForURL('https://www.example.com/', 'example.com') |
| 681 | ``` |
| 682 | |
| 683 | Stripping the path and query from the `url` is a departure from the original |
| 684 | Netscape implementation of PAC. It was introduced in Chrome 52 for [security |
| 685 | reasons](https://bugs.chromium.org/p/chromium/issues/detail?id=593759). |
| 686 | |
| 687 | There is currently no option to turn off sanitization of URLs passed to PAC |
| 688 | scripts (removed in Chrome 75). |
| 689 | |
| 690 | The sanitization of http:// URLs currently has a different policy, and does not |
| 691 | strip query and path portions of the URL. That said, users are advised not to |
| 692 | depend on reading the query/path portion of any URL |
| 693 | type, since future versions of Chrome may [deprecate that |
| 694 | capability](https://bugs.chromium.org/p/chromium/issues/detail?id=882536) in |
| 695 | favor of a consistent policy. |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 696 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 697 | ## Resolving client's IP address within a PAC script using myIpAddress() |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 698 | |
| 699 | PAC scripts can invoke `myIpAddress()` to obtain the client's IP address. This |
| 700 | function returns a single IP literal, or `"127.0.0.1"` on failure. |
| 701 | |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 702 | This API is [inherently ambiguous when used on multi-homed |
| 703 | hosts](#myIpAddress_myIpAddressEx_and-multi_homed-hosts), as such hosts can |
| 704 | have multiple IP addresses and yet the browser can pick just one to return. |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 705 | |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 706 | Chrome's algorithm for `myIpAddress()` favors returning the IP that would be |
| 707 | used if we were to connect to the public internet, by executing the following |
| 708 | ordered steps and short-circuiting once the first candidate IP is found: |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 709 | |
| 710 | 1. Select the IP of an interface that can route to public Internet: |
| 711 | * Probe for route to `8.8.8.8`. |
| 712 | * Probe for route to `2001:4860:4860::8888`. |
| 713 | 2. Select an IP by doing a DNS resolve of the machine's hostname: |
| 714 | * Select the first IPv4 result if there is one. |
| 715 | * Select the first IP result if there is one. |
| 716 | 3. Select the IP of an interface that can route to private IP space: |
| 717 | * Probe for route to `10.0.0.0`. |
| 718 | * Probe for route to `172.16.0.0`. |
| 719 | * Probe for route to `192.168.0.0`. |
| 720 | * Probe for route to `FC00::`. |
| 721 | |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 722 | Note that when searching for candidate IP addresses, link-local and loopback |
| 723 | addresses are skipped over. Link-local or loopback address will only be returned as a |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 724 | last resort when no other IP address was found by following these steps. |
| 725 | |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 726 | This sequence of steps explicitly favors IPv4 over IPv6 results, to match |
| 727 | Internet Explorer's IPv6 support. |
Eric Roman | a36bff3b | 2019-05-17 18:11:58 | [diff] [blame] | 728 | |
| 729 | *Historical note*: Prior to M72, Chrome's implementation of `myIpAddress()` was |
| 730 | effectively just `getaddrinfo(gethostname)`. This is now step 2 of the heuristic. |
| 731 | |
Eric Roman | 1266703 | 2019-06-03 18:38:19 | [diff] [blame] | 732 | ## Resolving client's IP address within a PAC script using myIpAddressEx() |
Eric Roman | 09fd4ce5 | 2019-05-16 21:55:39 | [diff] [blame] | 733 | |
Eric Roman | ac58688 | 2019-05-17 18:59:08 | [diff] [blame] | 734 | Chrome supports the [Microsoft PAC |
| 735 | extension](https://docs.microsoft.com/en-us/windows/desktop/winhttp/myipaddressex) |
| 736 | `myIpAddressEx()`. |
| 737 | |
| 738 | This is like `myIpAddress()`, but instead of returning a single IP address, it |
| 739 | can return multiple IP addresses. It returns a string containing a semi-colon |
| 740 | separated list of addresses. On failure it returns an empty string to indicate |
| 741 | no results (whereas `myIpAddress()` returns `127.0.0.1`). |
| 742 | |
| 743 | There are some differences with Chrome's implementation: |
| 744 | |
| 745 | * In Chrome the function is unconditionally defined, whereas in Internet |
| 746 | Explorer one must have used the `FindProxyForURLEx` entrypoint. |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 747 | * Chrome [does not necessarily enumerate all of the host's network |
| 748 | interfaces](#myIpAddress_myIpAddressEx_and-multi_homed-hosts) |
Eric Roman | ac58688 | 2019-05-17 18:59:08 | [diff] [blame] | 749 | * Chrome does not return link-local or loopback addresses (except if no other |
| 750 | addresses were found). |
| 751 | |
| 752 | The algorithm that Chrome uses is nearly identical to that of `myIpAddress()` |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 753 | described earlier, but in certain cases may return multiple IPs. |
Eric Roman | ac58688 | 2019-05-17 18:59:08 | [diff] [blame] | 754 | |
| 755 | 1. Select all the IPs of interfaces that can route to public Internet: |
| 756 | * Probe for route to `8.8.8.8`. |
| 757 | * Probe for route to `2001:4860:4860::8888`. |
| 758 | * If any IPs were found, return them, and finish. |
| 759 | 2. Select an IP by doing a DNS resolve of the machine's hostname: |
| 760 | * If any IPs were found, return them, and finish. |
| 761 | 3. Select the IP of an interface that can route to private IP space: |
| 762 | * Probe for route to `10.0.0.0`. |
| 763 | * Probe for route to `172.16.0.0`. |
| 764 | * Probe for route to `192.168.0.0`. |
| 765 | * Probe for route to `FC00::`. |
| 766 | * If any IPs were found, return them, and finish. |
| 767 | |
| 768 | Note that short-circuiting happens whenever steps 1-3 find a candidate IP. So |
| 769 | for example if at least one IP address was discovered by checking routes to |
| 770 | public Internet, only those IPs will be returned, and steps 2-3 will not run. |
Eric Roman | c5816ebb | 2019-11-13 18:08:46 | [diff] [blame] | 771 | |
Eric Roman | 649985b | 2020-04-29 20:43:02 | [diff] [blame] | 772 | ## myIpAddress() / myIpAddressEx() and multi-homed hosts |
| 773 | |
| 774 | `myIpAddress()` is a poor API for hosts that have multiple IP addresses, as it |
| 775 | can only return a single IP, which may or may not be the one you wanted. Both |
| 776 | `myIpAddress()` and `myIpAddressEx()` favor returning the IP for the interface |
| 777 | that would be used to route to the public internet. |
| 778 | |
| 779 | As an API, `myIpAddressEx()` offers more flexibility since it can return |
| 780 | multiple IP addresses. However Chrome's implementation restricts which IPs a |
| 781 | PAC script can see [due to privacy |
| 782 | concerns](https://bugs.chromium.org/p/chromium/issues/detail?id=905366). So |
| 783 | using `myIpAddressEx()` is not as powerful as enumerating all the host's IPs, |
| 784 | and may not address all use-cases. |
| 785 | |
| 786 | A more reliable strategy for PAC scripts to check which network(s) a user is on |
| 787 | is to probe test domains using `dnsResolve()` / `dnsResolveEx()`. |
| 788 | |
| 789 | Moreover, note that Chrome does not support the Firefox-specific |
| 790 | `pacUseMultihomedDNS` option, so adding that global to a PAC script has no |
| 791 | special side-effect in Chrome. Whereas in Firefox it reconfigures |
| 792 | `myIpAddress()` to be dependent on the target URL that `FindProxyForURL()` was |
| 793 | called with. |
| 794 | |
Eric Roman | c5816ebb | 2019-11-13 18:08:46 | [diff] [blame] | 795 | ## Android quirks |
| 796 | |
| 797 | Proxy resolving via PAC works differently on Android than other desktop Chrome |
| 798 | platforms: |
| 799 | |
| 800 | * Android Chrome uses the same Chromium PAC resolver, however does not run it |
| 801 | out-of-process as on Desktop Chrome. This architectural difference is |
| 802 | due to the higher process cost on Android, and means Android Chrome is more |
| 803 | susceptible to malicious PAC scripts. The other consequence is that Android |
| 804 | Chrome can have distinct regressions from Desktop Chrome as the service setup |
| 805 | is quite different (and most `browser_tests` are not run on Android either). |
| 806 | |
| 807 | * [WebView does not use Chrome's PAC |
| 808 | resolver](https://bugs.chromium.org/p/chromium/issues/detail?id=989667). |
| 809 | Instead Android WebView uses the Android system's PAC resolver, which is less |
| 810 | optimized and uses an old build of V8. When the system is configured to use |
| 811 | PAC, Android WebView's net code will see the proxy settings as being a |
| 812 | single HTTP proxy on `localhost`. The system localhost proxy will in turn |
| 813 | evaluate the PAC script and forward the HTTP request on to the resolved |
| 814 | proxy. This translation has a number of effects, including what proxy |
| 815 | schemes are supported, the maximum connection limits, how proxy fallback |
| 816 | works, and overall performance (the current Android PAC evaluator blocks on |
| 817 | DNS). |
| 818 | |
| 819 | * Android system log messages for `PacProcessor` are not related to Chrome or |
| 820 | its PAC evaluator. Rather, these are log messages generated by the Android |
| 821 | system's PAC implementation. This confusion can arise when users add |
| 822 | `alert()` to debug PAC script logic, and then refer to output in `logcat` to |
| 823 | try and diagnose a resolving issue in Android Chrome. |
Eric Roman | 0fdcd4f1 | 2020-03-03 22:22:03 | [diff] [blame] | 824 | |
| 825 | ## Downloading PAC scripts |
| 826 | |
| 827 | When a network context is configured to use a PAC script, proxy resolution will |
| 828 | stall while downloading the PAC script. |
| 829 | |
| 830 | Fetches for PAC URLs are initiated by the network stack, and behave differently |
| 831 | from ordinary web visible requests: |
| 832 | |
| 833 | * Must complete within 30 seconds. |
| 834 | * Must complete with an HTTP response code of exactly 200. |
| 835 | * Must have an uncompressed body smaller than 1 MB. |
| 836 | * Do not follow ordinary HTTP caching semantics. |
| 837 | * Are never fetched through a proxy |
| 838 | * Are not visible to the WebRequest extension API, or to service workers. |
| 839 | * Do not support HTTP authentication (ambient authentication may work, but |
| 840 | cannot prompt UI for credentials). |
| 841 | * Do not support client certificates (including `AutoSelectCertificateForUrls`) |
| 842 | * Do not support auxiliary certificate network fetches (will only used cached |
| 843 | OCSP, AIA, and CRL responses during certificate verification). |
| 844 | |
| 845 | ### Caching of successful PAC fetches |
| 846 | |
| 847 | PAC URLs are always fetched from the network, and never from the HTTP cache. |
| 848 | After a PAC URL is successfully fetched, its contents (which are used to create |
| 849 | a long-lived Java Script context) will be assumed to be fresh until either: |
| 850 | |
| 851 | * The network changes (IP address changes, DNS configuration changes) |
| 852 | * The response becomes older than 12 hours |
| 853 | * A user explicitly invalidates PAC through `chrome://net-internals#proxy` |
| 854 | |
| 855 | Once considered stale, the PAC URL will be re-fetched the next time proxy |
| 856 | resolution is requested. |
| 857 | |
| 858 | ### Fallback for failed PAC fetches |
| 859 | |
| 860 | When the proxy settings are configured to use a PAC URL, and that PAC URL |
| 861 | cannot be fetched, proxy resolution will fallback to the next option, which is |
| 862 | often `DIRECT`: |
| 863 | |
| 864 | * If using system proxy settings, and the platform supports fallback to manual |
| 865 | proxy settings (e.g. Windows), the specified manual proxy servers will be |
| 866 | used after the PAC fetch fails. |
| 867 | * If using Chrome's proxy settings, and the PAC script was marked as |
| 868 | [mandatory](https://developer.chrome.com/extensions/proxy), fallback to |
| 869 | `DIRECT` is not permitted. Subsequent network requests will fail proxy |
| 870 | resolution and complete with `ERR_MANDATORY_PROXY_CONFIGURATION_FAILED`. |
| 871 | * Otherwise proxy resolution will silently fall back to `DIRECT`. |
| 872 | |
| 873 | ### Recovering from failed PAC fetches |
| 874 | |
| 875 | When fetching an explicitly configured PAC URL fails, the browser will try to |
| 876 | re-fetch it: |
| 877 | |
| 878 | * In exactly 8 seconds |
| 879 | * 32 seconds after that |
| 880 | * 2 minutes after that |
| 881 | * Every 4 hours thereafter |
| 882 | |
| 883 | This background polling of the PAC URL is only initiated in response to an |
| 884 | incoming proxy resolution request, so it will not trigger work when the browser |
| 885 | is otherwise idle. |
| 886 | |
| 887 | Similarly to successful fetches, the PAC URL will be also be re-fetched |
| 888 | whenever the network changes, the proxy settings change, or it was manually |
| 889 | invalidated via `chrome://net-internals#proxy`. |
| 890 | |
| 891 | ### Text encoding |
| 892 | |
| 893 | Note that UTF-8 is *not* the default interpretation of PAC response bodies. |
| 894 | |
| 895 | The priority for encoding is determined in this order: |
| 896 | |
| 897 | 1. The `charset` property of the HTTP response's `Content-Type` |
| 898 | 2. Any BOM at the start of response body |
| 899 | 3. Otherwise defaults to ISO-8859-1. |
| 900 | |
| 901 | When setting the `Content-Type`, servers should prefer using a mime type of |
| 902 | `application/x-ns-proxy-autoconfig` or `application/x-javascript-config`. |
| 903 | However in practice, Chrome does not enforce the mime type. |
Eric Roman | 29a49f8 | 2020-04-09 17:34:23 | [diff] [blame] | 904 | |
| 905 | ## Capturing a Net Log for debugging proxy resolution issues |
| 906 | |
| 907 | Issues in proxy resolution are best investigated using a Net Log. |
| 908 | |
| 909 | A good starting point is to follow the [general instructions for |
| 910 | net-export](https://www.chromium.org/for-testers/providing-network-details), |
| 911 | *and while the Net Log is being captured perform these steps*: |
| 912 | |
| 913 | 1. Reproduce the failure (ex: load a URL that fails) |
| 914 | 2. If you can reproduce a success, do so (ex: load a different URL that succeeds). |
| 915 | 3. In a new tab, navigate to `chrome://net-internals/#proxy` and click both |
| 916 | buttons ("Re-apply settings" and "Clear bad proxies"). |
| 917 | 4. Repeat step (1) |
| 918 | 5. Stop the Net Log and save the file. |
| 919 | |
| 920 | The resulting Net Log should have enough information to diagnose common |
| 921 | problems. It can be attached to a bug report, or explored using the [Net Log |
| 922 | Viewer](https://netlog-viewer.appspot.com/). See the next section for some tips |
| 923 | on analyzing it. |
| 924 | |
| 925 | ## Analyzing Net Logs for proxy issues |
| 926 | |
| 927 | Load saved Net Logs using [Net Log Viewer](https://netlog-viewer.appspot.com/). |
| 928 | |
| 929 | ### Proxy overview tab |
| 930 | |
| 931 | Start by getting a big-picture view of the proxy settings by clicking to the |
| 932 | "Proxy" tab on the left. This summarizes the proxy settings at the time the |
| 933 | _capture ended_. |
| 934 | |
| 935 | * Does the _original_ proxy settings match expectation? |
| 936 | The proxy settings might be coming from: |
| 937 | * Managed Chrome policy (chrome://policy) |
| 938 | * Command line flags (ex: `--proxy-server`) |
| 939 | * (per-profile) Chrome extensions (ex: [chrome.proxy](https://developer.chrome.com/extensions/proxy)) |
| 940 | * (per-network) System proxy settings |
| 941 | |
Eric Roman | 21ea63d3 | 2020-04-13 18:01:00 | [diff] [blame] | 942 | * Was [proxy autodetect (WPAD)](#Web-Proxy-Auto_Discovery-WPAD) specified? In |
| 943 | this case the final URL probed will be reflected by the difference between |
| 944 | the "Effective" and "Original" settings. |
Eric Roman | 29a49f8 | 2020-04-09 17:34:23 | [diff] [blame] | 945 | |
| 946 | * Internally, proxy settings are per-NetworkContext. The proxy |
| 947 | overview tab shows settings for a *particular* NetworkContext, namely the |
| 948 | one associated with the Profile used to navigate to `chrome://net-export`. For |
| 949 | instance if the net-export was initiated from an Incognito window, it may |
| 950 | show different proxy settings here than a net-export capture initiated by a |
| 951 | non-Incognito window. When the net-export was triggered from command line |
| 952 | (`--log-net-log`) no particular NetworkContext is associated with the |
| 953 | capture and hence no proxy settings will be shown in this overview. |
| 954 | |
| 955 | * Were any proxies marked as bad? |
| 956 | |
| 957 | ### Import tab |
| 958 | |
| 959 | Skim through the Import tab and look for relevant command line flags and active |
| 960 | field trials. A find-in-page for `proxy` is a good starting point. Be on the lookout for |
Eric Roman | 3aa29ee | 2020-04-14 18:53:47 | [diff] [blame] | 961 | [`--winhttp-proxy-resolver`](#winhttp_proxy_resolver-command-line-switch) which |
| 962 | has [known problems](https://bugs.chromium.org/p/chromium/issues/detail?id=644030). |
Eric Roman | 29a49f8 | 2020-04-09 17:34:23 | [diff] [blame] | 963 | |
| 964 | ### Events tab |
| 965 | |
| 966 | To deep dive into proxy resolution, switch to the Events tab. |
| 967 | |
| 968 | You can start by filtering on `type:URL_REQUEST` to see all the top level |
| 969 | requests, and then keep click through the dependency links to |
| 970 | trace the proxy resolution steps and outcome. |
| 971 | |
| 972 | The most relevant events have either `PROXY_`, `PAC_`, or |
| 973 | `WPAD_` in their names. You can also try filtering for each of those. |
| 974 | |
| 975 | Documentation on specific events is available in |
| 976 | [net_log_event_type_list.h](https://chromium.googlesource.com/chromium/src/+/HEAD/net/log/net_log_event_type_list.h). |
| 977 | |
| 978 | Network change events can also be key to understanding proxy issues. After |
| 979 | switching networks (ex VPN), the effective proxy settings, as well as content |
| 980 | of any PAC scripts/auto-detect can change. |
Eric Roman | a953f0a4 | 2020-04-10 19:42:28 | [diff] [blame] | 981 | |
| 982 | ## Web Proxy Auto-Discovery (WPAD) |
| 983 | |
| 984 | When configured to use WPAD (aka "autotmaticaly detect proxy settings"), Chrome |
| 985 | will prioritize: |
| 986 | |
| 987 | 1. DHCP-based WPAD (option 252) |
| 988 | 2. DNS-based WPAD |
| 989 | |
| 990 | These are tried in order, however DHCP-based WPAD is only supported for Chrome |
| 991 | on Windows and Chrome on Chrome OS. |
| 992 | |
| 993 | WPAD is the system default for many home and Enterprise users. |
| 994 | |
| 995 | ### Chrome on macOS support for DHCP-based WPAD |
| 996 | |
| 997 | Chrome on macOS does not support DHCP-based WPAD when configured to use |
| 998 | "autodetect". |
| 999 | |
| 1000 | However, macOS might perform DHCP-based WPAD and embed this discovered PAC URL |
| 1001 | as part of the system proxy settings. So effectively when Chrome is configured |
| 1002 | to "use system proxy settings" it may behave as if it supports DHCP-based WPAD. |
| 1003 | |
| 1004 | ### Dangers of DNS-based WPAD and DNS search suffix list |
| 1005 | |
| 1006 | DNS-based WPAD involves probing for the non-FQDN `wpad`. This means |
| 1007 | WPAD's performance and security is directly tied to the user's DNS search |
| 1008 | suffix list. |
| 1009 | |
| 1010 | When resolving `wpad`, the host's DNS resolver will complete the hostname using |
| 1011 | each of the suffixes in the search list: |
| 1012 | |
| 1013 | 1. If the suffix list is long this process can very slow, as it triggers a |
| 1014 | cascade of NXDOMAIN. |
| 1015 | 2. If the suffix list includes domains *outside of the administrative domain*, |
| 1016 | WPAD may select an attacker controlled PAC server, and can subsequently |
| 1017 | funnel the user's traffic through a proxy server of their choice. The |
| 1018 | evolution of TLDs further increases this risk, since what were previously |
| 1019 | private suffixes used by an enterprise can become publicly registerable. |
| 1020 | See also [WPAD Name Collision |
| 1021 | Vulnerability](https://www.us-cert.gov/ncas/alerts/TA16-144A) |
Eric Roman | 3aa29ee | 2020-04-14 18:53:47 | [diff] [blame] | 1022 | |
| 1023 | ## --winhttp-proxy-resolver command line switch |
| 1024 | |
| 1025 | Passing the `--winhttp-proxy-resolver` command line argument instructs Chrome |
| 1026 | to use the system libraries for *one narrow part of proxy resolution*: evaluating |
| 1027 | a given PAC script. |
| 1028 | |
| 1029 | Use of this flag is NOT a supported mode, and has [known |
| 1030 | problems](https://bugs.chromium.org/p/chromium/issues/detail?id=644030): It |
| 1031 | can break Chrome extensions (`chrome.proxy` API), the interpretation of |
| 1032 | Proxy policies, hurt performance, and doesn't ensure full fidelity |
| 1033 | interpretation of system proxy settings. |
| 1034 | |
| 1035 | Another oddity of this switch is that it actually gets interpreted with a |
| 1036 | smilar meaning on other platforms (macOS), despite its Windows-specific naming. |
| 1037 | |
| 1038 | This flag was historically exposed for debugging, and to mitigate unresolved |
| 1039 | policy differences in PAC execution. In the future this switch [will be |
| 1040 | removed](https://bugs.chromium.org/p/chromium/issues/detail?id=644030). |
| 1041 | |
| 1042 | Although Chrome would like full fidelity with Windows proxy settings, there are |
| 1043 | limits to those integrations. Dependencies like NRPT for proxy |
| 1044 | resolution necessitate using Windows proxy resolution libraries directly |
| 1045 | instead of Chrome's. We hope these less common use cases will be fully |
| 1046 | addressed by [this |
| 1047 | feature](https://bugs.chromium.org/p/chromium/issues/detail?id=1032820) |