Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Cookies Lack Integrity: Real-World Implications

Xiaofeng Zheng, Tsinghua University; Jian Jiang, University of California, Berkeley;


Jinjin Liang, Tsinghua University; Haixin Duan, Tsinghua University and International
Computer Science Institute; Shuo Chen, Microsoft Research Redmond;
Tao Wan, Huawei Canada; Nicholas Weaver, International Computer Science Institute
and University of California, Berkeley
https://www.usenix.org/conference/usenixsecurity15/technical-sessions/presentation/zheng

This paper is included in the Proceedings of the


24th USENIX Security Symposium
August 12–14, 2015 • Washington, D.C.
ISBN 978-1-931971-232

Open access to the Proceedings of


the 24th USENIX Security Symposium
is sponsored by USENIX
Cookies Lack Integrity: Real-World Implications
Xiaofeng Zheng1,2,3 , Jian Jiang7 , Jinjin Liang1,2,3 , Haixin Duan1,3,4 , Shuo Chen5 , Tao Wan6 , and
Nicholas Weaver4,7
1 Institute
for Network Science and Cyberspace, Tsinghua University
2 Department of Computer Science and Technology, Tsinghua University
3 Tsinghua National Laboratory for Information Science and Technology
4 International Computer Science Institute
5 Microsoft Research Redmond
6 Huawei Canada
7 UC Berkeley

Abstract man-in-the-middle (MITM). However, there is no similar


measure to protect its integrity from the same adversary:
A cookie can contain a “secure” flag, indicating that it an HTTP response is allowed to set a secure cookie for
should be only sent over an HTTPS connection. Yet there its domain. An adversary controlling a related domain
is no corresponding flag to indicate how a cookie was is also capable to disrupt a cookie’s integrity by making
set: attackers who act as a man-in-the-midddle even tem- use of the shared cookie scope. Even worse, there is an
porarily on an HTTP session can inject cookies which asymmetry between cookie’s read and write operations
will be attached to subsequent HTTPS connections. Sim- involving pathing, enabling more subtle form of cookie
ilar attacks can also be launched by a web attacker from a integrity violation.
related domain. Although an acknowledged threat, it has
The lack of cookie integrity is a known problem,
not yet been studied thoroughly. This paper aims to fill
noted in the current specification [2]. However, the
this gap with an in-depth empirical assessment of cookie
real-world implications are under-appreciated. Although
injection attacks. We find that cookie-related vulnerabil-
the problem has been discussed by several previous re-
ities are present in important sites (such as Google and
searchers [4, 5, 30, 32, 24, 23], none provided in-depth
Bank of America), and can be made worse by the im-
and real-world empirical assessment. Attacks enabled by
plementation weaknesses we discovered in major web
merely injecting malicious cookies could be elusive, and
browsers (such as Chrome, Firefox, and Safari). Our
the consequence could be serious. For example, a cau-
successful attacks have included privacy violation, on-
tious user might only visit news websites at open wireless
line victimization, and even financial loss and account
networks like those at Starbucks. She might not know
hijacking. We also discuss mitigation strategies such as
that this is sufficient for a temporary MITM attacker to
HSTS, possible browser changes, and present a proof-of-
inject malicious cookies to poison her browser, and com-
concept browser extension to provide better cookie iso-
promise her bank account when she later logs on to her
lation between HTTP and HTTPS, and between related
bank site at home.
domains.
We aim to understand how could attackers launch
cookie inject attacks, and what are the damaging con-
1 Introduction sequences to real-world websites. Our study shows
that most websites are potentially susceptible to cookie
The same-origin policy (SOP) is a corner stone of web injection attacks by network attackers. For example,
security, guarding the web content of one domain from only one site in the Alexa top 100 websites has fully
the access from another domain. The most standard def- deployed HTTP Strict Transport Security (HSTS) on
inition of “origin” is a 3-tuple, consisting of the scheme, its top-level domain, a sufficient server-side protection
the domain and the port number. However, the notion of to counter cookie injection attacks by network attack-
“origin” regarding cookies is fairly unusual – cookies are ers (Section 3). We also found a number of browser
not separated between different schemes like HTTP and vulnerabilities and implementation quirks that can be ex-
HTTPS, as well as port. The domain isolation of cookie ploited by cookie injection attacks (Section 4). Notably,
is also weak: different but related domains can have a all major browsers, except Internet Explorer (IE), respect
shared cookie scope. A cookie may have a “secure” flag, the “Set-Cookie” header in a 407-response (i.e., an Au-
indicating that it should only be presented over HTTPS, thentication Required Response) when configured to use
ensuring confidentiality of its value against a network a proxy. Because of this vulnerability, even websites

USENIX Association 24th USENIX Security Symposium  707


adopting sufficient HSTS are subject to cookie injection 2 Background
attacks by a malicious proxy.
Our study also shows that current cookie practices 2.1 Cookies
have widespread problems when facing cookie injection
attacks (Section 5). We demonstrate multiple exploita- Cookies are a browser-side assisted state management
tions against large websites. For example, we show that mechanism that are pervasively used by web applica-
an attacker can put his Gmail chat gadget on a victim’s tions [2]. Cookies can be set by either HTTP servers
screen without affecting the victim’s use of Gmail and using “Set-Cookie:” header or client side JavaScript
other Google services. We also demonstrate that an at- with a write to “document.cookie”. A cookie can
tacker can hijack a victim’s online deposit to his account, have five optional attributes: domain and path specify-
or even deliver the victim’s online purchase to his ad- ing the cookie’s scope; expires stating when it should
dress. Other exploitations include user tracking, cross- be discarded; secure specifying that it should only be
site scripting (XSS) attacks against large financial sites sent over HTTPS connections, and HTTPOnly prevent-
embedded in injected cookies, etc.. ing browser-side scripts from reading the cookie. When
We have developed a mitigation strategy (Section 6). sending a request to a server, a web browser includes all
By modifying how browsers treat secure cookies, it is unexpired cookies whose domains and paths match the
possible to largely mitigate cookie injection attacks by requested URL, excluding those marked as secure from
network attackers. We have also considered possible the inclusion in an HTTP request.
browser enhancements to mitigate cookie injection from Cookies have two fairly unusual behaviors. First,
web attackers. We implement our proposals as a proof- there is a critical disconnection between cookie stor-
of-concept browser extension. A preliminary evaluation age and reading. Cookies are set and stored as a
does not encounter compatibility issues. name/domain/path to value attributes mapping, but only
In summary, this work makes the following main con- name-value pairs are presented to both JavaScript and
tributions: web servers. This asymmetry allows cookies with the
same name but different domain and/or path scopes to be
written into browser; a subsequent reader can read out
• We provided an evaluation of potential susceptible
all same name cookies together, yet cannot distinguish
websites to cookie injection attacks, including a de-
them because the other attributes such as path are not
tailed measurement of full HSTS adoption and an
presented in the reading process. Another complication
assessment of shared domains used by Content De-
occurs when writing a cookie, the writer can specify ar-
livery Networks (CDNs).
bitrary value for the path attribute, not limited by the
URL of the writer’s context.
• We examined both browser-side and server-side
Moreover, the security policy for cookies is not as
cookie implementation, in which we found sev-
stringent as the classic SOP. In web security, the SOP
eral browser vulnerabilities and a number of non-
is the most important access control mechanism to seg-
conforming and/or inconsistent implementations
regate static contents and active scripts from different
that could be exploited in cookie injection attacks.
origins [3]. An origin for a given URL is defined by a
3-tuple: scheme (or protocol), e.g. HTTP or HTTPS, do-
• We demonstrated the severity and prevalence of main (or host), and port (not supported by IE (Internet
cookie injection attacks in the real world. In par- Explorer)). However, the security policy guarding cook-
ticular, our exploitations against a variety of large ies does not provide separation based on either scheme or
websites show that cookie injection enables compli- port but only on domain [2]. In addition, a website can
cated interactions among implements, applications, set cookies with flexible domain scopes: 1) not shared
and various known attacks. (i.e., host-only), 2) shared with its subdomains, or 3)
shared with its sibling domains (i.e., using its parent do-
• We developed and implemented browser-side en- main as the scope). For the third case, a restriction is en-
hancements to provide better cookie isolation. Our forced by browser to ensure that a cookie domain scope
evaluation showed promising results in compatibil- is not “too wide”. For example, www.example.com can
ity. set a cookie with the scope of .example.com, but it can-
not set a cookie with .com as the scope because .com is a
Together, this work provides a close-up picture of the public top level domain (TLD). Unfortunately, there is no
cookie integrity problem and the threats of cookie inject clear definition of whether a domain scope is “too wide”
attacks. We intend to provide a context for motivating (See Section 3.2).
further discussion in research community and industry. The combination of the read/write asymmetry and the

