Render Https Sessions Vulnerable Data Leaks
Render Https Sessions Vulnerable Data Leaks
2 Department
Abstract
A cookie can contain a secure flag, indicating that it
should be only sent over an HTTPS connection. Yet there
is no corresponding flag to indicate how a cookie was
set: attackers who act as a man-in-the-midddle even temporarily on an HTTP session can inject cookies which
will be attached to subsequent HTTPS connections. Similar attacks can also be launched by a web attacker from a
related domain. Although an acknowledged threat, it has
not yet been studied thoroughly. This paper aims to fill
this gap with an in-depth empirical assessment of cookie
injection attacks. We find that cookie-related vulnerabilities are present in important sites (such as Google and
Bank of America), and can be made worse by the implementation weaknesses we discovered in major web
browsers (such as Chrome, Firefox, and Safari). Our
successful attacks have included privacy violation, online victimization, and even financial loss and account
hijacking. We also discuss mitigation strategies such as
HSTS, possible browser changes, and present a proof-ofconcept browser extension to provide better cookie isolation between HTTP and HTTPS, and between related
domains.
Introduction
USENIX Association
2.1
Background
Cookies
USENIX Association
lack of domain or scheme segregation implies that a domain cannot protect the integrity of its cookie from an active MITM or a malicious/compromised related domain
that shares some cookie domain scope with it. There are
two forms of cookie integrity violations:
in its HSTS header, a browser will allow HTTP connection to foo.example.com. Worse, even if the HSTS
policy of example.com specifies includeSubDomains,
this will not be checked by a browser if a user only visits
bar.example.com unless the page includes a reference
to example.com.
2.3
2.2
HSTS
Threat Analysis
We first present the threat model for cookie injection attacks. For each type of attacker, we analyze its real-world
threat. Table 1 gives an overview.
3
USENIX Association
Attacker
Network
Attacker
Active MITM
Malicious Proxy
Web
Attacker
Root Cause
Attack Surface
Websites and browsers that allow attackers to reply an unencrypted request to a related domain with forged response.
Mitigation
Full HSTS
Public suffix list
Out of scope
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
Full HSTS
0
1
7
35
212
997
3.2
Attack Surface
4
710 24th USENIX Security Symposium
USENIX Association
Vendor
Domain
Publis Suffix List? Vulnerable?
akamai.net
No
n/a 1
akamaiedge.net
No
n/a
Akamai
akamaihd.net
No
n/a
edgesuite.net
No
n/a
msecnd.net
No
Yes
Azure
windows.net
No
Yes
BitGravity
bitgravity.com
No
n/a
CacheFly 2
cachefly.net
No
Yes
CDN77
cdn77.net
No
Yes
CDNetworks
cdngc.net
No
n/a
CDN.net
worldcdn.net
No
n/a
ChinaCache
chinacache.net
No
n/a
ChinaNetCenter wscloudcdn.com
No
n/a
CloudFlare 3
cloudflare.net
No
Yes
CloudFront
cloudfront.net
Yes
No
EdgeCast
edgecasecdn.net
No
n/a
Exceda
expresscdn.com
No
Yes
Fastly 3
fastly.net
Yes
Yes
Highwinds
hwcdn.net
No
n/a
Incapsula
incapsula.net
No
Yes
Internap
internapcdn.net
No
n/a
Jiasule
jiashule.com
No
Yes
KeyCDN 2
kxcdn.com
No
Yes
Level3
footprint.net
No
n/a
Limelight
linwd.net
No
n/a
MaxCDN
netdna-cdn.com
No
Yes
Squixa
squixa.net
No
n/a
weaker cookie SOP. As we previously discussed in Section 2.1, a domain is allowed to set cookies with wider
domain scope as long as the scope is not considered
public. Hence, a clear boundary between public and
non-public domain scope is needed to prevent cookie
injection from undesired shared cookie domain. However, this is not easy to define and implement clearly.
First, many top-level domains (a.k.a., TLDs), especially
country code top-level domains (a.k.a., ccTLDs) have
their own reserved suffixes such as .com.cn, .co.uk,
which are mostly TLD-specific. Second, many websites
use shared domains to assign subdomains to their mutually untrusted clients. Such shared domain providers
include cloud hosting providers, web hosting providers,
blog providers, CDN providers etc. These shared domains should also be considered as non-public in terms
of cookie domain scope.
The problem of cookie domain scope boundary is
partially remedied by a community effort initiated by
Mozilla called public suffix list, which maintains an
exceptional list containing TLDs, TLD-reserved suffixes,
and self-declared shared domains [25]. Public information suggests that the list is enforced by major browser
vendors including IE, Chrome, Firefox, and Opera, while
our own tests confirm that Safari implements this list.
Our study of the public suffix list shows that the
public shared domains list still exposes an attack surface for cookie injection. First, we empirically identified 45 shared domains from the Alexa top one million
websites, among which only 10 Google domains and 3
non-Google domains are included in the public suffix
list. Among the remaining domains, we found at least
4 domains (sinaapp.com, weebly.com, myshopify.
com, and forumotion.com) allow customized serverside code or browser-side scripts. Websites hosting on
these domains are vulnerable to cookie injection attacks.
Another easy-to-miss corner case is shared domains
used by CDNs. CDNs commonly assign subdomains
or sub-directories of shared domains to their customers.
If a website directly uses a shared domain assigned by
its CDN provider, and the CDN provider does not handle the shared domain carefully, then the website is subject to cookie injection attacks from malicious customers
of the same CDN provider. While websites rarely use
shared domains as their main domains, a common practice is to refer static resources (e.g., JavaScript files, images) using shared domain URLs. Although cookies under these resource URLs are usually not processed by
server-side code or browser-side scripts, cookie injection
attacks could still cause serious consequences. For example, suppose both websites A and B host their static
resource files under one shared domain from the same
CDN. Website A can inject garbage cookies from the
requests to his resource files with specific paths so that
5
USENIX Association
fix list, which fails to prevent JavaScript from injecting cookies. Second, although Fastly has declared several subdomains of fastly.net as public suffix, its
naming mechanism enables shared scopes in customerspecific prefixes, making its customers still vulnerable to
cookie injection attacks. For example, for a customer
foo.com, Fastly assigns a customer subdomain foo.
com.global.prod.fastly.net. Although the suffix
global.prod.fastly.net is present in the public suffix list, the prefix causes a cookie scope com.global.
prod.fastly.net shared with other customer subdomains such as bar.com.global.prod.fastly.net.
CloudFlare also has the same problem. We have reported
this problem to all vulnerable vendors. CloudFlare and
CDN77 have acknowledged our reports. The response
from CloudFlare said that they are considering to disable
direct access of all cloudflare.net URLs to defend
against this problem.
with the same name, while the name-value map interface in Python standard library prefers the last-ordered
cookie, all others prefers the first-ordered one. This explains why cookie shadowing is possible and the example
given in Section 2.1 works in many cases.
Cookie Storage Limitation. The specification has
several vague suggestions for browsers to limit the number and size of stored cookies. We found all major
browsers set the maximum size of a single cookie to 4
KB. Chrome, Firefox, and Opera implements a cookie jar
for every base domain, with the total numbers of cookies
limited to 180, 150, and 180, respectively. IEs cookie jar
implementation is per cookie domain scope, with the total number of cookies limited to 50. We did not reach Safaris cookie storage limit after writing and reading 1,000
cookies.
Cookie Header Size Limit. While Safari does not
seem to have a limit for the number of cookies, it truncates the matching cookie list if the length of the cookie
header exceeds 8 KB. We did not observe similar behaviors in other browsers.
Cookie Name. The cookie name can contain all
US-ASCII values except control characters and separator characters (see definition in [2] and [8]). We
found that Safari mistakenly stores cookie name in caseinsensitive manner. Some programming languages also
implement cookie names incorrectly. Previously Lundeen et al. reported that ASP.NET implements cookie
names case-insensitively [24]. We found that ASP makes
same mistake. In addition, PHP performs percentdecoding on cookie names. For these languages, different cookie names sent by browser are possibly recognized as same name cookies, which embraces another
vector for cookie shadowing. For example, PHP interprets a cookie header %76alue=bad; value=good; as
value=bad; value=good;, causing the good cookie to
be shadowed by the bad one.
Cookie Path. According to the specification, a cookie
matches a URL only when the path scope of the cookie is
a sub-directory of (or identical to) the URL path. When
a cookie does not specify the path scope, the browser
is required to set its default path as the directory-portion
of the URL path without any trailing slash. We found 4
violations to the standard: 1) IE and Safari4 implement
a sub-string other than sub-directory matching rule; 2)
Firefox matches cookie path with not only the URL path,
but also the URL query and the URL fragment portion;
3) Firefox matches a cookie path with a URL path when
the former has one more slash than the later; 4) Chrome,
Safari, and Opera (Linux and iOS versions) include the
trailing slash in default cookie path.
Based on the threat model and the understanding of potential attack surfaces, we then turn to understand how
cookie related mechanisms are implemented in browsers
and web applications. Our study pinpointed a number
of inconsistent and/or non-conforming behaviors in major browsers and web frameworks, as summarized in Table 4. We also identified several vulnerabilities in major browsers allowing an active network attacker to inject
cookies even when the full HSTS is deployed. We have
reported these vulnerabilities to browser vendors.
4.1
6
712 24th USENIX Security Symposium
USENIX Association
Cookie Property
Browser-side priority
Server/script-side preference
Specification
Cookies SHOULD be ranked by specificity of
path then by creation time in ascending order.
Server SHOULD NOT rely on cookies ordering presented by browsers.
Not specified
US-ASCII values except control characters
and separator characters (see definition in [2]
and [8])
1. Cookie path and URL path MUST be identical or sub-directory matching;
2. Trailing slash MUST NOT be included in
default cookie path.
Cookie path
Non-conforming/inconsistent behaviors
1. Safari ranks cookies by specificity of domain then by specificity of path.
1. Most standard libs and frameworks only provide name-value map interfaces;
2. For each name in the cookie list, Python prefers the last-ordered cookie, others
prefer the first-ordered one.
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.
1. Safari truncates the cookie header not to exceed 8,192 bytes.
1. Safari is case-insensitive with cookie name;
2. ASP and ASP.NET are case-insensitive;
3. PHP performs percent-decoding on cookie name.
1. Firefox matches cookie path not only with URL path, but also with URL query
and URL fragment;
2. IE and Safari implement sub-string matching other than sub-directory matching;
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 implementations.
4.2
Uncovered Vulnerabilities
IE
Chrome
Firefox
Safari
Opera
Windows
Mac OS
Linux
Android
iOS
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A
Real-World Exploitations
USENIX Association
5.1.1
5.1
USENIX Association
quest on Safari by exploiting its cookie header limitation (see Case-5 in Section 5.1.5 for the details). However, the server seemed to check whether session cookies under https://www.google.com/search are consistent with those under https://www.google.com/.
Once receiving inconsistent session cookies from the
AJAX request, it navigated the web interface to https:
//www.google.com/search, which still showed the attackers profile name and icon.
Our final attack was to inject session cookies with domain scope www.google.com and path /, so that for
non-Safari browsers, the attacker could steal the victims
search history. Although this attack affects the web interface, causing to show the attackers profile name and
icon, it does not affect most other Google services. We
also verified an invisible attack by spoofing the victims
profile name and icon.
5.1.2
which may be noticed by the victim. However, if the attacker can only hijack an AJAX request which is not related to the interface, especially ID-indicators, the attack
could be launched invisibly.
Second, explicit and session dependent verifiers could
bind separate URLs together, so that the attacker needs
to hijack more URLs. One example is using a session
dependent nonce to counter CSRF attacks. Suppose the
attacker wants to steal some sensitive information submitted by a form which is fetched from URL GetForm
then submitted through URL SubmitForm. If the CSRF
protection of the form is session dependent, e.g. a nonce
associated with user session embedded in the form and
verified when submitting, the attacker must hijack both
GetForm and SubmitForm so that the CSRF verification does not fail. Otherwise he only needs to hijack
SubmitForm.
It turns out that sub-session hijacking can be a powerful attack against todays websites. Because many
web applications do not adopt mechanisms to bind subsessions together, and, for many operations, hijacking
one sub-session is sufficient to cause serious consequences. Below we describe three common functionalities that are often vulnerable to sub-session hijacking,
demonstrated with real-world cases.
The two cases above show a common pattern: the attacker intends to limit the effective scope of injected session cookies as small as possible to reduce the visibility
of his attack.
Essentially, web applications require one or more
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
a series of pages, the corresponding sub-sessions carrying the same user authentication tokens are attributed to
the users account. However, when using cookies as authentication tokens, the cookie-URL matching rules and
implementations often allow the attacker to selectively
associate one or more sub-sessions to the attackers account by cookie shadowing. That is why we call this type
of attack sub-session hijacking attacks.
The impact of such attacks varies by the applications.
In general, the attackers strategy is to select a minimum
set of sub-sessions that achieve his attack goals meanwhile keep the visibility of the attack as small as possible. However such attack could be made difficult by
some implementation choices.
First, in general, a victim could notice a sub-session
hijacking attack if she views abnormal changes of some
visual elements on her screen. Typically such elements
include username, email, a profile icon etc., which we
refer to as ID-indicators. If a website uses less URLs in
one page or one certain functionality, and makes the important URLs related with the ID-indicators, the attacker
is less likely to perform sub-session hijacking without
being noticed. For example, in Case-2, the attacker has
to hijack both of the URL that shows the search interface,
and the AJAX request that performs the search. This limitation causes the expose of his profile name and icon,
5.1.3
A common feature in many Chinese websites is the ability to deposit money from an online bank (or a third-party
payment service like Alipay) into a website for future
9
USENIX Association
5.2
Session fixation is a well-known attack in which an attacker holds a session ID, then persuades a victim to authenticate with that ID so that he gains control of the
victims account [21]. Cookie injection can be used to
exploit vulnerable websites that use cookies to store session IDs. Standard defenses, e.g. regenerating session ID
after login, have been widely adopted.
However, we found that, although some websites have
implemented defenses for typical session fixation attacks, they still have similar vulnerabilities for cookie
injection. The root cause is that they associate important server-side states with long-term cookies. Moreover, they do not bind these states with user sessions.
10
USENIX Association
The attacker can fixate such cookies by cookie injection (e.g., through cookie overwriting) in order to access
and manipulate the associated states. Interestingly, most
of the vulnerable websites we found vulnerable are Ecommerce websites.
Case-6: Shopping cart tracking/manipulation on
popular E-commerce websites. We demonstrate this
type of issues on 3 popular E-commerce websites:
Apple, eBay, and JD.com. These websites allow unregistered visitors to add items in shopping carts. For better
user experience, they never expire the shopping carts
on the server side, and use long-term cookies on the
browser side as references. We have verified that if the
attacker fixates the corresponding cookies using cookie
injection, he can track or manipulate shopping carts of
the unregistered visitors.
5.3
11
USENIX Association
found that one cookie with path / on Bank of Americas website could be exploited to inject XSS. At first,
our nave exploitation by overwriting the cookie with a
XSS payload failed. The limitation was that the website
performed a strict validation on the cookie at the login
URL. Only if the cookie was absent would the website
set a clean value on the cookie from the response of the
login URL, then used it in subsequent requests without
validation. Our nave exploitation was prevented by the
strict validation at the login URL.
We found a technique to bypass the limitation, so that
the XSS payload can be buried into the victims browser
and triggered when next time the victim logs in by injecting multiple cookies. We injected two cookies. The
first one had the same 3-tuple identifier as the legitimate
one, but with an expired time to ensure the legitimate
cookie was discarded and absent at the login URL. The
second injected cookie contained the XSS payload and
had a different cookie path /myaccount that matched
with the first URL after login. Although the server set a
clean cookie in the response of the login URL, the specific path of the second injected cookie not only avoid
being overwritten by the clean cookie, but also shadowed
the clean cookie in subsequent requests, triggering a successful XSS attack.
This case implies a possible misconception that performing a complete cookie validation on one entry
point is sufficient. In fact, because of the asymmetry
between cookie read and write operations, every different
URL might bring different and unexpected cookie values
no matter how server set cookies in previous responses.
Developers must treat every request as a new entry point
and carefully validate all associated cookies.
5.3.2
5.4
Summary
Possible Defenses
In 2002, Kelsey observed that when combining encryption with some compression algorithms, the size of compressed data can be used as a side channel, potentially
causing plaintext leakage under certain conditions [20].
Rizzo and Duong found a real-world case in 2012, named
as CRIME attack, in which an active network attacker
initiates encrypted HTTP requests from a victim browser
with different URLs as partially-chosen plaintexts, then
infer embedded secrets like session cookies by observing
the sizes of the compressed and encrypted requests [29].
Rizzo and Duong also mentioned that a similar attack
could also be mounted to infer secrets in encrypted
HTTP responses. This was explored and demonstrated
by Gluck et al., named as the BREACH attack [12].
BREACH requires the attacker to be able to 1) inject a
partially-chosen plaintext into the HTTP response of one
webpage, and 2) measure the size of the compressed then
encrypted response. An active network attacker satisfies
12
718 24th USENIX Security Symposium
USENIX Association
6.1
We propose several browser-side enhancements to mitigate cookie injection attacks. Our proposals do not require any server-side change, so they would benefit many
legacy websites.
6.1.1
13
USENIX Association
Related Work
Comparison to Previous Work. We are aware of several research papers that are directly related to cookies
weak SOP and integrity problem [4, 30, 24, 23, 5, 2,
32], and some other papers that are comparable to our
work [17, 22]. Among the directly related research,
Barths [2] and Zalewskis work [32] focused on explaining the cause of the cookie integrity problem. Most previous research only briefly touched cookie integrity as
a relevant subproblem rather than main topic [4, 30, 24,
23]. Bortz et al. s research is close to ours. Especially,
they introduced the notion of a related domain attacker
which we use throughout this paper. However, their work
is limited to high-level discussion [5]. In summary, previous research has discussed the problem of cookies lack
Conclusions
Cookies lack integrity. Although long known in community lore, the community has under-appreciated the implications. We have attempted to systematically evaluate
the implications of cookie integrity, including evaluating
weaknesses and evaluation artifacts in both browser and
server libraries, building real-world attacks against ma14
USENIX Association
jor sites including Google and Bank of America, including subtle account-hijack attacks and XSS attacks buried
in injected cookies, and developing an alternate browser
cookie policy that mitigates the threat from networklevel attackers. We expect our work to raise the awareness of the problem, and to provide a context for further
discussion among researchers, developers and vendors.
[12] G LUCK , Y., H ARRIS , N., AND P RADO , A. BREACH: Reviving the CRIME Attack.
http://breachattack.com/
resources/BREACH%20-%20SSL,%20gone%20in%2030%
20seconds.pdf, 2013. [accessed Feb-2015].
[13] G OOGLE S UPPORT. Block Adult Content at Your School.
https://support.google.com/websearch/answer/
186669?hl=en. [accessed Feb-2015].
[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 Transport Security (HSTS). IETF RFC 6797 (2012).
Acknowledgements
[16] IEB LOG. Project Spartan and the Windows 10 January Preview
Build. http://blogs.msdn.com/b/ie/archive/2015/01/
22/project-spartan-and-the-windows-10-januarypreview-build.aspx. [accessed Feb-2015].
References
[17] JACKSON , C., AND BARTH , A. Beware of Finer-Grained Origins. Proceedings of 2th W2SP (2008).
[18] JACKSON , C., AND BARTH , A. ForceHTTPS: Protecting HighSecurity Web Sites from Network Attacks. In Proceedings of the
17th WWW (2008), ACM, pp. 525534.
[19] J OHNSTON , P., AND M OORE , R. Multiple Browser Cookie
Injection Vulnerabilities. http://www.westpoint.ltd.uk/
advisories/wp-04-0001.txt, 2004. [accessed Feb-2015].
[3] BARTH , A. The Web Origin Concept. IETF RFC 6454 (2011).
[4] BARTH , A., JACKSON , C., AND M ITCHELL , J. C. Robust Defenses for Cross-Site Request Forgery. In Proceedings of the 15th
CCS (2008), ACM, pp. 7588.
[6] C HEN , S., M AO , Z., WANG , Y.-M., AND Z HANG , M. PrettyBad-Proxy: An Overlooked Adversary in Browsers HTTPS Deployments. In Proceedings of the 30th IEEE S&P (Oakland)
(2009), IEEE, pp. 347359.
[8] F IELDING , R., G ETTYS , J., M OGUL , J., F RYSTYK , H., M AS INTER , L., L EACH , P., AND B ERNERS -L EE , T. Hypertext
Transfer ProtocolHTTP/1.1. IETF RFC 2616 (1999).
[31] WANG , R., Z HOU , Y., C HEN , S., Q ADEER , S., E VANS , D.,
AND G UREVICH , Y. Explicating SDKs: Uncovering Assumptions Underlying Secure Authentication and Authorization. In
USENIX Security (2013), pp. 399314.
[9] F IELDING , R., AND R ESCHKE , J. Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing. IETF RFC 7230
(2014).
OpenID Authentication 2.0 - Final.
[10] F OUNDATION , O.
http://openid.net/specs/openid-authentication2_0.html. [accessed Feb-2015].
15
USENIX Association