You are on page 1of 12

Transparent Proxies: Threat or Menace?

Lin-Shung Huang, Eric Y. Chen, Adam Barth, Eric Rescorla, and Collin Jackson

Abstract—Browsers limit how web sites can access the network. browsers, the protocols themselves have seen only modest
Historically, the web platform has limited web sites to HTTP, amounts of security analysis. Recently, these protocols were
but HTTP is inefficient for a number of applications—including shown to be vulnerable to DNS rebinding attacks [1], whereby
chat and multiplayer games—for which raw socket access is more
appropriate. Java, Flash Player, and HTML5 provide socket APIs the consent was scoped to a host name rather than an IP
to web sites, but we discover and experimentally verify attacks address, letting the attacker transfer his or her consent to
that exploit the interaction between these APIs and transparent another network endpoint.
proxies. Our attacks poison the proxy’s cache, causing all clients We show that both of these consent protocols are vulnerable
of the proxy to receive malicious content supplied by the attacker.
to attack in some network configurations. In particular, consider
We then propose a revised version of the HTML5 WebSocket
handshake that resists these (and other) attacks. a network scenario in which the user connects to the Internet via
a transparent proxy and a firewall, as is common in enterprise
networks. The transparent proxy intercepts outbound HTTP
I. I NTRODUCTION
requests, perhaps to monitor employee network access or to
Browsers restrict how web applications can interact with enforce a security policy, and the firewall prevents miscreants
the network by enforcing a number of security invariants on on the Internet from accessing the internal network.
their use of the user’s network connection. These restrictions Unfortunately, these transparent proxies often forward the
are essential to the core security guarantee of the web security server’s consent without understanding its semantics. When
model: users can safely visit arbitrary web sites and execute a server provides a Flash policy files authorizing a SWF to
scripts provided by those sites. Generally speaking, browsers connect to the server’s IP address on port 80, Flash Player will
permit web applications to send well-formed HTTP requests actually authorize the SWF to open a socket connection to
to arbitrary network locations (with a handful of important the transparent proxy, not the server itself. Once the attacker
restrictions) but prevent them from reading back the response has opened a socket to the proxy server, the type of misdeeds
unless the server opts in via some mechanism. the attacker can perform depend on details of how the proxy
A number of plug-ins relax these restrictions. For example, behaves. In the worst case, the attacker can poison the proxy’s
both Java and Flash Player provide a mechanism for web appli- HTTP cache for an arbitrary server with the result that all users
cations to open raw socket connections. Of course, unrestricted of the proxy receive the attacker’s malicious content instead
raw socket access to the network would be disastrous for of the honest server’s content.
security. An attacker could use such a facility to wreak havoc The conditions required for such an exploit are relatively
with any network service that relies on IP source addresses or precise (e.g., a specific network configuration and a specific
network connectivity for security (e.g., network devices behind class of proxy behavior). To determine whether these conditions
a firewall). Rather than allowing unrestricted socket access, actually arise in practice, we conducted an experiment on the
both Java and Flash Player limit web applications to opening Internet to see what fraction of Internet users are vulnerable
sockets to servers that have consented to such connections. these attacks by running an advertisement that mounted the
In this paper, we study the protocols by which browser attacks against servers in our laboratory. We found that 32 of
or plug-ins obtain consent from the remote server to open a 21, 303 (0.15%) users in our study were vulnerable to Java-
socket connection. We find that the consent protocols used based cache poisoning attacks and 42 of 36, 305 (0.12%) were
by browsers today are vulnerable to attack in certain network vulnerable to Flash-based cache poisoning.
configurations involving network intermediaries, specifically Raw socket access lets web applications provide functionality
transparent proxies. Our essential insight is that the designers that is difficult to provide with only HTTP networking APIs.
of these protocols need to consider how the attacker can Rather than simply recommending that raw socket access be
manipulate these protocols to exploit network intermediaries removed from the web platform, we study the question of
that might unintentionally proxy the consent of the remote how to design a consent protocol that is robust to oblivious
server without understanding its semantics. intermediaries. As a starting point, we consider the HTML5
Java and Flash Player use different consent protocols. Java protocol for establishing socket connections, WebSockets.
uses a trivial “consent” protocol whereby Java byte code is WebSockets uses an “in-band” consent protocol whereby the
implicitly authorized to open socket connections to the IP browser exchanges messages with the server over a socket
address from which it originated. Flash Player, by contrast, before handing the socket over to the web application.
requires the server to supply a policy file over a specific port We show, empirically, that the current version of the
that explicitly authorizes socket connections to a set of port WebSocket consent handshake is vulnerable to proxy cache
numbers. Although these protocols are widely deployed in poisoning attacks. Even though the WebSocket handshake is
Fig. 1. An example network topology