2
708  24th USENIX Security Symposium USENIX Association
lack of domain or scheme segregation implies that a do- in its HSTS header, a browser will allow HTTP connec-
main cannot protect the integrity of its cookie from an ac- tion to foo.example.com. Worse, even if the HSTS
tive MITM or a malicious/compromised related domain policy of example.com specifies includeSubDomains,
that shares some cookie domain scope with it. There are this will not be checked by a browser if a user only visits
two forms of cookie integrity violations: bar.example.com unless the page includes a reference
to example.com.
• Cookie Overwriting. If a cookie shares the domain
scope with a related domain, it can be directly over-
written by that domain using another cookie with 2.3 Cookie Injection Attacks
the exactly same name/domain/path. Of particular It is a known vulnerability that cookies can be injected
note, although a secure cookie can only be read by by HTTP response into subsequent HTTPS request, and
an HTTPS process, it can be written or overwritten from one domain to another related domain. Johnston
by an HTTP request. and Moore reported such problem in 2004 [19]. Their
• Cookie Shadowing. Alternatively, an attacker with report already pinpointed the root cause: the loosely
the control of a related domain can intentionally defined SOP for cookies. Unfortunately browsers ven-
shadow a cookie by injecting another one that has dors did not fix the problem probably because they were
the same name, but different domain/path scope. concerned of potential incompatibility issues. In 2008,
For example, to shadow a cookie with “value=good; Evans described an attack called cookie forcing that ex-
domain=www.example.com; path=/; secure”, a ploits cookie integrity deficiency to overwrite cookies in
related domain evil.example.com can write a HTTPS sessions [7]. In 2013, GitHub migrated their do-
cookie with “value=bad; domain=.example.com; main for hosting users’ homepages from github.com to
path=/home”. Later, when browser issues a re- github.io after they recognized the threat of cookie in-
quest to https://www.example.com/home, both jection from/to a shared domain whose subdomains be-
cookies match the URL and are included. For long to mutually untrusted users; they described detailed
most browsers, the cookie header will be “Cookie: steps of several possible cookie injection exploits and re-
value=bad; value=good;”. The “good” cookie could ferred to them as cookie tossing [11].
be shadowed by the “bad” one if a website happens The problem was also noted in several more formal
to prefer the value of “bad” over “good”. publications. Barth et al. discussed security impli-
cations of cookie overwriting on session initiation [4].
Note while the “good” cookie has a secure flag and
They also proposed a new header Cookie-Integrity
is sent over HTTPS, it can still be shadowed with a
to provide additional information so that web server can
cookie set from an HTTP connection.
distinguish between cookies set from HTTP and those
set from HTTPS. Bortz et al. also reviewed the problem
2.2 HSTS and proposed a new header Origin-Cookie that guaran-
HSTS (HTTP Strict Transport Security) allows a server tees integrity by enforcing a complete 3-tuple SOP [5].
to inform a client to only initiate communications over Singh et al. referred the difference between the classic
HTTPS. It was originally proposed by Jackson and SOP and the cookie SOP as inconsistent principal la-
Barth to address a number of MITM threats such as beling [30]. Both Zalewski’s book [32] and the current
cookie sniffing and SSL stripping [18], and is now cookie specification by Barth [2] explained the cookie
standardized in RFC6797 as a HTTP response header integrity deficiencies in great detail. We also learned of
Strict-Transport-Security [15]. two technical reports, one from Black Hat EU by Lun-
The HSTS header requires a max-age attribute deen [23] and the other from Black Hat AD by Lun-
indicating how long a browser should keep the deen et al. [24], that illustrated several subtle attacks ini-
HSTS policy for that domain. An optional attribute tiated by cookie injection.
includeSubDomains tells a browser to apply the HSTS Although a known threat, previous research fall short
policy to its all subdomains. After receiving an HSTS of in-depth empirical assessment of its real-world secu-
header, a conforming browser ensures that all subse- rity implications. This work aims to fill this gap. We
quent connections to that domain always take place over provide a detailed comparison in Section 7.
HTTPS until the policy expires. Chrome and Firefox also
support a preloaded list that contains self-declared web- 3 Threat Analysis
sites supporting HSTS. For more information on HSTS,
please see [22]. We first present the threat model for cookie injection at-
HSTS coverage can often be incomplete. For example, tacks. For each type of attacker, we analyze its real-world
if example.com does not specify includeSubDomains threat. Table 1 gives an overview.

3
USENIX Association 24th USENIX Security Symposium  709
Attacker Root Cause Attack Surface Mitigation
Network Active MITM SOP without protocol & Websites and browsers that allow attackers to reply an unen-
Full HSTS
Attacker Malicious Proxy complete domain isolation. crypted request to a related domain with forged response.
Web Full control of related domain SOP without complete do- Websites using shared domains. Public suffix list
Attacker XSS on related domain main isolation. Websites with compromised related domains. Out of scope

Table 1: Overview of the threats of cookie injection attacks

3.1 Threat Model Domain Ranking


