A proxy auto-config (PAC) file defines how
web browser
A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used on ...
s and other
user agent
In computing, a user agent is any software, acting on behalf of a user, which "retrieves, renders and facilitates end-user interaction with Web content". A user agent is therefore a special kind of software agent.
Some prominent examples of u ...
s can automatically choose the appropriate
proxy server
In computer networking, a proxy server is a server application that acts as an intermediary between a client requesting a resource and the server providing that resource.
Instead of connecting directly to a server that can fulfill a requ ...
(access method) for fetching a given
URL
A Uniform Resource Locator (URL), colloquially termed as a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifi ...
.
A PAC file contains a
JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
function
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-orie ...
FindProxyForURL(url, host)
. This function returns a string with one or more access method specifications. These specifications cause the user agent to use a particular proxy server or to connect directly.
Multiple specifications provide a fall-back when a proxy fails to respond. The browser fetches this PAC file before requesting other URLs. The URL of the PAC file is either configured manually or determined automatically by the
Web Proxy Auto-Discovery Protocol.
Context
Modern web browsers implement several levels of automation; users can choose the level that is appropriate to their needs. The following methods are commonly implemented:
* Automatic proxy selection: Specify a host-name and a port number to be used for all URLs. Most browsers allow you to specify a list of domains (such as
localhost
) that will bypass this proxy.
* Proxy auto-configuration (PAC): Specify the URL for a PAC file with a JavaScript function that determines the appropriate proxy for each URL. This method is more suitable for laptop users who need several different proxy configurations, or complex corporate setups with many different proxies.
*
Web Proxy Auto-Discovery Protocol (WPAD): Let the browser guess the location of the PAC file through
DHCP
The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on Internet Protocol (IP) networks for automatically assigning IP addresses and other communication parameters to devices connected to the network using a cli ...
and
DNS
The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned to ...
lookups.
History
The Proxy auto-config file format was originally designed by
Netscape
Netscape Communications Corporation (originally Mosaic Communications Corporation) was an American independent computer services company with headquarters in Mountain View, California and then Dulles, Virginia. Its Netscape web browser was on ...
in 1996 for the
Netscape Navigator 2.0 and is a
text file
A text file (sometimes spelled textfile; an old alternative name is flatfile) is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists stored as data within a computer file system. In operat ...
that defines at least one JavaScript function.
The PAC File
By convention, the PAC file is normally named
proxy.pac
. The
WPAD standard uses
wpad.dat
. The file is expected to contain at least one function:
: , with two arguments and return value in specific format:
: * is the URL of the object
: * is the host-name derived from that URL. Syntactically it is the same string as between
://
and the first
:
or
/
after that.
: * is a string of signatures in the following format (see examples below):
[ EBNF by ]W3C
The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working t ...
notation
::
returnValue = type host,":",port,[];
type = "DIRECT" , "PROXY" , "SOCKS" , "HTTP" , "HTTPS" , "SOCKS4" , "SOCKS5"
host = UTF16String (* ECMA262-compatible UTF16 string *)
port = UTF16String (* Digits *)
To use it, a PAC file is published to a
HTTP server
An HTTP server is a computer (software) program (or even a software component included in an other program) that plays the role of a server in a client–server model by implementing the ''server part'' of the HTTP and/or HTTPS network proto ...
, and client user agents are instructed to use it, either by entering the URL in the proxy connection settings of the browser or through the use of the WPAD protocol. The URL may also reference a local file as for example:
file:///etc/proxy.pac
.
Even though most clients will process the script regardless of the
MIME type
A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication o ...
returned in the
HTTP reply, for the sake of completeness and to maximize compatibility, the HTTP server should be configured to declare the MIME type of this file to be either
application/x-ns-proxy-autoconfig
or
application/x-javascript-config
.
There is little evidence to favor the use of one MIME type over the other. It would be, however, reasonable to assume that
application/x-ns-proxy-autoconfig
will be supported in more clients than
application/x-javascript-config
as it was defined in the original Netscape specification, the latter type coming into use more recently.
Example
A very simple example of a PAC file is:
function FindProxyForURL (url, host)
This function instructs the browser to retrieve all pages through the proxy on
port
A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as ...
8080 of the server
proxy.example.com
. Should this proxy fail to respond, the browser contacts the Web-site directly, without using a proxy. The latter may fail if
firewalls, or other intermediary network devices, reject requests from sources other than the proxy—a common configuration in corporate networks.
A more complicated example demonstrates some available JavaScript functions to be used in the
FindProxyForURL
function:
function FindProxyForURL (url, host)
By default, the PROXY keyword means that a proxy corresponding to the protocol of the original request, be it http, https, or ftp, is used. Other supported keyword and proxy types include:
; SOCKS: Use a
SOCKS
A sock is a piece of clothing worn on the feet and often covering the ankle or some part of the calf. Some types of shoes or boots are typically worn over socks. In ancient times, socks were made from leather or matted animal hair. In the lat ...
proxy.
; HTTP, HTTPS: Introduced in more recent versions of Firefox. Specifies an HTTP(S) proxy.
; SOCKS4, SOCKS5: Introduced in more recent versions of Firefox. Specifies the SOCKS protocol version.
Limitations
PAC Character-Encoding
The encoding of PAC scripts is generally unspecified, and different browsers and network stacks have different rules for how PAC scripts may be encoded. In general, wholly
ASCII
ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because ...
PAC scripts will work with any browser or network stack.
Mozilla Firefox
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current a ...
66 and later additionally supports PAC scripts encoded as
UTF-8
UTF-8 is a variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit''.
UTF-8 is capable of ...
.
DnsResolve
The function
dnsResolve
(and similar other functions) performs a
DNS
The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned to ...
lookup that can block the browser for a long time if the DNS server does not respond.
myIpAddress
The
myIpAddress
function has often been reported to give incorrect or unusable results, e.g.
127.0.0.1
, the IP address of the localhost.
It may help to remove on the system's host file (e.g.
/etc/hosts
on Linux) any lines referring to the machine host-name, while the line
127.0.0.1 localhost
can, and should, stay.
Security
In 2013, researchers began warning about the security risks of proxy auto-config.
The threat involves using a PAC, discovered automatically by the system, to redirect the victim's browser traffic to an attacker-controlled server instead.
Another issues about pac file is the typical implementation involve clear text http retrieval, which does not include any security features such as code signing or web certificates. Attacker can perform man-in-middle spoofing attack easily.
Old Microsoft problems
Caching of proxy auto-configuration results by domain name in Microsoft's
Internet Explorer
Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft which was used in the Microsoft Wind ...
5.5 or newer limits the flexibility of the PAC standard. In effect, you can choose the proxy based on the domain name, but not on the path of the URL. Alternatively, you need to disable caching of proxy auto-configuration results by editing the
registry Registry may refer to:
Computing
* Container registry, an operating-system-level virtualization registry
* Domain name registry, a database of top-level internet domain names
* Local Internet registry
* Metadata registry, information system for re ...
, a process described by de Boyne Pollard (listed in
further reading
Further or Furthur may refer to:
* ''Furthur'' (bus), the Merry Pranksters' psychedelic bus
* Further (band), a 1990s American indie rock band
* Furthur (band), a band formed in 2009 by Bob Weir and Phil Lesh
* ''Further'' (The Chemical Brothers a ...
).
It is recommended to always use
IP address
An Internet Protocol address (IP address) is a numerical label such as that is connected to a computer network that uses the Internet Protocol for communication.. Updated by . An IP address serves two main functions: network interface ident ...
es instead of host domain names in the
isInNet
function for compatibility with other Windows components which make use of the Internet Explorer PAC configuration, such as
.NET 2.0 Framework. For example,
if (isInNet(host, dnsResolve(sampledomain), '255.255.248.0')) // .NET 2.0 will resolve proxy properly
if (isInNet(host, sampledomain, '255.255.248.0')) // .NET 2.0 will not resolve proxy properly
The current convention is to fail over to direct connection when a PAC file is unavailable.
Shortly after switching between network configurations (e.g. when entering or leaving a VPN),
dnsResolve
may give outdated results due to DNS caching.
For instance, Firefox usually keeps 20 domain entries cached for 60 seconds. This may be configured via the
network.dnsCacheEntries
and
network.dnsCacheExpiration
configuration variables. Flushing the system's
DNS cache may also help, which can be achieved e.g. in Linux with
sudo service dns-clean start or in Windows with
ipconfig /flushdns.
On Internet Explorer 9,
isInNet('localHostName', 'second.ip', '255.255.255.255')
returns
true
and can be used as a workaround.
The
myIpAddress
function assumes that the device has a single IPv4 address. The results are undefined if the device has more than one IPv4 address or has IPv6 addresses.
Others
Further limitations are related to the
JavaScript engine
A JavaScript engine is a software component that executes JavaScript code. The first JavaScript engines were mere interpreters, but all relevant modern engines use just-in-time compilation for improved performance.
JavaScript engines are typica ...
on the local machine.
Advanced functionality
More advanced PAC files can reduce load on proxies, perform load balancing, fail over, or even
black
Black is a color which results from the absence or complete absorption of visible light. It is an achromatic color, without hue, like white and grey. It is often used symbolically or figuratively to represent darkness. Black and white ha ...
/
white listing before the request is sent through the network.
One can return multiple proxies:
return 'PROXY proxy1.example.com:80; PROXY proxy2.example.com:8080';
The above will try proxy1 first and if unavailable it will then try proxy2.
Notes
References
Further reading
External links
*
*
*
*
{{Internet censorship circumvention technologies
Web browsers
*
JavaScript
Computer files