based on HTTP, which should be understood by most network communicating with the attacker’s server, located somewhere
intermediaries, the handshake uses the esoteric “Upgrade” on the Internet outside the firewall. One or more private servers
mechanism of HTTP. In our experiment, we find that many are located behind the firewall. These servers might be web
proxies do not implement the Upgrade mechanism properly, servers, servers for some other protocol, or both. Because these
which causes the handshake to succeed even through subsequent servers are located behind the firewall, the attacker’s server
traffic over the socket will be misinterpreted by the proxy. cannot communicate with them directly. Many servers located
Building upon our analysis and empirical measurements, behind firewalls are only weakly secured against network
we propose improving the WebSocket handshake in two ways. attacks because the administrator considers other machines
First, we recommend employing the widely used “CONNECT” behind the firewall less dangerous than machines on the Internet
mechanism in HTTP to instruct the proxy to treat the remainder at large—hence the need for a firewall. In particular, such
of the socket as opaque data. Second, we recommend encrypting servers often treat traffic they receive from the internal network
the attacker-controlled portions of the initial handshake message as trusted, e.g., authorized to view confidential information.
with a stream cipher. Even though the decryption key can be In this scenario, we wish the browser to enforce a set of
readily computed from other information in the handshake, security policies that prevent the attacker from interacting
computing the decryption key requires a WebSocket-specific arbitrarily with the servers behind the firewall. We assume
globally unique identifier, which is unlikely to be used by that the user visits malicious web sites, that the browser is
network endpoints that do not understand the WebSocket uncompromised, and that the browser properly enforces its
protocol. Finally, we attempt the same attacks against our security policy. The relevant question, then, is what security
proposed handshake and observe that our proposed handshake policy should the browser enforce on the malicious web site’s
is not vulnerable to these attacks. network access?
Organization. The rest of this paper is organized as follows.
Section II explains our threat model, the same-origin policy, B. Same-Origin Policy
and elaborations thereof. Section III details our attacks on
Flash Player and Java, including our experimental verification. One natural response to the threat of firewall traversal attacks
Section IV presents the design of the WebSocket handshake is to simply forbid programs running in the browser from
and our attack. Section V proposes a new consent protocol communicating with any server other than the one hosting the
that is robust to intermediaries. Section VI places our work in programs. This model, called the same-origin policy, was first
the context of related work. Section VII concludes. introduced for Java applets. Java was originally designed as a
general purpose programming language and so, unsurprisingly,
II. BACKGROUND : N ETWORK ACCESS IN THE B ROWSER offers generic networking primitives, including a API that lets
In this section, we review the network access mechanisms the programmer request the virtual machine to open a raw
browsers provide to web applications in the context of a threat socket to an arbitrary network address and port. If the virtual
environment. These assumptions might be somewhat unfamiliar machine fulfilled these requests unconditionally, these API
to those used to conventional communications security threat would be extremely dangerous. For this reason, Java allows
models because they assume a less powerful class of attackers network connections only to the source of the Java byte code.1
but also a stronger set of invariants we wish to enforce. The policy appears, a priori, safe; how much harm can you
do if you’re talking only to yourself?
A. Threat Model
We assume a network topology similar to the one shown 1 These restrictions do not apply to signed applets which the user has
in Figure 1. The client is behind a firewall or NAT but is accepted. Those applets have the user’s full privileges.
Unfortunately, Java’s notion of “source” has proved to 2) JavaScript Cross-Origin Communication: Until recently,
be quite problematic. One natural definition of “source” is network access for JavaScript applications was limited to
to simply compare hostnames, but there is no guarantee making HTTP requests via XMLHttpRequest(). Browsers
that the same host name will always be bound to servers heavily restrict these requests and forbid requesting cross-
controlled by the same entity. In particular, if Java does its origin URLs [5]. Recently, browser vendors have added two
own name resolution then the system becomes vulnerable to mechanisms to allow web applications to escape (hopefully
DNS rebinding attacks [1], [2]. safely) from these restrictions.
In a DNS rebinding attack, the victim visits a) CORS: Cross-Origin Resource Sharing (CORS) [6]
attacker.com and attacker’s DNS server responds allows web applications to issue HTTP requests to sites outside
with an A record pointing to the attacker’s server but with a their origin. When a web application issues a cross-origin
short time-to-live. The client downloads the applet, which XMLHttpRequest, the browser includes the application’s
then opens a socket to attacker.com. Because the DNS origin in the the request in the Origin header. The server
result has expired, the virtual machine resolves the host name can authorize the application to read back the response by
again, but this time the attacker serves an A record pointing echoing the contents of the Origin request header in the
to the victim’s server, letting the applet (which is under the Access-Control-Allow-Origin response header. This
attacker’s control) open a socket to the victim’s server. DNS consent-based relaxation of the same-origin policy makes it
rebinding attacks have been known for a long time and are easier for different web applications to communicate in the
addressed by basing access control decisions on the IP address browser.
rather than the host name, either directly by checking against b) WebSockets: While CORS is only targeted at HTTP
the IP address (as in Java) or by pinning, forcing a constant requests, WebSockets [7] lets web applications open a socket
mapping between DNS name and IP address regardless of the connection to any server (whether or not the server is in the
time-to-live of the DNS result (as is done for JavaScript). application’s own origin) and send arbitrary data. This feature is
an extremely useful, especially as an optimization for scenarios
C. Verified-Origin Policy in which the server wishes to asynchronously send data to the
client. Currently, such applications use a rather clumsy set of
Unfortunately, the same-origin policy, strictly construed, mechanisms generally known as Comet [8]. Like Flash Player
is quite limiting: many web application developers wish to and CORS, WebSockets uses a verified-origin mechanism to let
communicate with other web sites, for example to incorporate the target server consent to the connection. Unlike Flash Player
additional functionality or content (including advertisements). and CORS, the verification is performed over the same socket
Allowing such communication is unsafe in the general case, connection as will be used for the data (using a cryptographic
but the browser can safely allow communication as long as handshake where the server replies to a client-provided nonce).
it verifies that the target site consents to the communication This handshake is performed by the browser and only after the
traffic. There are a number of Web technologies that implement handshake has completed does the browser allow the script to
this verified-origin policy [3]: send raw data over the socket.
1) Flash Cross-Domain Policies: Prior to letting a SWF open
a socket connections to a server,2 Flash Player first connects D. Our Contribution
to the site and fetches a cross-domain policy file: an XML
blob that specifies the origins that are allowed to connect to As the history of DNS rebinding issues above suggests,
that site [4].The location of the policy file is itself subject designing a correct same-origin or verified-origin policy is a
to a number of restrictions, which make it more difficult for challenging problem. Previous designs have been extremely
an attacker who has some access to the victim machine to subject to TOCTOU issues. In this paper, we make two
generate a valid file. For instance, policy files hosted on ports contributions.
≥ 1024 cannot authorize access to ports < 1024. First, we describe and demonstrate a new class of vul-
Flash Player uses the same general mechanism to control nerabilities which affect all the major existing and proposed
access both to raw sockets and to cross-domain HTTP requests. same-origin and verified-origin policies, with the exception
As with Java, Flash Player’s consent mechanism was vulnerable of CORS. Our attacks exploit the existence of transparent
to rebinding attacks in the past. (The DNS rebinding issues proxies in networks and, in particular, their confusion about
in Flash Player were fixed in version 9.0.115.0) Indeed, the how to handle mismatches between the HTTP Host header
mechanism described above where the cross-domain policy file and the destination IP address of the connection they are
is always checked is a response to some of these rebinding intercepting. Using the raw socket APIs available to web
attacks [1] which exploited a time-of-check-time-of-use (TOC- applications we are often able to (depending on the proxy
TOU) issue between the browser’s name resolution and that type) either poison the proxy’s cache so that the proxy serves
performed by Flash Player. data of the attacker’s choice for an arbitrary target.com
to all of the proxy’s users or (with other proxies) to convince
2 This description is a simplification of Flash Player’s actual security the proxy to connect to a host behind the victim’s firewall.
policy [4], which is quite complex. Our measurements indicate that around 3.6% of users on the
Fig. 2. Firewall Circumvention Attack