<10 10-102 102 -103 103 -104 104 -105 > 105
Valid HTTPS 7 52 353 2,914 20,548 128,805
Two classes of attackers can manipulate a target site’s Full HSTS 0 1 7 35 212 997
cookies: an active network adversary or a remote adver-
sary able to host or inject content on a related domain. Table 2: Ranking distribution of domains with valid
The active MITM attacker (including the classic HTTPS and full HSTS.
MITM fully controlling the network and the Man-on-the-
Side (i.e., wiretapping and packet-injecting)) can load ar-
bitrary cookies through HTTP into the target’s cookie considered “non-public”) with the includeSubDomains
store. The attacker modifies an unrelated HTTP re- option, which we refer to as full HSTS; 2) the browser
quest to create a hidden iframe in a web page. The at- supports HSTS; and 3) the browser has received the full
tacker’s iframe then creates a series of HTTP fetches to HSTS policy from the base domain of the target domain.
the target domains, which the attacker responds to with Unfortunately, the support and adoption of HSTS in
Set-Cookie headers to poison the victim’s cookie store. the real world is unsatisfactory. First, all current ver-
A malicious proxy is at least as powerful as an active sions of IE, a major browser with considerable mar-
MITM in terms of manipulating network traffic. More- ketshare, do not support HSTS (Microsoft announced
over, because the browser has extra protocol interactions that its new browser will support HSTS [16]). Sec-
with the proxy, potential logic flaws or implementation ond, there is limited adoption of full HSTS among sites.
bugs might give the malicious proxy additional chances We scanned 961,857 base domains from the Alexa top
to break in. Chen et al. highlighted this threat with a one million websites and also examined if these do-
number of logic flaws [6]. Our study also targets this mains present in the Chrome’s preloaded HSTS list [28].
type of issues related to unexpected capabilities for a ma- While we observed 152,679 (15.87%) domains have de-
licious proxy to inject cookies. ployed HTTPS with valid certificates, we only found
Finally, if an attacker controls a related domain di- 1,252 (0.13%) domains have enabled full HSTS. More-
rectly, he may launch cookie injection remotely. The at- over, most of the full HSTS domains are low ranked do-
tacker does not need full control of the related server, just mains (see Table 2). A recent study by Kranch and Bon-
the ability to host JavaScript. This attacker cannot target neau also presented a similar total number of full HSTS
arbitrary domains, but can target any other domain under domains among the Alexa top one million websites [22].
the same “top level” domain. Because of the prevalence of unsafe networks like
One key property of all these adversaries is its ability open wireless networks and the very limited deploy-
to change state. For example, a victim might only visit ment/availability of full HSTS protection, we consider
her bank from known-good networks, but an attacker can cookie injection by active network attackers a pervasive
poison the victim’s browser when the victim is on an and severe threat, especially for websites who have de-
open wireless network. Only later, when the victim has ployed HTTPS to prevent active network attackers from
now returned to the “safe” network and visits her bank, launching other possible attacks such as eavesdropping
does the attack actually affect the victim. or active script injection, yet have not enabled full HSTS.
Web Attack Surface: Generally, a web attacker
3.2 Attack Surface might be able to control a related domain in two ways.
First, for large websites that all subdomains are used in-
Network Attack Surface: The only current protection ternally, an attacker can fully control one subdomain by
against an active network attacker requires that the vic- compromising its DNS resolution or its hosting server.
tim’s browser never issues an unencrypted HTTP con- The attacker can also exploit a XSS vulnerability on a
nection to a target site or any related domain. This con- subdomain of a large website. A cookie injection attack
dition holds if 1) the target domain enables HSTS on its can then be launched to target other subdomains.
base domain 1 (i.e. the first upper-level domain that is A greater concern is when a website either hosts user
1 We learned this term from Kranch and Bonneau’s recent HSTS content or shares a domain scope with other possibly
study [22]. untrustworthy sites. This problem is inherent from the

4
710  24th USENIX Security Symposium USENIX Association
Vendor Domain Publis Suffix List? Vulnerable?
weaker cookie SOP. As we previously discussed in Sec- akamai.net No n/a 1
tion 2.1, a domain is allowed to set cookies with wider Akamai
akamaiedge.net No n/a
domain scope as long as the scope is not considered akamaihd.net No n/a
edgesuite.net No n/a
public. Hence, a clear boundary between “public” and msecnd.net No Yes
Azure
“non-public” domain scope is needed to prevent cookie windows.net No Yes
BitGravity bitgravity.com No n/a
injection from undesired shared cookie domain. How- CacheFly 2 cachefly.net No Yes
ever, this is not easy to define and implement clearly. CDN77 cdn77.net No Yes
CDNetworks cdngc.net No n/a
First, many top-level domains (a.k.a., TLDs), especially CDN.net worldcdn.net No n/a
country code top-level domains (a.k.a., ccTLDs) have ChinaCache chinacache.net No n/a
ChinaNetCenter wscloudcdn.com No n/a
their own reserved suffixes such as .com.cn, .co.uk,
CloudFlare 3 cloudflare.net No Yes
which are mostly TLD-specific. Second, many websites CloudFront cloudfront.net Yes No
use shared domains to assign subdomains to their mu- EdgeCast edgecasecdn.net No n/a
Exceda expresscdn.com No Yes
tually untrusted clients. Such shared domain providers Fastly 3 fastly.net Yes Yes
include cloud hosting providers, web hosting providers, Highwinds hwcdn.net No n/a
Incapsula incapsula.net No Yes
blog providers, CDN providers etc. These shared do- Internap internapcdn.net No n/a
mains should also be considered as non-public in terms Jiasule jiashule.com No Yes
of cookie domain scope. KeyCDN 2 kxcdn.com No Yes
Level3 footprint.net No n/a
The problem of cookie domain scope boundary is Limelight linwd.net No n/a
partially remedied by a community effort initiated by MaxCDN netdna-cdn.com No Yes
Squixa squixa.net No n/a
Mozilla called “public suffix list”, which maintains an 1: “n/a” refers to the case that we were not able to test.
exceptional list containing TLDs, TLD-reserved suffixes, 2: CDNs attempting to defend cookie related attacks on shared do-
mains by filtering the Set-Cookie header.
and self-declared shared domains [25]. Public informa- 3: CDNs allowing shared cookie scopes in customer-specific prefixes
tion suggests that the list is enforced by major browser of shared domains.
vendors including IE, Chrome, Firefox, and Opera, while
Table 3: Assessment of cookie injection attacks on
our own tests confirm that Safari implements this list.
shared domains used by CDNs.
Our study of the public suffix list shows that the
public shared domains list still exposes an attack sur-
face for cookie injection. First, we empirically identi- the injected cookies will be sent with the requests of re-
fied 45 shared domains from the Alexa top one million source files to website B. This type of cookie injection
websites, among which only 10 Google domains and 3 attack could cause performance downgrade, bandwidth
non-Google domains are included in the public suffix consumption, and even denial-of-service (DoS) if the
list. Among the remaining domains, we found at least amount of injected cookies exceeds the server’s header
4 domains (sinaapp.com, weebly.com, myshopify. size limitation2 . In worst case, DoS of a critical resource
com, and forumotion.com) allow customized server- file like a JavaScript library could break the whole web-
side code or browser-side scripts. Websites hosting on site.
these domains are vulnerable to cookie injection attacks. We empirically collected 28 shared domains used
Another easy-to-miss corner case is shared domains by 23 CDNs 3 , in which only 2 domains are reg-
used by CDNs. CDNs commonly assign subdomains istered in the public suffix list, as presented in Ta-
or sub-directories of shared domains to their customers. ble 3. We were also able to sign up and test 13
If a website directly uses a shared domain assigned by shared domains from 12 CDNs. While we confirmed
its CDN provider, and the CDN provider does not han- that cloudfront.net is immune because of its pres-
dle the shared domain carefully, then the website is sub- ence in the public suffix list, for each of the other 12
ject to cookie injection attacks from malicious customers domains, we successfully launched DoS attack on one
of the same CDN provider. While websites rarely use test URL by injecting 72KB cookies from another test
shared domains as their main domains, a common prac- URL. Our experiments also found two problematic be-
tice is to refer static resources (e.g., JavaScript files, im- haviors. First, CacheFly and KeyCDN attempt to de-
ages) using shared domain URLs. Although cookies un- fend cookie related attacks by filtering the Set-Cookie
der these resource URLs are usually not processed by header in response instead of utilizing the public suf-
server-side code or browser-side scripts, cookie injection
attacks could still cause serious consequences. For ex- 2 Although the current HTTP specification does not define any lim-

ample, suppose both websites A and B host their static itation on the size of request header [9], most of web server implemen-
tations do so by default. For example, nginx by default limits a single
resource files under one shared domain from the same HTTP header not to exceed 8KB [26].
CDN. Website A can inject garbage cookies from the 3 We collected most of the CDNs from http://www.cdnplanet.

requests to his resource files with specific paths so that com/cdns/.

5
USENIX Association 24th USENIX Security Symposium  711
fix list, which fails to prevent JavaScript from inject- with the same name, while the name-value map inter-
ing cookies. Second, although Fastly has declared sev- face in Python standard library prefers the last-ordered
eral subdomains of fastly.net as public suffix, its cookie, all others prefers the first-ordered one. This ex-
naming mechanism enables shared scopes in customer- plains why cookie shadowing is possible and the example
specific prefixes, making its customers still vulnerable to given in Section 2.1 works in many cases.
cookie injection attacks. For example, for a customer Cookie Storage Limitation. The specification has
foo.com, Fastly assigns a customer subdomain foo. several vague suggestions for browsers to limit the num-
com.global.prod.fastly.net. Although the suffix ber and size of stored cookies. We found all major
global.prod.fastly.net is present in the public suf- browsers set the maximum size of a single cookie to 4
fix list, the prefix causes a cookie scope com.global. KB. Chrome, Firefox, and Opera implements a cookie jar
prod.fastly.net shared with other customer subdo- for every base domain, with the total numbers of cookies
mains such as bar.com.global.prod.fastly.net. limited to 180, 150, and 180, respectively. IE’s cookie jar
CloudFlare also has the same problem. We have reported implementation is per cookie domain scope, with the to-
this problem to all vulnerable vendors. CloudFlare and tal number of cookies limited to 50. We did not reach Sa-
CDN77 have acknowledged our reports. The response fari’s cookie storage limit after writing and reading 1,000
from CloudFlare said that they are considering to disable cookies.
direct access of all cloudflare.net URLs to defend Cookie Header Size Limit. While Safari does not
against this problem. seem to have a limit for the number of cookies, it trun-
cates the matching cookie list if the length of the cookie
header exceeds 8 KB. We did not observe similar behav-
4 Pitfalls in Cookie Implementations
iors in other browsers.
Based on the threat model and the understanding of po- Cookie Name. The cookie name can contain all
tential attack surfaces, we then turn to understand how US-ASCII values except control characters and sepa-
cookie related mechanisms are implemented in browsers rator characters (see definition in [2] and [8]). We
and web applications. Our study pinpointed a number found that Safari mistakenly stores cookie name in case-
of inconsistent and/or non-conforming behaviors in ma- insensitive manner. Some programming languages also
jor browsers and web frameworks, as summarized in Ta- implement cookie names incorrectly. Previously Lun-
ble 4. We also identified several vulnerabilities in ma- deen et al. reported that ASP.NET implements cookie
jor browsers allowing an active network attacker to inject names case-insensitively [24]. We found that ASP makes
cookies even when the full HSTS is deployed. We have same mistake. In addition, PHP performs percent-
reported these vulnerabilities to browser vendors. decoding on cookie names. For these languages, dif-
ferent cookie names sent by browser are possibly rec-
ognized as same name cookies, which embraces another
4.1 Uncovered Implementation Quirks vector for cookie shadowing. For example, PHP inter-
Browser-side Cookie Ordering. The current cookie prets a cookie header “%76alue=bad; value=good;” as
specification [2] suggests that browsers should rank “value=bad; value=good;”, causing the “good” cookie to
cookies first by path specificity and then by the creation be shadowed by the “bad” one.
time in ascending order. We found all major browsers Cookie Path. According to the specification, a cookie
follow this suggestion except Safari, which ranks cook- matches a URL only when the path scope of the cookie is
ies first by the specificity of the domain attribute then by a sub-directory of (or identical to) the URL path. When
the path specificity. a cookie does not specify the path scope, the browser
Server/script-side Cookie Preference. The cookie is required to set its default path as the directory-portion
header is semantically a list. For the same name cookies of the URL path without any trailing slash. We found 4
in the list, the specification states that the server should violations to the standard: 1) IE and Safari4 implement
not rely upon cookie’s ordering presented by the browser. a sub-string other than sub-directory matching rule; 2)
We examined popular web programming languages, web Firefox matches cookie path with not only the URL path,
frameworks, and third-party libraries including PHP, but also the URL query and the URL fragment portion;
Python, Java, Go, ASP, ASP.NET, JavaScript, Node.js, 3) Firefox matches a cookie path with a URL path when
JQuery, JSF, SpringMVC. At the language level, only the former has one more slash than the later; 4) Chrome,
Java, JavaScript and Go provide built-in or standard li- Safari, and Opera (Linux and iOS versions) include the
brary interfaces to read cookies as a list. Other lan- trailing slash in default cookie path.
guages, and all web frameworks and third-party libraries 4 Also Chrome on iOS, but as iOS browsers need to use Apple’s
treat the cookie list as a name-value map that only returns rendering engine rather than their own, this is probably due to Apple’s
one value for each cookie name in the list. For cookies decision, not Google’s

