proxy.pac dnsDomainIs() and Java/JRE

While troubleshooting a non-working Java applet I realized something interesting: not all browsers/plugin frameworks will handle automatic proxy configuration similarly.

IIRC proxy auto-configuration (PAC) was thought up and implemented by Netscape. It provides a flexible way of letting the browser decide dynamically whether to use a proxy or which proxy to use based upon the URL that is visited. This is done by giving the browser a URL instead of just a proxy server name. The URL, for example http://my.local.server/proxy.pac, points to a text file that contains Javascript. This Javascript file implements the FindProxyForURL(url, host) function that is called by the browser to determine which proxy to use. It can return DIRECT or “PROXY proxy.example.com:3128” . Several Javascript functions are available to help writing an efficient FindProxyForURL(). Some of them are isPlainHostName(), shExpMatch() and dnsDomainIs(). The original documentation of these function are only still available on the Web Archive and are far from complete or unambiguous.

It is no real surprise that each browser (or more specific, each Javascript engine) implements these functions a little different. For example, the documentation for dnsDomainIs() function is:

dnsDomainIs(host, domain)

host
is the hostname from the URL.
domain
is the domain name to test the hostname against.

Returns true iff the domain of hostname matches.

Examples:

dnsDomainIs("www.netscape.com", ".netscape.com")
is true.
dnsDomainIs("www", ".netscape.com")
is false.
dnsDomainIs("www.mcom.com", ".netscape.com")
is false.

As you can see the domain argument in the examples all start with a dot. So what happens if you enter a FQDN as the domain? The behavior is not specified above, so it is up to each implementation. Trial and error showed me that dnsDomainIs(“www.netscape.com”, “www.netscape.com”) returns TRUE in Firefox 3.6, IE6 and IE8. However, it returns FALSE in JRE 1.6.0_20b02. This behavior is described in Java Bug ID 6346688 and can easily be fixed by using

dnsDomainIs(host, "www.netscape.com") || host == "www.netscape.com"

in your proxy.pac. This seems to work in all implementations.

Leave a Comment