Internet are behind a transparent proxy that is broken in one A. Vulnerabilities


of these ways. Consider the situation in which the user is behind a
Our second contribution is a consent protocol that resists transparent proxy and visits attacker.com. The attacker
these attacks. Our approach is based on three basic principles. embeds a malicious SWF served from attacker.com, and
First, we address only the verified-origin case, treating same- the browser uses Flash Player to run the SWF. The attacker
origin simply as verified-origin connection to the same address. can now mount a number of different attacks, depending on
This approach eliminates a whole class of attacks involving how the proxy behaves.
confusion between host names and IP addresses. Second, we 1) Route by Host Header: When using a traditional proxy,
perform our verification handshake over the same channel as the browser connects directly to the proxy and sends an HTTP
the data to be sent, thus avoiding attacks that exploit different request, which indicates to the proxy which resource the
routing for different connections. Finally, we mask all the browser wishes to retrieve. When a transparent proxy intercepts
attacker-controlled parts of the handshake with a stream cipher, an HTTP request made by a browser, the proxy has two options
thus making it impractical for the attacker to chose bytes to for how to route the request:
send on the wire that might confuse intermediaries. Rather, the • The HTTP Host header.
data appears random to network entities that are oblivious to • The IP address to which the browser originally sent the
our protocol. We propose replacing all existing verified-origin request.
mechanisms with this mechanism or a derivative.
Unfortunately, as described by Auger [9], if the proxy routes
the request based on the Host header, an attacker can trick the
proxy into routing the request to a server behind the firewall,
III. ATTACKS ON JAVA AND F LASH S OCKETS as depicted in Figure 2:
1) The attacker hosts a permissive Flash socket policy server
In this section, we describe two attacks that leverage browser on attacker.com:843 that allows access to every
socket APIs to attack transparent proxies. Unlike traditional port from every origin.
HTTP proxies, which are explicitly configured and known to the 2) The attacker’s SWF requests to open a raw socket con-
client, transparent proxies insert themselves into the transport nection to attacker.com:80 (which has IP address
path (e.g., by acting as the network’s default gateway or as a 2.2.2.2).
bridge) and then act as proxies without the client’s knowledge. 3) Flash Player connects to attacker.com:843 and
Such proxies are common in traffic filtering applications retrieves the attacker’s a socket policy, indicates that
but also can serve as network accelerators or proxy caches. the server has opted into the socket connection.
Although colloquially referred to as “transparent” proxies, these 4) Flash Player lets the attacker’s SWF open a new socket
proxies are more accurately termed “intercepting” proxies connection to attacker.com:80. proxy.)
because, as we show in this section, they are not quite as 5) The attacker’s SWF sends a sequence of bytes over the
transparent as their deployers might wish. socket crafted with a fake Host header as follows:
Fig. 3. Cache Poisoning Attack