6
712  24th USENIX Security Symposium USENIX Association
Cookie Property Specification Non-conforming/inconsistent behaviors
Browser-side priority Cookies SHOULD be ranked by specificity of 1. Safari ranks cookies by specificity of domain then by specificity of path.
path then by creation time in ascending order.
Server/script-side preference Server SHOULD NOT rely on cookie’s order- 1. Most standard libs and frameworks only provide name-value map interfaces;
ing presented by browsers. 2. For each name in the cookie list, Python prefers the last-ordered cookie, others
prefer the first-ordered one.
Cookie storage limitation Several vague suggestions 1. Safari seemingly does not have limitation on the number of stored cookies;
2. Chrome and Firefox limit the size of the cookie store per base domain, IE does
so per specific domain scope.
Cookie header size limitation Not specified 1. Safari truncates the cookie header not to exceed 8,192 bytes.
Cookie name US-ASCII values except control characters 1. Safari is case-insensitive with cookie name;
and separator characters (see definition in [2] 2. ASP and ASP.NET are case-insensitive;
and [8]) 3. PHP performs percent-decoding on cookie name.
Cookie path 1. Cookie path and URL path MUST be iden- 1. Firefox matches cookie path not only with URL path, but also with URL query
tical or sub-directory matching; and URL fragment;
2. Trailing slash MUST NOT be included in 2. IE and Safari implement sub-string matching other than sub-directory match-
default cookie path. ing;
3. Firefox allows cookie path has one more slash than the URL path;
4. Chrome, Safari, and Opera under some platforms include trailing slash in the
default cookie path.

Table 4: Summaries of non-conforming and inconsistent behaviors found in browser and web server cookie imple-
mentations.

4.2 Uncovered Vulnerabilities IE


Windows

Mac OS
N/A
Linux
N/A
Android
N/A
iOS
N/A
Chrome     
Vulnerabilities in Handing Proxy Response. In [6], Firefox     N/A

Chen et al. found a number of flaws in major browsers. Safari   N/A N/A 
Opera   N/A  N/A
The root problem resided in the handling of HTTPS re-
: cookie injection with pop-up window.
sponses. Essentially, all browsers at that time could not : cookie injection without pop-up window.
differentiate an HTTPS response from a proxy and an : cookie injection and script injeciton.

HTTPS response from the intended server. The flaws Table 5: Browser vulnerabilities in handling 407 re-
were patched after disclosure. However, we found the sponse by a malicious proxy.
patches are incomplete: if a proxy replies to a HTTPS
CONNECT request with an unencrypted 407 (proxy au-
thentication required) response, all major browsers ex- decoding and upper-to-lower case conversion on its do-
cept IE accept the cookies set in 407 response. While main name before issuing a request. However, the HSTS
some vulnerable browsers display a pop-up window, check is performed before the conversion process com-
some accept cookies silently (Table 5). pletes, enabling an attacker to bypass Safari’s HSTS
These vulnerabilities allow a malicious proxy to check if both capital and percent-encoding are used in
launch cookie injection attacks against a full HSTS site. the domain name.
Users who use proxies or have them set automatically,
these vulnerabilities can also be exploited by an active
MITM between the victim and the proxy, even if a victim 5 Real-World Exploitations
user does not intentionally use the attacker as the proxy.
Vulnerability in Handing Public Suffixes in Safari. Our study aims at understanding the prevalence and
As described in Section 3.2, the public suffix list enforces severity of potential exploitation by cookie injection in
the boundary between public and non-public cookie do- real-world websites. In particular, we are curious about
main scopes. However we found the implementation how web developers use cookies, whether they are aware
of Safari is vulnerable under certain conditions. When of this problem explicitly and have developed best prac-
Safari issues a request http://tld/, it accepts cook- tices accordingly. With these questions in mind, we
ies in the response with domain scope as .tld, which conducted black box penetration tests on a number of
are shared by all subdomains.tld. Because HSTS is popular websites with our test accounts. We also re-
not enabled on an entire TLD (in general, there is no A viewed several well-known open source web applica-
record indicating a server at the TLDs), this vulnerability tions. For penetration tests, we first used browser exten-
is exploitable by active network attackers who can forge sions like EditThisCookie [1] to test manually. For pos-
a DNS response as well as an HTTP response. sible exploitations, we then implemented with Bro [27]
Vulnerability in Safari’s HSTS Implementation. (for packet sniffing and injection with the rst tool) in an
We also found a vulnerability in Safari’s HSTS imple- open wireless network setting.
mentation. When receiving a URL, Safari does percent- We found cookie injection attacks are possible with

7
USENIX Association 24th USENIX Security Symposium  713
very large websites and popular open source applications 5.1.1 Exploiting Google Chat and Search
including Google, Amazon, eBay, Apple, Bank of Amer-
ica, BitBucket, China Construction Bank, China Union- We first present two exploits targeting Google, which
Pay, JD.com, phpMyAdmin, and MediaWiki, among lead our observation of the sub-session hijacking attack.
others. The consequences of attacks include, but are not Google’s base domain google.com is not protected with
limited to, XSS, privacy leakage, bypassing of cross-site full HSTS, so in most cases it is subject to cookie injec-
request forgery (CSRF) defenses, financial loss, and ac- tion by an active network attacker.
count hijacking. The varieties of vulnerable web appli- Case-1: Gmail chat gadget hijacking. The web
cations and exploitations suggest cookie injection is a interface of Gmail at https://mail.google.com/
serious threat in the real world, and deserves a greater shows a chat gadget at the bottom left corner. If an at-
attention from the web security community. tacker hijacks the gadget without affecting Gmail and
The exploitations we found indicate three common other Google services, he can fake the victim’s friend list
cookie usages: 1) using cookies as authentication tokens; and chat with the victim to initiate advanced phishing,
2) associating important and session independent states intercept communication, or perform other disruptive ac-
with cookies; 3) reflecting cookies into HTML. These tivity. This could be particularly deceptive in a targeted
cookie usages often lead to cookie injection attacks if attack scenario.
specific defensive measures are not in place. We have confirmed this attack. Although the browser
We present our exploitations based on these cate- displays everything as one page, the chat gadget and
gories, along with the necessary background and addi- Gmail content are actually loaded with different URLs
tional observations. Please refer Section 4 and Table 4 then composed together. Both the chat gadget and Gmail
for the details of different cookie implementations in- use cookies for authentication. If an attacker injects his
volved in some cases. We extensively make use of cookie Google session cookies in a way that the injected cookies
shadowing. For these cases, unless otherwise specified, shadow the original ones only at the chat gadget related
we assume that the web server has the common behav- URLs, then the attacker can put his chat gadget on the
ior of preferring the first-ordered cookie for each name victim’s screen, without disturbing the victim’s use of
in the cookie list. Gmail and other Google services.
We demonstrated this attack by injecting a total of 25
cookies: five session cookies “SID/SSID/HSID/APISID/
5.1 Cookies as Authentication Tokens SAPISID”, each with five specific paths. Meanwhile
A common practice in web development is to use a most Google services are not affected because the spe-
cookie to identify a user session. Many websites fur- cific paths of the injected cookies do not match with their
ther set long expiration durations on session cookies to URL paths. This is sufficient to cause the chat window
avoid having users sign in every time. This practice itself to load with the attacker’s cookies, while all other com-
is somewhat questionable, because session cookies are ponents are loaded as the victim.
sent along with HTTP requests automatically, which fa- Case-2: “Invisible” Google search history steal-
cilitate CSRF attacks. Nevertheless, Barth et al. showed ing. Another attack is to use cookie shadowing to steal
that CSRF attacks can be defeated with specific defen- Google search history (which is automatically logged
sive principles and techniques in web applications [4]. and retrievable with the login cookie) without being no-
Also in [4], Barth et al. noted a special form of CSRF ticed. We assume that a user has visited https://
which they called login CSRF. In this attack, an attacker www.google.com/, which shows the search box and her
signs in with his own account on the victim’s browser. profile name and icon. When she types in the search
If not noticed, the victim might visit targeted web site box, browser-side script issues AJAX requests to https:
on behalf of the attacker’s account, resulting in security //www.google.com/search to get search results.
and privacy consequences such as search history leakage, Our original goal was to only shadow the session
credit card stealing, and XSS. The authors also pointed cookies of the AJAX request, so that we could steal
out that login CSRF is a special form of a threat they search history without affecting the web interface loaded
called Authenticated-as-Attacker, which can also be car- by https://www.google.com/. But it turned out we
ried out by injecting malicious session cookies to over- could not achieve this. We first injected three relevant
write original ones. session cookies “SID/SSID/HSID” with path “/search”.
In fact, the consequences of cookie injection on ses- However, this attempt failed because we found the server
sion cookies can go beyond those described in [4]. We unusually preferred the last-ordered cookie, and the in-
found that, by using cookie shadowing, similar attacks jected cookies were ranked before the legitimate ones
could be carried out without noticeable evidences by the because of the specific path. We then found out a way
victim. We call our attacks sub-session hijacking attacks. to only shadow the session cookies of the AJAX re-