GET /secret.html HTTP/1.1 Some transparent proxies that route by IP are also caching
Host: target.com proxies. As with routing, proxies can cache responses either
6) The transparent proxy treats these bytes as an HTTP according to the Host header or according to the original
request and routes the request according to the Host destination IP address. If a proxy routes by IP but caches
header (and not on the original destination IP address). according to the Host header, the attacker can instruct the
Notice that the request is routed to target.com:80 proxy to cache a malicious response for a URL of the attacker’s
(which has an IP address of 1.1.1.1). choice, as shown in Figure 3:
7) The target server (behind the firewall) replies 1) The attacker’s Java applet opens a raw socket connection
with the confidential document for the URL to attacker.com:80 (as before, the attacker can
http://target.com/secret.html, and the also a SWF to mount a similar attack by hosting an
transparent proxy forwards the response to the attacker’s appropriate policy file to authorize this request).
SWF. 2) The attacker’s Java applet sends a sequence of bytes over
Alternatively, the attacker can try to trick the proxy into the socket crafted with a forged Host header as follows:
tunneling a raw socket connection to the target server using GET /library.js HTTP/1.1
the HTTP CONNECT method: Host: target.com
3) The transparent proxy treats the sequence of bytes as
CONNECT target.com:80 HTTP/1.1
an HTTP request and routes the request based on the
Host: target.com:80
original destination IP, that is to the attacker’s server.
Notice that Flash Player authorized the attacker’s SWF to 4) The attacker’s server replies with malicious script file
open a socket to the attacker’s server based on a policy file it with an HTTP Expires header far in the future (to
retrieved from the attacker’s server. However, the transparent instruct the proxy to cache the response for as long as
proxy routed the request to a different server because the socket possible).
API let the attacker break the browser’s security invariant that 5) Because the proxy caches based on the Host header,
the Host header matched the destination IP address, leading the proxy stores the malicious script file in its
to the vulnerability. cache as http://target.com/library.js, not
An attacker can also exploit Java sockets in the same way. as http://attacker.com/library.js.
The attack steps are identical, except that the attacker need not 6) In the future, whenever any client requests
host a policy file because Java implicitly grants byte code the http://target.com/library.js via the
authority to open socket connections back to its origin server proxy, the proxy will serve the cached copy of the
without requiring the server to consent. malicious script.
2) Cache by Host Header: In the attack above, we consid- One particularly problematic variant of this attack is for
ered transparent proxies that route HTTP requests according to the attacker to poison the cache entry for Google Analytics,
the Host header. However, not all proxies are configured that http://www.google-analytics.com/ga.js. Every
way. Some proxies route the request to the original destination user of the proxy (possibly the entire enterprise) will now
IP address, regardless of the Host header. Although those load the attacker’s malicious JavaScript into every page that
proxies are immune to the attack described in the previous uses Google Analytics, which is approximately 57% of the top
section, the attacker can still leverage some of these proxies 10,000 web sites [10]. Because the Google Analytics JavaScript
to mount an attack. runs with the privileges of the embedding web site, the attacker
is able to effectively mount a persistent cross-site scripting that attempts to load a script from the target server at
attack against the majority of the Internet, as viewed by users http://target.com/script.php/<random>,
of the proxy. reusing the random value from the previous request.
Because the random value was only used previously via
B. Experiment the socket API, this URL will not be present in the
The attacks described above have very specific network browser’s HTTP cache (as the browser does not observe
configuration requirements. To determine how commonplace the bytes sent over the socket). By checking the contents
these network configurations are on the Internet, we developed of the response (specifically, a JavaScript variable), we can
proof-of-concept exploits for both the firewall circumvention determine whether the script was from the attacker or the
and cache poisoning attacks using both Flash Player and Java. target server. If we receive the version of the script hosted
We then ran an advertisement on a public advertising network on the attack server, we can deduce that a transparent
that mounted the attacks against servers in our laboratory. proxy has cached the response.
1) Methodology: Our experiment consisted of two machines 2) Results: We ran our advertisement on five successive
in our laboratory, with different host names and IP addresses. days in November 2010, spending $150 in total. We garnered a
One machine played the role of the target server and the total of 144,549 unique impressions. We discarded repeat visits
other played the role of the attacking server. The target was a by the same users by setting a cookie in the user’s browser.
standard Apache web server. The attacking server ran a standard The advertisement ran our JavaScript, SWF, and Java code
Apache web server and a Flash socket policy server on port without user intervention and sent results back to server in our
843. We used a rich media banner advertisement campaign laboratory after completing the experiment. If the user closed
on an advertising network to serve our experimental code to the browser window or navigated away before the experiment
users across the world. Our advertisement required no user finished running, we did not receive the results from that part
interaction, and was designed to perform the following tasks of the experiment. We collected 36,305 results from SWFs and
in the user’s web browser: 33,820 results from Java applets (16,843 of the impressions
produced results from both tests). The most likely reason for
• Firewall Circumvention Test. Our advertisement opens
the low response rate is that the loading time of our SWF and
a raw socket connection back to the attacking server
Java code was noticeably slow, and users did not stay on the
using both Java and Flash Player. The attacking server
page long enough for the experiment to run. Our experimental
runs a custom Flash socket policy server on port 843
results show that both proxy cache poisoning and firewall
that allows Flash socket connections to port 80 from any
circumvention attacks exist in real world scenarios, as shown
origin. Upon a successful connection, the advertisement
in Table I.
spoofs an HTTP request over the socket by sending the
a) Firewall Circumvention Tests: In the firewall circum-
following request:
vention test using Flash sockets, we observed that the spoofed
GET /script.php/<random> HTTP/1.1 request was routed back to the attacking server on 25,665
Host: target.com of 36,305 impressions (70.6%), suggesting that the client
The attacking server and the target server each host a made a direct connection or the network intermediaries routed
PHP file at /script.php, but because these files are regardless of the Host header. We logged 9,830 of 36,305
different we can easily determine which server the request impressions (26%) where the Flash socket failed to open,
went to. The random value on the end of the URL serves possibly due to firewalls that blocked port 843, preventing Flash
to bypass caches used by plugins, browsers, or proxies. Player from fetching the socket policy file. There were 7 cases
Alternatively, we could have included the random value in where the client received an HTML error message, possibly
the query string (i.e., after a ? character) but some caching generated by a transparent proxy that blocked the spoofed
proxies treat URLs containing query strings inconsistently. request. On 803 impressions (2.2%) the spoofed request was
If the request went to the attacker server, implying that it routed by the Host header to the target server, indicating
is routing on the Host header, that is an indication that possible vulnerability to firewall circumvention.
the user is vulnerable to firewall circumvention. However, Using Java sockets, we observed that 32,422 of 33,820
we cannot guarantee that the user is vulnerable to attack impressions (95.9%) received the response from the attacker’s
because the proxy might be outside the firewall or might server, implying that they were routing on IP. Out of 33,820
be configured to block “hairpin” requests for resource impressions, there were 184 (0.54%) connection errors that
behind the Firewall. Our experiment cannot distinguish threw Java exceptions and 2 that received an HTML error
these cases. message. We found that 1,212 of 33,820 impressions (3.6%)
• Cache Poisoning Test. In the previous test, the script routed on the Host header. Note that while the Java test reports
files were served with Cache-Control: public, a higher fraction of successful tests than the SWF test, the
Last-Modified and Expires response headers difference is largely due to the large fraction of the SWF tests
that allowed them to be cached for one year. To check which were unable to open a raw socket at all.
whether the socket connection has poisoned the proxy’s b) Cache Poisoning Tests: In the cache poisoning test
cache, we added a script tag to our advertisement using Flash sockets, we observed that 36,262 of 36,305 (99.9%)
Flash Player Java
Spoof request routed to target? 803 1212
Spoof request routed to attacker 25665 32422
Script tag cached from target 36262 21271
Script tag cached from attacker† 42 32
TABLE I
HTTP H OST HEADER SPOOFING VIA PLUGIN SOCKETS

POST-based Upgrade-based Our Proposal


Handshake pass and spoof request ignored 47741 47162 47204
Spoof request routed to target? 1376 1 0
Spoof request routed to attacker 97 174 2
Script tag cached from target 54519 54526 54534
Script tag cached from attacker† 15 8 0
TABLE II
HTTP H OST HEADER SPOOFING VIA PROPOSED W EB S OCKET HANDSHAKES

? Allows attacker to open a direct socket from the client to an arbitrary server, bypassing firewalls
† Allows attacker to poison the HTTP cache of all clients of the proxy