8
714  24th USENIX Security Symposium USENIX Association
quest on Safari by exploiting its cookie header limita- which may be noticed by the victim. However, if the at-
tion (see Case-5 in Section 5.1.5 for the details). How- tacker can only hijack an AJAX request which is not re-
ever, the server seemed to check whether session cook- lated to the interface, especially ID-indicators, the attack
ies under https://www.google.com/search are con- could be launched invisibly.
sistent with those under https://www.google.com/. Second, explicit and session dependent verifiers could
Once receiving inconsistent session cookies from the bind separate URLs together, so that the attacker needs
AJAX request, it navigated the web interface to https: to hijack more URLs. One example is using a session
//www.google.com/search, which still showed the at- dependent nonce to counter CSRF attacks. Suppose the
tacker’s profile name and icon. attacker wants to steal some sensitive information sub-
Our final attack was to inject session cookies with do- mitted by a form which is fetched from URL GetForm
main scope “www.google.com” and path “/”, so that for then submitted through URL SubmitForm. If the CSRF
non-Safari browsers, the attacker could steal the victim’s protection of the form is session dependent, e.g. a nonce
search history. Although this attack affects the web in- associated with user session embedded in the form and
terface, causing to show the attacker’s profile name and verified when submitting, the attacker must hijack both
icon, it does not affect most other Google services. We GetForm and SubmitForm so that the CSRF verifica-
also verified an invisible attack by spoofing the victim’s tion does not fail. Otherwise he only needs to hijack
profile name and icon. SubmitForm.
It turns out that sub-session hijacking can be a pow-
5.1.2 Sub-session Hijacking Attacks erful attack against today’s websites. Because many
web applications do not adopt mechanisms to bind sub-
The two cases above show a common pattern: the at- sessions together, and, for many operations, hijacking
tacker intends to limit the effective scope of injected ses- one sub-session is sufficient to cause serious conse-
sion cookies as small as possible to reduce the visibility quences. Below we describe three common functional-
of his attack. ities that are often vulnerable to sub-session hijacking,
Essentially, web applications require one or more demonstrated with real-world cases.
request-reply pairs with different URLs, which we view
as different sub-sessions. In a normal case, when a user
views a web page or performs a certain action through 5.1.3 Payment Account Stealing
a series of pages, the corresponding sub-sessions carry-
Many websites require users to associate one or more
ing the same user authentication tokens are attributed to
payment accounts to pay their bills or online purchases.
the user’s account. However, when using cookies as au-
If the attacker hijacks the payment account submission
thentication tokens, the cookie-URL matching rules and
form, he could get sensitive information, or even spend
implementations often allow the attacker to selectively
money using the victim’s payment account.
associate one or more sub-sessions to the attacker’s ac-
Case-3: Credit card stealing on China UnionPay.
count by cookie shadowing. That is why we call this type
China UnionPay, a government-owned financial corpo-
of attack sub-session hijacking attacks.
ration in China, has an online third-party payment ser-
The impact of such attacks varies by the applications.
vice in which users can add their credit/debit cards. Al-
In general, the attacker’s strategy is to select a minimum
though the process of adding a card involves four URLs
set of sub-sessions that achieve his attack goals mean-
as well as authentication via text message, all the URLs
while keep the visibility of the attack as small as pos-
merely use one session cookie “uc s key” for authentica-
sible. However such attack could be made difficult by
tion and the actual data submission is performed at one
some implementation choices.
URL that is not related to any ID-indicator. We have
First, in general, a victim could notice a sub-session
verified that by shadowing the session cookie at the sub-
hijacking attack if she views abnormal changes of some
mission URL, the attacker can hijack China UnionPay’s
visual elements on her screen. Typically such elements
credit card association invisibly to obtain the victim’s
include username, email, a profile icon etc., which we
(obfuscated) credit card number and its spending history
refer to as ID-indicators. If a website uses less URLs in
when the victim uses this interface in the future.
one page or one certain functionality, and makes the im-
portant URLs related with the ID-indicators, the attacker
is less likely to perform sub-session hijacking without 5.1.4 Online Deposit Hijacking
being noticed. For example, in Case-2, the attacker has
to hijack both of the URL that shows the search interface, A common feature in many Chinese websites is the abil-
and the AJAX request that performs the search. This lim- ity to deposit money from an online bank (or a third-party
itation causes the expose of his profile name and icon, payment service like Alipay) into a website for future

9
USENIX Association 24th USENIX Security Symposium  715
spending. We found this feature is particularly vulnera- and BitBucket. BitBucket, a popular code hosting
ble to sub-session hijacking. service, provides account association with Google by
The process of online deposit usually includes six OAuth. If a user is already logged in with Google
steps: 1) the user enters deposit amount; 2) the website and has authorized BitBucket to access her Google pro-
generates an ID as a unique identifier of this transaction; file through OAuth, the association is accomplished
3) the website redirects the user to the selected online with two forth-and-back redirections with https://
bank with the transaction ID; 4) the user authenticates accounts.google.com/o/oauth2/auth without con-
and confirms to withdraw money from the online bank; firmation except a final message saying “You’ve success-
5) the online bank notifies the website with the transac- fully connected your Google account”.
tion ID and redirects the user back to the website; 6) the Our goal is to hijack the Google OAuth URL to in-
website receives the notification from the online bank, visibly cause an association violation. There are 5 rel-
and adds the corresponding amount on the user’s account evant session cookies: “SID/SSID/HSID” with domain
according to the transaction ID. The bank site only shows scope “.google.com” and path “/”, and “LSID/LSOSID”
the transaction ID on its interface which is usually an un- with domain scope “.accounts.google.com” and path “/”.
meaningful string. If the attacker can hijack the step 2 to This is challenging because the server seemingly has
associate the transaction ID with his account without be- deployed specific defense to counter cookie injection.
ing noticed, the victim user is likely to finish all steps on First, accounts.google.com has enabled HSTS with
the online bank because there is no abnormal visual indi- includeSubDomains. Second, if we inject cookies with
cation. Once the victim does so, the money is deposited the same names, the server redirects us to a “CookieMis-
to the attacker’s account. match” warning page.
Case-4: Deposit hijacking on JD.com. JD.com is a We successfully launch the attack on Safari by tak-
popular E-commerce website in China. In its implemen- ing advantage of Safari’s quirks. First, we exploit the
tation of the online deposit feature, the second step uses HSTS implementation bug (Section 4.2) to inject the at-
an AJAX request that is not related to any ID-indicator. tacker’s five session cookies with domain scope “.ac-
We have verified that by shadowing JD.com’s session counts.google.com” and path “/o/oauth2/”. Recall that
cookie “ceshi3.com” at the AJAX request, the attacker can Safari ranks cookies by domain specificness then by path
hijack the online deposit invisibly, redirecting funds from specificness, therefore the injected cookies shadows the
the victim into the attacker’s jd.com account. legitimate ones. Then, we make use of Safari’s 8 KB
limitation on the cookie header (see Section 4.1) to get
around the same name cookie detection. To achieve
5.1.5 Account Hijacking in SSO Association
this, we inject a number of cookies with specific names
Single Sign On (SSO) is a technique where an Identity and domain/path scopes, so that they are ranked be-
Provider (IdP) provides authentication assertions for a tween the injected session cookies and the legitimated
logged-in user to relying parties (RP) for them to authen- session cookies. We control the length of these cookies
ticate the user. SSO usually enables automatic login on to “overflow” the cookie list so that Safari truncates the
the relying party, providing a better user experience and legitimated session cookies when issuing requests to the
in some cases better security. This is a popular technique OAuth URL. This allows us to bypassed all restrictions.
deployed by a number of large websites such as Google
and Facebook as IdPs, and many other web sites as rely- 5.2 Cookies as References to Session Inde-
ing parties. Popular web protocols used for SSO imple-
pendent States
mentation include OpenID [10] and OAuth [14].
Under certain conditions, SSO systems face a threat Session fixation is a well-known attack in which an at-
called association violation [31], in which a victim ac- tacker holds a session ID, then persuades a victim to au-
count on an RP is associated with an attacker’s account thenticate with that ID so that he gains control of the
on an IdP, so that the attacker gains control of the vic- victim’s account [21]. Cookie injection can be used to
tim’s account on the RP. This is likely to happen when 1) exploit vulnerable websites that use cookies to store ses-
the victim is logged-in in the IdP as the attacker, 2) the sion IDs. Standard defenses, e.g. regenerating session ID
RP has a feature for its users to associate with their ac- after login, have been widely adopted.
counts on the IdP, 3) the feature is implemented through However, we found that, although some websites have
redirections without further confirmation. The first con- implemented defenses for typical session fixation at-
dition can be mounted by cookie injection, and the web- tacks, they still have similar vulnerabilities for cookie
sites satisfying the latter two conditions are not hard to injection. The root cause is that they associate impor-
find. tant server-side states with long-term cookies. More-
Case-5: Account hijacking against Google OAuth over, they do not bind these states with user sessions.