impressions were able to fetch the script from the target. data. With this goal in mind, consider the following strawman
However, we discovered that the cache poisoning attack was handshake based on an HTTP POST request:
successful on 42 of 36,305 (0.12%) impressions. This suggests
that some transparent proxies route HTTP requests by IP but Client → Server:
cache according to the Host header. POST /path/of/attackers/choice HTTP/1.1
In our cache poisoning test using Java sockets, we observed Host: host-of-attackers-choice.com
that 12,517 of 33,820 impressions (37%) caused exceptions Sec-WebSocket-Key: <connection-key>
when using Java to interrogate the results of the second
query. Thus, we were unable to determine whether the cache Server → Client:
poisoning succeeded or not. Out of 21,303 impressions that HTTP/1.1 200 OK
executed correctly, we observed 21,271 (99.8%) impressions Sec-WebSocket-Accept: <connection-key>
that retrieved the response from the attacking server. Similarly
to the results using Flash sockets, there were 32 impressions If WebSockets are less generative than the form element, then
(0.15%) that reported a successful cache poisoning attack. we might believe that adding WebSockets support to browsers
does not increase the attack surface.
IV. V ULNERABLE H ANDSHAKES 2) Attack: Unfortunately, using this handshake WebSockets
One diagnosis of the cause of the Java and Flash socket are not less generative than the HTML form element, which
vulnerabilities is that both use an out-of-band mechanism leads to vulnerabilities. Although we have accomplished our
to authorize socket connections. Because intermediaries are initial goal of not sending any non-HTTP data to WebSockets
oblivious to these out-of-band signals, they misinterpret the servers, we can still confuse transparent proxies.
information sent over the socket by the attacker. In this Consider an intermediary examining packets exchanged
section, we consider two in-band signaling mechanisms for between the browser and the attacker’s server. As above,
authorizing socket connections, both based on HTTP. The first the client requests WebSockets and the server agrees. At
is a “strawman” proposal of our own invention to illustrate this point, the client can send any traffic it wants on the
some of the design issues. The second is the state-of-the-art channel. Unfortunately, the intermediary does not know about
handshake used by HTML5. WebSockets, so the initial WebSockets handshake just looks
like a standard HTTP request/response pair, with the request
A. A POST-based Handshake being terminated, as usual, by an empty line. Thus, the client
1) Design: One natural approach to designing an in-band program can inject new data which looks like an HTTP request
signaling mechanism is to model the handshake after HTTP. and the proxy may treat it as such. So, for instance, he might
The idea here is that until we have established the server’s inject the following sequence of bytes:
consent to receive WebSockets traffic, we will not send any data GET /sensitive-document HTTP/1.1
that the attacker could not already have generated with existing Host: victim.com
browser functionality—with the HTML form element being
the most powerful piece of syntax in this respect—so what When the intermediary examines these bytes, it might conclude
could possibly go wrong? This should protect servers which that these bytes represent a second HTTP request over the
do not want to speak WebSockets from being sent WebSockets same socket. If the intermediary is a transparent proxy, the
intermediary might route the request or cache the response Connection: Upgrade
according to the forged Host header, discussed in Section III. Upgrade: WebSocket
3) Experiment: To evaluate the practicality of mounting Sec-WebSocket-Accept:
firewall circumvention and cache poisoning attacks with the HMAC(<connection-key>, "...")
WebSocket handshakes, we implemented prototypes for each
2) Attack: Unfortunately, HTTP’s Upgrade mechanism is
WebSocket handshake using Flash sockets and a WebSocket
virtually unused in practice. Instead of layering TLS over
server written in Python. We reused the system from the Java
HTTP using Upgrade, nearly every deployment of HTTP over
and Flash socket experiment with the following changes. We
TLS uses a separate port, typically port 443 (the generic
setup a custom multiplexing server at port 80 on the attacking
name for this mode is HTTPS [11]). Consequently, many
server, which forwards requests to either a standard Apache
organizations are likely to deploy network intermediaries that
server or the WebSocket server depending on the request
fail to implement the Upgrade mechanism because these
headers. We ran an advertisement campaign for four successive
intermediaries will largely function correctly on the Internet
days in November 2010, spending $20 in the Philippines
today. Implementers and users of these intermediaries have
and $80 globally. Our advertisement contains a SWF which
little incentive to implement Upgrade, and might, in fact, be
performs the WebSocket handshake, spoofs an HTTP request
unaware that they do not implement the mechanism.
upon handshake success, and instructs the browser to request a
To an intermediary that does not understand HTTP’s Up-
script from the target server using a script tag. We experimented
grade mechanism, the HTML5 WebSocket handshake appears
with how intermediaries process each WebSocket handshake.
quite similar to our strawman POST-based handshake. These
Table II shows our results.
intermediaries are likely to process the connection the same
Out of a total of 54,534 impressions, 49,218 (90.2%)
way for both the POST-based handshake and the Upgrade-
succeeded with the POST-based handshake and 5,316 (9.4%)
based handshake. If such an intermediary is vulnerable to the
failed. Out of the 49,218 impressions on which we were
attacks on the POST-based handshake, they intermediary is
able to run our firewall circumvention test, 47,741 (96.9%)
likely to be vulnerable to the same attacks when using the
reported that no intermediaries were confused when sending
Upgrade-based handshake.
the spoofed HTTP request. However, we found that the firewall
3) Experiment: In our experiment, we tested how interme-
circumvention attack succeeded on 1,376 of 49,218 impressions
diaries in the wild process the Upgrade-based handshake. Out
(2.8%), where the client was behind a Host-routing proxy.
of a total of 54,534 impressions, 47,338 (86.8%) succeeded
There were 97 of 49,218 impressions (0.2%) where the spoofed
with the handshake and 7,196 (13.2%) failed. The handshake
request was routed by IP and 4 that received an HTML error.
failed more often than the POST-based handshake, possibly
We ran the cache poisoning test on the clients that succeeded
when the Upgrade mechanism was unsupported and, perhaps,
with the POST-based handshake, and found 15 successful cache
stripped. Out of the 47,338 impressions on which we were
poisoning attacks. These results show that the POST-based
able to run our firewall circumvention test, 47,162 (99.6%)
handshake is vulnerable to both attacks.
did not receive a response after spoofing an HTTP request.
B. HTML5’s Upgrade-based Handshake. We noticed that the firewall circumvention attack succeeded
on 1 impression, where the client was behind a Host-routing
1) Design: In an attempt to improve the security of its proxy. There were 174 of 47,338 impressions (0.37%) where
socket handshake, HTML5 uses HTTP’s Upgrade mechanism the spoofed request was routed by IP. One impression received
to upgrade from the HTTP protocol to the WebSocket protocol. an HTML error message.
HTTP’s Upgrade mechanism is a generic mechanism for nego- Out of the 47,338 impressions that succeeded the Upgrade-
tiating protocols using HTTP which was originally designed based handshake, we ran the cache poisoning test and found
for layering TLS over HTTP. HTTP’s Upgrade mechanism has 8 successful cache poisoning attacks. The 8 impressions were
two pieces: a Connection header whose value is the string also vulnerable to cache poisoning when using the POST-based
“Upgrade” and an Upgrade header whose value is the name handshake.
of the protocol to which the client wishes to switch. Below
is a simplified version of the HTML5 WebSocket handshake V. O UR P ROPOSAL
using HTTP’s Upgrade mechanism.
In this section, we present our proposal for a WebSocket
Client → Server: handshake. Rather than relying upon the rarely used HTTP
GET /path/of/attackers/choice HTTP/1.1 Upgrade mechanism to inform network intermediaries that the
Host: host-of-attackers-choice.com remainder of the socket is not HTTP, we propose using HTTP’s
Connection: Upgrade CONNECT mechanism. This mechanism is widely used on the
Sec-WebSocket-Key: <connection-key> Internet to tunnel TLS connections through proxies. Proxy
Upgrade: WebSocket implementations that lack support for the CONNECT mechanism
will likely discover and repair that oversight quickly.
Server → Client: In addition to using HTTP’s CONNECT mechanism, we mask
HTTP/1.1 101 Switching Protocols all the attacker-controlled bytes in the initial handshake message
by encrypting them under a key derived from a nonce in the require “knowledge” of an identifier that is globally unique to
initial handshake message and a globally unique identifier the WebSocket protocol. We believe it is unlikely that a server
that represents the WebSocket protocol. To a receiver who that is oblivious to the WebSocket protocol would reply with
does not understand the WebSocket mechanism (and hence the appropriate <hmac> value.
does not know the globally unique identifier), these bytes will
appear to be chosen uniformly at random, making it difficult B. Experiment
for the attacker to confuse the receiver into performing some We tested whether our proposal would resist transparent
undesirable action. proxy attacks in the real world. Out of a total of 54,534
A. Design impressions, 47,206 (86.6%) succeeded with the handshake
and 7,328 (13.4%) failed. Out of the 47,206 impressions on
To establish a WebSocket connection, the browser sends the which we were able to run our firewall circumvention all but
server the following message, which uses an HTTP CONNECT two did not receive a response after spoofing an HTTP request.
request: We observed that the firewall circumvention attack did not
Client → Server: succeed on any clients. We logged 1 impression that returned
CONNECT websocket.invalid:443 HTTP/1.1 an HTML error message. We observed 2 impressions where the
Host: websocket.invalid:443 spoof request was routed by IP to the attacking server, however
Sec-WebSocket-Key: <connection-key> none indicated proxy routing based on the Host header. It
Sec-WebSocket-Metadata: <metadata> appears that these proxies simply passed the CONNECT to our
server untouched and then treated the next spoofed request as
where <connection-key> is a 128-bit random number if it were a separate request routed by IP. We proceeded to
encoded in base64 and <metadata> is various metadata the cache poisoning test and found that none of the clients
about the connection (such as the URL to which the client were vulnerable to the cache poisoning attack. Our experiment
wishes to open a WebSocket connection), encrypted using results showed that our proposal successfully resisted to both
AES-128-CTR and encoded in base64. To key the encryp- the firewall circumvention and cache poisoning attacks.
tion, the client uses HMAC of the globally unique identi-
fier C1BA787A-0556-49F3-B6AE-32E5376F992B un- C. Security Analysis
der with key <connection-key>. Note that the browser
Our proposed WebSocket handshake mechanism has a
must ensure that the application provides the metadata before
number of desirable properties:
the connection key is sent, otherwise it will be possible to
control the encrypted metadata. • Because CONNECT is used to establish opaque tunnels to