10
716  24th USENIX Security Symposium USENIX Association
The attacker can fixate such cookies by cookie injec- track all purchases of the victim. To do so, he first
tion (e.g., through cookie overwriting) in order to access creates an on-going purchase, of which the internal
and manipulate the associated states. Interestingly, most data structure is also shared with the victim. Later,
of the vulnerable websites we found vulnerable are E- when the victim makes a purchase, the information
commerce websites. is updated to the shared data structure, consequently
Case-6: Shopping cart tracking/manipulation on retrieved by the attacker. On Amazon China, the at-
popular E-commerce websites. We demonstrate this tacker can see all information of the victim’s pur-
type of issues on 3 popular E-commerce websites: chase including items, amount, the victim’s name,
Apple, eBay, and JD.com. These websites allow unreg- delivery address, and cellphone number. On Ama-
istered visitors to add items in shopping carts. For better zon U.S., the delivery address and cellphone num-
user experience, they never expire the shopping carts ber are not visible by the attacker.
on the server side, and use long-term cookies on the
browser side as references. We have verified that if the • Potential hijacking of purchases. When detecting
attacker fixates the corresponding cookies using cookie an ongoing purchase by the victim, the attacker can
injection, he can track or manipulate shopping carts of change the delivery address so that the purchase is
the unregistered visitors. paid by the victim but sent to the attacker. If the
victim confirms the hijacked purchase, she cannot
We also found similar problems on Amazon, which even see where the purchase is hijacked to in her
are much more serious in terms of the real-world order history, because Amazon only shows “Gift-
consequences, because they compromise security for ing address”. The attacker can even manipulate the
registered users.5 purchase in such a way that it is paid by the vic-
Case-7: Browsing history and purchase track- tim, delivered to the attacker, and only recorded in
ing/hijacking on Amazon. Amazon’s E-commerce the attacker’s order history. The only limitation of
websites use two long-term cookies “session-id” and the attack is that if the delivery address is new to
“ubid-main” to associate with a user’s browsing history the payment option, Amazon requires the victim to
and the ongoing purchase. Surprisingly, these important confirm the card number, however the interface is
states are not associated with the user session (Not as its arguably not alarming. On Amazon China, this lim-
name suggests, “session-id” is not used for user authen- itation does not apply if the victim chooses to pay
tication). Once the attacker fixates the two cookies, he with a third-party service like Alipay.
can launch various attacks remotely.
The first exploitation is to track and manipulate the 5.3 Cookies reflected into HTML
user’s browsing history. Amazon keeps all previous
viewed items in a user’s browsing history. Upon fixat- Another common practice is to store auxiliary variables
ing the two referencing cookies, the attacker can track like preferred language or username as cookies, and re-
what the victim have viewed on Amazon in real-time. He flect these cookies into HTML or script snippets. If not
can also inject unwanted items into the browsing history, implemented carefully, this practice could make websites
which affects the recommendation system. vulnerable to various attacks in face of cookie injection.
Moreover, from what we observed, we infer that Ama-
zon keeps a session independent data structure for an
5.3.1 XSS via Cookie Injection
on-going purchase, which stores the user, the purchased
items, the total amount, the delivery address, and other A direct threat is XSS: if reflected cookies are not
payment information. The structure is likely created by sanitized sufficiently, the attacker can embed malicious
clicking the “proceed to checkout” button, and released scripts in reflected cookies to launch XSS attacks through
after clicking of the “place your order” button. This cookie injection.
structure is associated with the same two cookies refer- Case-8: XSS via cookie injection on China Con-
encing the browsing history. By fixating the two cookies struction Bank, Amazon Cloud Drive, eBay and oth-
and consequently gaining access of the data structure, the ers. We found a number of websites do not validate re-
attacker has various ways to manipulate the victim’s pur- flected cookies sufficiently. Using cookie injection, we
chase remotely. Below we describe two exploitations: successfully mounted XSS against China Construction
Bank, Amazon Cloud Drive, eBay and several other web-
• Tracking of all purchases. First, the attacker can sites.
5 However, we note that many E-commerce sites, including Ama- Case-9: Insufficient cookie validation on Bank of
zon, use mixed content, and thus are also vulnerable to attackers inject- America. Among the XSS vulnerabilities we found, the
ing scripts into the insecure domain that remain in the browser cache. one on the Bank of America website is fairly unique. We

11
USENIX Association 24th USENIX Security Symposium  717
found that one cookie with path “/” on Bank of Amer- the second condition. If a webpage contains a reflected
ica’s website could be exploited to inject XSS. At first, cookie, the attacker can abuse it with cookie injection
our naı̈ve exploitation by overwriting the cookie with a as the first vector to launch the BREACH attack to infer
XSS payload failed. The limitation was that the website secrets in this webpage.
performed a strict validation on the cookie at the login Case-10: BREACH attacks on phpMyAdmin and
URL. Only if the cookie was absent would the website MediaWiki. We found phpMyAdmin, a popular open
set a clean value on the cookie from the response of the source web application for remote database manage-
login URL, then used it in subsequent requests without ment, reflects a cookie for language preference after
validation. Our naı̈ve exploitation was prevented by the sanitization in error page if its value is invalid. The
strict validation at the login URL. BREACH attack using this cookie can reliably infer the
We found a technique to bypass the limitation, so that CSRF token in the error page, enabling further CSRF at-
the XSS payload can be buried into the victim’s browser tacks. Similarly, MediaWiki reflects a cookie into its lo-
and triggered when next time the victim logs in by in- gin form, also allowing the BREACH attack to infer the
jecting multiple cookies. We injected two cookies. The CSRF token in the login page.
first one had the same 3-tuple identifier as the legitimate
one, but with an expired time to ensure the legitimate 5.4 Summary
cookie was discarded and absent at the login URL. The
second injected cookie contained the XSS payload and These exploitations show that cookie injection enables
had a different cookie path “/myaccount” that matched undesired and complicated interactions among cookie
with the first URL after login. Although the server set a implementations, web applications, and various known
clean cookie in the response of the login URL, the spe- threats. It is clear that our empirical assessment only
cific path of the second injected cookie not only avoid touches a part of the whole problem space. Neverthe-
being overwritten by the clean cookie, but also shadowed less, we believe these cases demonstrate that the security
the clean cookie in subsequent requests, triggering a suc- implications of cookie’s lack of integrity are not well and
cessful XSS attack. widely understood by the community, and current cookie
This case implies a possible misconception that per- practices have widespread problems when cookie injec-
forming a complete cookie validation on one “entry tion is taken into consideration.
point” is sufficient. In fact, because of the asymmetry Report and Response. We have reported all vulner-
between cookie read and write operations, every different abilities to the affected websites. Some have acknowl-
URL might bring different and unexpected cookie values edged (e.g., Amazon), and some (e.g., Bank of America)
no matter how server set cookies in previous responses. have fixed the issues.
Developers must treat every request as a new entry point
and carefully validate all associated cookies. 6 Possible Defenses

5.3.2 BREACH Attacks through Cookie Injection Some existing techniques can help mitigate this threat,
including full HSTS, public suffix list, defensive cookie
In 2002, Kelsey observed that when combining encryp- practices, and anomaly detection.
tion with some compression algorithms, the size of com- Full HSTS and Public Suffix List. We strongly
pressed data can be used as a side channel, potentially recommend that websites deploy full HSTS to prevent
causing plaintext leakage under certain conditions [20]. cookie injection from active network attackers, as this
Rizzo and Duong found a real-world case in 2012, named provides complete protection once a site is pinned by a
as CRIME attack, in which an active network attacker user visit. The community should also make the effort to
initiates encrypted HTTP requests from a victim browser raise the awareness of cookie injection attacks, and clar-
with different URLs as partially-chosen plaintexts, then ify the different levels of security provided by HTTPS,
infer embedded secrets like session cookies by observing HSTS, and full HSTS. For websites that host shared do-
the sizes of the compressed and encrypted requests [29]. mains, the best practice is to use separate domains and
Rizzo and Duong also mentioned that a similar attack register them on the public suffix list. Efforts also should
could also be mounted to infer secrets in encrypted be made to increase the awareness of cookie injection
HTTP responses. This was explored and demonstrated from shared domains and the public suffix list.
by Gluck et al., named as the BREACH attack [12]. Defensive Cookie Practices. For websites that can-
BREACH requires the attacker to be able to 1) inject a not enable full HSTS, and have concerns about cookie
partially-chosen plaintext into the HTTP response of one injection from related domains, defensive cookie prac-
webpage, and 2) measure the size of the compressed then tices may mitigate certain cookie injection threats. For
encrypted response. An active network attacker satisfies example, frequently invalidating session cookies could

12
718  24th USENIX Security Symposium USENIX Association
reduce the risk of sub-session hijacking. Instead of using 2. Cookies with the secure flag MUST be given
cookies, Websites can also use new features in HTML5 higher priority over non-secure cookies.
like localStorage and sessionStorage to facilitate 3. A browser MUST only send the highest priority
browser-side state management, which does not have cookie for any cookie name.
cookie’s integrity deficiencies, although these mecha-
nisms are less convenient for cross-protocol and cross- 4. In removing cookies due to a too-full cookie store,
domain state sharing. the browser MUST NOT remove a secure cookie
Anomaly Detection. Websites should consider de- when there are non-secure cookies that can be re-
tecting same name cookies in the cookie header, as we moved.
discussed in the accounts.google.com case. This is 5. The browser MUST allow an HTTP connection
reasonable because same name cookies should not be to clear a secure cookie by setting an already-
considered a legitimate use according to both the spec- expired expiration date, but the browser MUST
ification and the inconsistent implementations. This de- NOT remove the cookie from the store. Instead,
tection would protect non-Safari users from attacks using the browser MUST set the “do not send” flag and
cookie shadowing. maintain the original expiration date.
6. The browser MUST NOT send a cookie with the
6.1 Proposed Browser Enhancements “do not send” flag, nor send any non-secure cookie
with the same name.
We propose several browser-side enhancements to mit-
igate cookie injection attacks. Our proposals do not re- The first rule prevents an active network attacker from
quire any server-side change, so they would benefit many injecting or replacing secure cookies. The second and
legacy websites. third rules combined prevent an active network attacker
from shadowing a secure cookie. The fourth rule pre-
6.1.1 Mitigating Active Network Attackers vents an attacker from flooding the cookie store to evict
secure cookies. The fifth and sixth rules are subtle but
Currently, Chrome, Firefox and Safari, but not Internet necessary: mixed-content sites might have a “logout”
Explorer, have deployed the HSTS support. We believe button in HTTP which clears secure session cookies.
that if all major browsers could deploy it, websites with We wish to enable this functionality without allowing at-
full HSTS would be capable of defending against ac- tackers to remove and replace a secure cookie.
tive network attackers in most cases. However, deploy- Taken together, our proposals should add HSTS-like
ing full HSTS needs all subdomains to support HTTPS pinning to secure cookies within the existing cookie
with valid certificates. There are a number of practical store. If a cookie was set with secure flag, an active
hurdles for websites to satisfy such a strict requirement. network attacker can only delete it, which largely miti-
For example, Google cannot enable full HSTS, because gates cookie injection attacks 6 .
it is required to support non-HTTPS access for manda- Compatibility. We implemented the first three rules
tory adult-content filtering at school and some other lo- as a Chrome extension7 , and used the extension to
cations [13]. Kranch and Bonneau also reported the cur- manually examined the Alexa top 40 websites. We
rent incapability of Facebook and Twitter to deploy full found one broken case: the signing out operation on
HSTS [22]. Hence, we believe full HSTS is not likely to http://www.bing.com/ results in a request-reply with
be adopted widely in the near future. http://login.live.com/logout.srf which expires
To protect a site which cannot deploy full HSTS, a several secure session cookies under its SSO IdP do-
browser must not allow an HTTP connection to replace main live.com. Allowing HTTP to clear secure cook-
or shadow secure cookies, effectively adding an HSTS- ies should improve compatibility with such signing-out
like pin for any secure cookie. We propose to modify the practice.
semantics of the existing cookie store by adding a “do We also crawled the Alexa top 100,000 domains with
not send” flag and changing the cookie store behavior both HTTP and HTTPS. In total, 48,039 domains re-
with the following semantics. We believe these semantic sponded with cookies. 152 (0.32%) domains returned
change should provide protections while minimizing the secure cookies over HTTP; 570 (1.19%) domains re-
disruption to existing sites: sponded with cookies that have same name yet different
6 The non-conforming cookie name behaviors of PHP, ASP, and
1. A browser MUST NOT accept a cookie presented
ASP.NET described in Section 4.1 still expose some possibilities for
in an HTTP response with the secure flag set, nor cookie shadowing. We suggest vendors to fix these incorrect imple-
overwrite an unexpired secure cookie, except the mentations.
case in 5. 7 https://github.com/seccookie/ExtSecureCookie

13
USENIX Association 24th USENIX Security Symposium  719
domains and/or paths. These numbers suggest secure of integrity, its root cause, and its security implications.
cookies over HTTP (incompatible with the first rule) and However, prior understanding of the subtlety, prevalence,
same name cookies (related to the second and third rules) and severity of this problem in the real world is limited.
are rare in real-world websites. We manually examined We take a much closer look at the problem space, pro-
10 domains in each case with our extension and did not vide a number of new empirical assessments which we
observe evidence of broken behaviors. believe will help the community understand the problem
While the results from our compatibility testing are more deeply and know the status quo better. Specifically,
promising, we acknowledge they are preliminary. First, we conduct a detailed measurement of full HSTS adop-
we may have missed subtle incompatibility issues in our tion and reveal the threat to CDN customers. Prior to our
manual testing. Second, some incompatibility behaviors work, Kranch and Bonneau recently studied full HSTS
may only occur with logged-in sessions and/or specific deployment practice but within a different context [22].
paths, which our testing may have failed to uncover. We The cookie related problems revealed in our assessment
hope our limited experiments will motivate browser ven- of browser and server libraries are largely unknown, ex-
dors to conduct large-scale in-depth compatibility evalu- cept a few fragmented knowledge from Lundeen’s [23]
ation. and Lundeen et al. ’s work [24]. The attack cases we
present also supplement previous discussion on poten-
6.1.2 Mitigating Web attackers tial exploitations in both breadth and depth. Our close-
up study also leads us to find promising cookie isolation
A domain can set cookies with a more specific domain enhancements that only require browser-side adoption.
scope (e.g. host-only) to prevent cookie stealing by XSS In contrast, the previous proposed defenses need both
from sibling domains. But this currently has no effect browser- and server-side changes [4, 5].
on cookie injection since injected cookies with shared Broadly, our work can be viewed as an in-depth case
domain scopes yet longer paths are effective for cookie study of inconsistent access control policies in web.
shadowing, and longer paths are available in most cases Jackson and Barth’s [17] and Singh et al. ’s work [30]
if an adversary is in control of a related domain. Combin- explored this general problem, and each provided vari-
ing the second rule of the above proposals, we suggest: ous instances. One example illustrated by Jackson and
Barth is the ability of JavaScript to read all cookies with
7. When issuing a request, the browser MUST rank the matching domain scopes regardless of their paths [17].
cookie list by a) presence of the secure flag, and b) This behavior has now been noted explicitly in the cur-
specificity of the domain scope. rent specification [2].
Security Related Cookie Measurement. Zhou and
Together with the third rule presented above, this Evans studied the rare deployment of the HTTPOnly
should enable developers to prevent cookies from being cookies at the time [33]. They believed that the require-
overwritten or shadowed by using specific domain scope ment of both client and server changes played an impor-
(together with the secure flag when using HTTPS). We tant hurdle in its adoption. Kranch and Bonneau found
have also implemented this policy in the same Chrome many websites deploy HSTS yet do not marked their
extension mentioned above. cookies with the secure flag, which are vulnerable to
cookie theft in certain conditions [22]. These two mea-
surements were concerned with cookie’s confidentiality,
7 Related Work
while our work looks at the other property, i.e. cookie’s
Comparison to Previous Work. We are aware of sev- integrity. Singh et al. measured the real-world usages
eral research papers that are directly related to cookie’s of secure cookies (0.07%, 62 out of 89,222 sites) over
weak SOP and integrity problem [4, 30, 24, 23, 5, 2, HTTP and same name cookies (they called duplicate
32], and some other papers that are comparable to our cookies) (5.48%, 4,893 out of 89,222 sites) [30]. Our
work [17, 22]. Among the directly related research, assessment obtains similar results.
Barth’s [2] and Zalewski’s work [32] focused on explain-
ing the cause of the cookie integrity problem. Most pre- 8 Conclusions
vious research only briefly touched cookie integrity as
a relevant subproblem rather than main topic [4, 30, 24, Cookies lack integrity. Although long known in commu-
23]. Bortz et al. ’s research is close to ours. Especially, nity lore, the community has under-appreciated the im-
they introduced the notion of a related domain attacker plications. We have attempted to systematically evaluate
which we use throughout this paper. However, their work the implications of cookie integrity, including evaluating
is limited to high-level discussion [5]. In summary, pre- weaknesses and evaluation artifacts in both browser and
vious research has discussed the problem of cookie’s lack server libraries, building real-world attacks against ma-