Encrypting the metadata does not provide any confidentiality pass TLS traffic, transparent proxies are likely to interpret
from eavesdroppers. An eavesdropper can read the connection this request as an HTTPS connect request, assume the
key out of the Sec-WebSocket-Key and compute the remainder of the socket is unintelligible, and simply route
encryption key. Instead, encrypting the metadata prevents the all traffic transparently based on the IP.
attacker controlling the bytes sent on the wire to the recipient, • The handshake breaks any intermediary that attempts to

who has not yet demonstrated a willingness to speak the interpret it. Instead of using the attacker’s host name,
WebSockets protocol. We encrypt the metadata using a stream we use an invalid host name (per RFC 2606 [12]). Any
cipher, such as AES-128-CTR, to ensure that the encrypted intermediaries that understand this message according to
bytes appear to be chosen uniformly at random to a recipient its HTTP semantics will route the request to a non-existent
who lacks the key. host and fail the request. Even if the host did somehow
To accept the request, the server replies with the following resolve, CONNECT does not involve transmitting any of the
message: headers to the destination server so the proxy would not
route the Sec-WebSocket-Key to the attacker, making
Server → Client: it difficult for the attacker to perform actions based on
HTTP/1.1 200 OK the key.
Sec-WebSocket-Accept: <hmac> • The attacker cannot choose any of the bytes sent on the

where <hmac> is the HMAC of the globally unique iden- wire in the handshake. The URL and the Host header
tifier 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 un- are fixed, the connection key is random, and although the
der the key <connection-key> (encoded in base64). No- plaintext of the metadata is controlled by the attacker, the
tice that this message is a well-formed acceptance of the HTTP ciphertext is random from the attacker’s perspective.
CONNECT request. An intermediary that understands CONNECT • The handshake message cannot be generated by a web

requests is likely to treat any further bytes transmitted on this attacker in today’s browsers. A server that wishes to
socket as opaque. multiplex HTTP and WebSockets on the same port can
By sending the <hmac> value, the server demonstrates use the request-line to distinguish the two protocols.
to the client that it understands and is willing to speak the We now consider the major threats that any proposed
WebSocket protocol because computing the <hmac> value handshake must address.
Fig. 4. Our proposal