14
720  24th USENIX Security Symposium USENIX Association
jor sites including Google and Bank of America, includ- [12] G LUCK , Y., H ARRIS , N., AND P RADO , A. BREACH: Re-
ing subtle account-hijack attacks and XSS attacks buried viving the CRIME Attack. http://breachattack.com/
resources/BREACH%20-%20SSL,%20gone%20in%2030%
in injected cookies, and developing an alternate browser 20seconds.pdf, 2013. [accessed Feb-2015].
cookie policy that mitigates the threat from network-
[13] G OOGLE S UPPORT. Block Adult Content at Your School.
level attackers. We expect our work to raise the aware- https://support.google.com/websearch/answer/
ness of the problem, and to provide a context for further 186669?hl=en. [accessed Feb-2015].
discussion among researchers, developers and vendors. [14] H ARDT, D. The OAuth 2.0 Authorization Framework. IETF
RFC 6749 (2012).
[15] H ODGES , J., JACKSON , C., AND BARTH , A. Http Strict Trans-
Acknowledgements port Security (HSTS). IETF RFC 6797 (2012).
[16] IEB LOG. Project Spartan and the Windows 10 January Preview
We would like to thank our shepherd Hovav Shacham, Build. http://blogs.msdn.com/b/ie/archive/2015/01/
and the anonymous reviewers for their insightful com- 22/project-spartan-and-the-windows-10-january-
preview-build.aspx. [accessed Feb-2015].
ments. We are grateful to Vern Paxson, Frank Li and
David Fifield for valuable discussion, and Jianjun Chen [17] JACKSON , C., AND BARTH , A. Beware of Finer-Grained Ori-
gins. Proceedings of 2th W2SP (2008).
for help of some exploitations. We also thank Chris
Evans, Joel Weinberger, Chris Palmer, and Nick Sulli- [18] JACKSON , C., AND BARTH , A. ForceHTTPS: Protecting High-
Security Web Sites from Network Attacks. In Proceedings of the
van for valuable feedback. This work is partially sup- 17th WWW (2008), ACM, pp. 525–534.
ported by the National Natural Science Foundation of [19] J OHNSTON , P., AND M OORE , R. Multiple Browser Cookie
China (Grant No. 61472215), Tsinghua National Labo- Injection Vulnerabilities. http://www.westpoint.ltd.uk/
ratory for Information Science and Technology (TNList) advisories/wp-04-0001.txt, 2004. [accessed Feb-2015].
Academic Exchange Foundation, and the Natinoal Sci- [20] K ELSEY, J. Compression and Information Leakage of Plaintext.
ence Foundation (CNS-1213157 and CNS-1237265). In Fast Software Encryption (2002), Springer, pp. 263–276.
[21] KOL ŠEK , M. Session Fixation Vulnerability in Web-based
Applications. http://www.acros.si/papers/session_
References fixation.pdf, 2002. [accessed Feb-2015].
[22] K RANCH , M., AND B ONNEAU , J. Upgrading HTTPS in mid-air:
[1] Edit This Cookie. http://www.editthiscookie.com/. [ac-
An empirical study of strict transport security and key pinning. In
cessed Feb-2015].
Proceedings of the 22th NDSS (2015).
[2] BARTH , A. HTTP State Management Mechanism. IETF RFC [23] L UNDEEN , R. The Deputies Are still Confused. Blackhat EU
6265 (2011). (2013).
[3] BARTH , A. The Web Origin Concept. IETF RFC 6454 (2011). [24] L UNDEEN , R., O U , J., AND R HODES , T. New Ways Im Going
[4] BARTH , A., JACKSON , C., AND M ITCHELL , J. C. Robust De- to Hack Your Web App. Blackhat AD (2011).
fenses for Cross-Site Request Forgery. In Proceedings of the 15th [25] M OZZILA. Public Suffix List. https://publicsuffix.org/.
CCS (2008), ACM, pp. 75–88. [accessed Feb-2015].
[5] B ORTZ , A., BARTH , A., AND C ZESKIS , A. Origin Cookies: [26] N GINX. Module ngx http core module. http://nginx.org/
Session Integrity for Web Applications. Web 2.0 Security and en/docs/http/ngx_http_core_module.html#large_
Privacy (W2SP) (2011). client_header_buffers. [accessed Jun-2015].
[6] C HEN , S., M AO , Z., WANG , Y.-M., AND Z HANG , M. Pretty- [27] PAXSON , V. Bro: A System for Detecting Network Intruders in
Bad-Proxy: An Overlooked Adversary in Browsers’ HTTPS De- Real-Time. Computer networks 31, 23 (1999), 2435–2463.
ployments. In Proceedings of the 30th IEEE S&P (Oakland) [28] P ROJECTS , T. C. HTTP Strict Transport Security. http://www.
(2009), IEEE, pp. 347–359. chromium.org/hsts. [accessed Feb-2015].
[7] E VANS , C. Cookie Forcing. http://scarybeastsecurity. [29] R IZZO , J., AND D UONG , T. The CRIME Attack. In EKOparty
blogspot.com/2008/11/cookie-forcing.html, 2008. [ac- Security Conference (2012), vol. 2012.
cessed Feb-2015].
[30] S INGH , K., M OSHCHUK , A., WANG , H. J., AND L EE , W.
[8] F IELDING , R., G ETTYS , J., M OGUL , J., F RYSTYK , H., M AS - On the Incoherencies in Web Browser Access Control Policies.
INTER , L., L EACH , P., AND B ERNERS -L EE , T. Hypertext In Proceedings of the 31th IEEE S&P (Oakland) (2010), IEEE,
Transfer Protocol–HTTP/1.1. IETF RFC 2616 (1999). pp. 463–478.

[9] F IELDING , R., AND R ESCHKE , J. Hypertext Transfer Proto- [31] WANG , R., Z HOU , Y., C HEN , S., Q ADEER , S., E VANS , D.,
col (HTTP/1.1): Message Syntax and Routing. IETF RFC 7230 AND G UREVICH , Y. Explicating SDKs: Uncovering Assump-
(2014). tions Underlying Secure Authentication and Authorization. In
USENIX Security (2013), pp. 399–314.
[10] F OUNDATION , O. OpenID Authentication 2.0 - Final.
http://openid.net/specs/openid-authentication- [32] Z ALEWSKI , M. The Tangled Web: A Guide to Securing Modern
2_0.html. [accessed Feb-2015]. Web Applications. No Starch Press, 2012.
[33] Z HOU , Y., AND E VANS , D. Why Arent HTTP-only Cookies
[11] G IT H UB. Yummy Cookies across Domains. https://github.
More Widely Deployed. Proceedings of 4th W2SP 2 (2010).
com/blog/1466-yummy-cookies-across-domains, 2013.
[accessed Feb-2015].

15
USENIX Association 24th USENIX Security Symposium  721

You might also like