1) Completing the Handshake with non-WebSockets Servers: proxy) or reject the request (more likely). If the server attempts
The first case we must consider is whether an attacker can con- to service the request, then the server will most likely simply
vince a non-WebSockets server to send traffic which completes fail because the request is to connect to an invalid host. Even if
the handshake. Clearly, because the handshake requires that the the server somehow manages to service the request, the result
server perform a cryptographic operation (HMAC) involving is simply a transparent connection carrying only the payload,
a WebSocket-specific globally unique identifier, no existing which is empty (i.e., stripping the Sec-WebSocket-Key
unmodified server will perform the operation correctly. This and Sec-WebSocket-Metadata headers) with the result
does not exhaust the analysis, however: The attacker might be that it leaks no information about the key. Therefore, all the
able to gain some control over the server. For example, the attacker can do is open a socket to whatever target the initial
victim server might be in a shared hosting environment and the server routes the connection to.
attacker might control a name-based virtual host on the same If the server is oblivious to HTTP, then the possibilities for
machine. This scenario is the motivation for the bogus Host attack are even more limited. The attacker cannot choose any of
header and the CONNECT method, both of which prevent the the bytes in the initial handshake, and the fixed portions of the
attacker from being able to funnel requests to his or her virtual initial handshake message do not match any non-HTTP protocol
host. Instead, if the server attempts to serve the request at all, header with which we are familiar, and the remainder of the
the server will simply discover that there is no matching host message is simply random from the attacker’s perspective.
and reject it. It seems unlikely that this mechanism can be used to any
significant effect on the protocol state machine.
2) Cross-Protocol Attacks on non-WebSockets Servers: We 3) Attacks via Network Intermediaries: Having considered
next consider the case where an attacker uses the WebSocket the previously known attacks, we now consider attacks using
protocol to attack a server that does not support the WebSocket network intermediaries like those described in Section III.
protocol. More specifically, the attacker writes a web site that We are primarily concerned here with transparent intermedi-
uses the WebSockets API to send traffic to an unsuspecting aries. Non-transparent intermediaries (i.e., HTTP proxies) are
server. If the server is familiar with HTTP semantics, then the configured into the browser and the browser will need to attempt
server will treat the WebSocket handshake as a CONNECT re- an RFC 2817 [13] CONNECT to establish a clear channel to
quest and either attempt to service the request (if the server is a the server before it begins the WebSockets handshake. At that
point, a compliant intermediary will simply ignore the contents and IRC. To prevent these attacks, browsers restrict access to
of the traffic entirely. Any intermediary that does attempt to well-known ports of vulnerable applications, such as port 25
inspect the contents is most likely some sort of deep packet for SMTP. This defense cannot be applied to WebSockets
inspection enforcement device and will probably either fail because WebSockets operates over port 80, the same port as
when it determines that the traffic is not TLS or to simply pass with HTTP, for compatibility. We suspect there are other forms
the CONNECT on to the next proxy in the chain. of cross-protocol attacks and expect to address more of these
Transparent proxies that attempt to actually engage the problems in future work.
CONNECT handshake (e.g., an intermediary which is both
transparent and non-transparent and which attempts to auto- B. Pretty-Bad-Proxy
detect the type of handshake) will, as described above, route Chen et. al. [16] introduce a series of attacks in which a
on the Host header and thus fail the connection. malicious proxy breaks the end-to-end security guarantees of
The analysis of caching servers is more complicated. Con- the TLS protocol by injecting messages that are interpreted
sider a caching proxy as described in Section III-A2 that caches as HTTPS responses by the browser. A malicious proxy can
on the Host header. If the proxy actually processes CONNECT trick browsers into running a script of the attacker’s choice in
correctly then, like a non-transparent proxy, it will attempt to the security context of a target server by embedding scripts
connect to the host specified in the URI, which will fail. in HTTP error messages or by redirecting script requests
In our experiments, we observed two proxies which appear to malicious servers using HTTP redirects. Browsers have
not to understand CONNECT but simply to treat the request mitigated these vulnerabilities by ignoring the proxy redirection
as an ordinary request and then separately route subsequent and error messages received prior to completing the TLS
requests, with all routing based on IP address. Although these handshake. Our work does not focus on malicious proxies.
proxies did not cache, it is possible that proxies of this type Rather, we are interested in benign-but-confused proxies.
which cache do exist—though our data suggest that they would However, one should always be wary of malicious proxies
be quite rare. In this case the attacker would be able to mount when designing a secure communication protocol.
a cache poisoning attack as described in Section III-A2.
Although appearing to be possible only in rare cases, this C. DNS Rebinding
attack can be mitigated by encrypting the raw sockets traffic
in addition to the initial routing data. However, encrypting the DNS rebinding [1] attacks subvert the same-origin policy by
raw socket writes as one long stream is insufficient because the manipulating to which IP addresses the attacker’s host names
attacker learns the encryption key in the handshake and thus are bound. In a DNS rebinding attack, the attacker responds to
can generate inputs to the socket write function that produce user’s initial DNS query with a short TTL, then subsequently
ciphertexts of his choice. Instead, we encrypt each write() binds attacker.com to the target’s IP address. As a result,
separately, using a random nonce as the top part of the CTR scripts from the attacker’s page are able to read responses
counter block, with the lower part being reserved for the block retrieved from the target’s IP address.
counter. From the perspective of the attacker, this effectively DNS rebinding attacks have similar results to several attacks
randomizes the data sent on the wire even if the attacker knows we discuss in this paper. For example, proxies that route based
the key exchanged in the handshake. Note that each write() on host headers suffer from similar security consequences as a
must be encrypted with a fresh nonce and that the browser DNS rebinding attack. However, DNS rebinding attacks cannot
must not send any bytes on the wire until the browser receives poison HTTP caches in the same way that our attacks can
the entire data block from the script. Otherwise, the attacker poison the proxy’s HTTP cache.
could learn the nonce and adjust the rest of the input data
D. Transparent Proxy Vulnerabilities
based on that information.3 This mitigation comes at a modest
performance cost and some cost in packet expansion for the Auger [9] describes how an attacker can leverage transparent
nonce, which needs to be large enough that the attacker’s proxies to access servers behind firewalls via the use of socket-
chance of guess the nonce is sufficiently low. For example, 64 capable browser plug-ins. The attack uses Flash sockets to
bits (8 bytes) seems likely to be a sufficient value. communicate with hosts accessible to the proxy, bypassing the
browser’s restrictions on network access. The attack required
VI. R ELATED W ORK that the transparent proxy routes HTTP requests based on their
A. Cross-Protocol Attacks Host headers, as described in Section III-A1. In our work, we
Cross-protocol attacks are used to confuse a server or an in- experimentally verify that such attacks are effective in the wild
termediary into associating a request with an incorrect protocol. and measure the fraction of users that are vulnerable to attack.
We described an instance of a cross protocol attack between In addition, we introduce and demonstrate new attacks that
HTTP and the WebSocket protocol. Topf [15] describes an poison the cache of proxies that route by IP address (but cache
attack that uses HTML forms to send commands to servers by Host header). Instead of retrieving confidential documents
running ASCII based protocols like SMTP, NNTP, POP3, IMAP, protected by a firewall, these attacks are analogous to a cross-
site scripting attack: the attacker injects malicious content into
3A similar condition applies to TLS [14] packet writes. honest security origins for every user of the proxy.
E. HTTP Response Splitting [7] I. Hickson, “The Web Sockets API,” 2009, http://www.w3.org/TR/
websockets/.
In an HTTP response splitting attack [17], the attacker [8] A. Russell, “Comet: Low Latency Data for the Browser,” 2006, http:
sends a single HTTP request that tricks the benign server //infrequently.org/2006/03/comet-low-latency-data-for-the-browser/.
[9] R. Auger, “Socket capable browser plugins result in transparent proxy
into generating an HTTP response that is misinterpreted by abuse,” 2010, http://www.thesecuritypractice.com/the security practice/
the browser or an intermediary as two HTTP responses. TransparentProxyAbuse.pdf.
Typically, the malicious request contains CRLF sequences [10] BuiltWith, “Google Analytics Usage Statistics,” 2010, http://trends.
builtwith.com/analytics/Google-Analytics.
that are reflected by the server into the output stream and [11] E. Rescorla, “HTTP Over TLS,” RFC 2818 (Informational), Internet
appear to terminate the first response, letting the attacker craft Engineering Task Force, May 2000, updated by RFC 5785. [Online].
the byte sequence that the browser or intermediary interprets Available: http://www.ietf.org/rfc/rfc2818.txt
[12] D. Eastlake 3rd and A. Panitz, “Reserved Top Level DNS Names,” RFC
as the second response. The attacker can mount a cache 2606 (Best Current Practice), Internet Engineering Task Force, Jun.
poisoning attack by sending a second request to a benign 1999. [Online]. Available: http://www.ietf.org/rfc/rfc2606.txt
server, which causes the browser or proxy associates with [13] R. Khare and S. Lawrence, “Upgrading to TLS Within HTTP/1.1,” RFC
2817 (Proposed Standard), Internet Engineering Task Force, May 2000.
the second “response” and stores in its cache. Servers can [Online]. Available: http://www.ietf.org/rfc/rfc2817.txt
prevent the attack by sanitizing data and not allowing CRLF in [14] T. Dierks and E. Rescorla, “The Transport Layer Security (TLS) Protocol
HTTP response headers. In our work, we introduce new cache Version 1.2,” RFC 5246 (Proposed Standard), Internet Engineering Task
Force, Aug. 2008, updated by RFCs 5746, 5878. [Online]. Available:
poisoning attacks against transparent proxies, which are not http://www.ietf.org/rfc/rfc5246.txt
addressed by previous mitigations. [15] J. Topf, “Html form protocol attack,” 2001, http://www.remote.org/jochen/
sec/hfpa/hfpa.pdf.
VII. C ONCLUSION [16] S. Chen, Z. Mao, Y.-M. Wang, and M. Zhang, “Pretty-bad-proxy: An
overlooked adversary in browsers’ https deployments,” in Proceedings
Although raw socket access is an important capability for full- of the 2009 30th IEEE Symposium on Security and Privacy, 2009.
featured browser-based applications, providing sockets safely [17] A. Klein, “Divide and conquer - HTTP response splitting, web cache
poisoning attacks, and related topics,” 2004, http://packetstormsecurity.
has proven to be challenging. While it is well-understood org/papers/general/whitepaper httpresponse.pdf.
that the browser needs to verify that the destination server
consents to receive raw socket traffic, our results demonstrate
that all the major current mechanisms for verifying consent
are broken in the face of certain transparent proxies. Not only
are there theoretical vulnerabilities, our measurements show
that approximately 3.6% of browsers are behind proxies with
implementation errors that may enable attack via one of these
vectors.
We propose a new mechanism which addresses all known
issues with the existing consent verification techniques. This
mechanism is based on the three key ideas: (1) using HTTP
CONNECT to suppress processing by intermediate proxies (2)
in-band verification to prevent attacks between connections and
(3) preventing the browser application from directly controlling
any of the bytes on the wire by encrypting the traffic using
keys which are established as part of the handshake. Our mea-
surements indicate that this handshake achieves similar success
rates to existing proposals for the WebSockets handshake while
having superior security properties.

R EFERENCES
[1] C. Jackson, A. Barth, A. Bortz, W. Shao, and D. Boneh, “Protecting
browsers from dns rebinding attacks,” in Proceedings of the 14th ACM
Conference on Computer and Communications Security, 2007.
[2] D. D. Edward, E. W. Felten, and D. S. Wallach, “Java security: From
hotjava to netscape and beyond,” in Proceedings of the 1996 IEEE
Symposium on Security and Privacy, 1996.
[3] H. Wang, X. Fan, J. Howell, and C. Jackson, “Protection and communi-
cation abstractions for web browsers in mashupos,” in Proceedings of
21st ACM SIGOPS Symposium on Operating Systems Principles (SOSP),
2007.
[4] Adobe, “White paper: Adobe flash player 10 security,” 2008, http://www.
adobe.com/devnet/flashplayer/articles/flash player10 security wp.html.
[5] M. Zalewski, “Browser security handbook,” http://code.google.com/p/
browsersec/wiki/Part2#Same-origin policy for XMLHttpRequest.
[6] A. van Kesteren, “Cross-Origin Resource Sharing,” 2010, http://www.
w3.org/TR/cors/.

You might also like