w:en: HTTP cookie

{{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}}

HTTP cookie (also called web cookie, Internet cookie, browser cookie, or simply cookie) is a small block of data created by a web server while a 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.

Cookies serve useful and sometimes essential functions on the web. They enable web servers to store stateful information (such as items added in the shopping cart in an online store) on the user's device or to track the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past).{{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}} They can also be used to save information that the user previously entered into form fields, such as names, addresses, passwords, and payment card numbers for subsequent use.

Authentication cookies are commonly used by web servers to authenticate that a user is logged in, and with which 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 encrypted. Security vulnerabilities may allow a cookie's data to be read by an attacker, used to gain access to 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).{{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}}

Tracking cookies, and especially third-party tracking cookies, are commonly used as ways to compile long-term records of individuals' browsing histories {{Em dash}} a potential privacy concern that prompted European{{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}} and U.S. lawmakers to take action in 2011.{{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}}{{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}} European law requires that all websites targeting European Union member states gain "informed consent" from users before storing non-essential cookies on their device.

Background

=Origin of the name=

File:Cookie stack.jpg.]]

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.{{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}}{{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}}

=History=

Magic cookies were already used in computing when computer programmer Lou Montulli had the idea of using them in web communications in June 1994.{{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}} At the time, he was an employee of Netscape Communications, which was developing an e-commerce application for 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 virtual shopping cart.{{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}}{{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}}

Together with John Giannandrea, Montulli wrote the initial Netscape cookie specification the same year. Version 0.9beta of Mosaic Netscape, released on October 13, 1994,{{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}}{{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}} 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, which was granted in 1998.{{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}} Support for cookies was integrated with Internet Explorer in version 2, released in October 1995.{{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}}

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.{{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}} The public learned about cookies after the Financial Times published an article about them on February 12, 1996.{{cite news|last=Jackson|first=T|title=This Bug in Your PC is a Smart Cookie|newspaper=Financial Times|date=1996-02-12}} 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 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 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.{{Cite ietf|rfc=2109 |section=8.3 }} 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 Set-Cookie2 header field, which informally came to be called "RFC 2965-style cookies" as opposed to the original Set-Cookie header field which was called "Netscape-style cookies".{{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}}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. Set-Cookie2 was seldom used, however, and was deprecated in RFC 6265 in April 2011 which was written as a definitive specification for cookies as used in the real world.{{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}} No modern browser recognizes the Set-Cookie2 header field.{{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}}

Terminology

{{More citations needed section|date=August 2011}}

=Supercookie=

A supercookie is a cookie with an origin of a top-level domain (such as .com) or a public suffix (such as .co.uk). Ordinary cookies, by contrast, have an origin of a specific domain name, such as example.com.

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 .com could maliciously affect a request made to example.com, even if the cookie did not originate from example.com. This can be used to fake logins or change user information.

The Public Suffix List{{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}} 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.

==Other 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 ETag cookies.{{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}} Due to media attention, Microsoft later disabled this code.{{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 }} In a 2021 blog post, Mozilla used the term supercookie to refer to the use of browser cache as a means of tracking users across sites.{{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 }}

Structure

A cookie consists of the following components:{{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}}}}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}}{{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 }}

  1. Name
  2. Value
  3. Zero or more attributes (name/value pairs). Attributes store information such as the cookie's expiration, domain, and flags (such as Secure and HttpOnly).

Uses

=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). 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 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.

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.

=Personalization=

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.

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.

Also, DuckDuckGo uses cookies to allow users to set the viewing preferences like colors of the web page.

=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 referer field of the HTTP request header, but cookies allow for greater precision. This can be demonstrated as follows:

  1. 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.
  2. 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.

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.Rainie, Lee (2012). Networked: The New Social Operating System. p. 237 The data can then be collected and sold to bidding corporations.

Implementation

File:HTTP cookie exchange.svg

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 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 HttpOnly flag is set, in which case the cookie cannot be modified by scripting languages).

The cookie specifications{{cite ietf |rfc=6265 |title=HTTP State Management Mechanism}}{{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}} require that browsers meet the following requirements in order to support cookies:

  • Can support cookies as large as 4,096 bytes in size.
  • Can support at least 50 cookies per domain (i.e. per website).
  • Can support at least 3,000 cookies in total.

=Cookie 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.

==Domain and Path==

The Domain and Path 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 example.org cannot set a cookie that has a domain of foo.com because this would allow the website example.org to control the cookies of the domain foo.com.

If a cookie's Domain and Path attributes are not specified by the server, they default to the domain and path of the resource that was requested.{{cite ietf |rfc=6265 |section=4.1.2.4 |title=HTTP State Management Mechanism, The Path Attribute |last1=Barth |first1=A. }} However, in most browsers there is a difference between a cookie set from foo.com without a domain, and a cookie set with the foo.com domain. In the former case, the cookie will only be sent for requests to foo.com, also known as a host-only cookie. In the latter case, all subdomains are also included (for example, docs.foo.com).{{cite ietf |rfc=6265 |section=5.1.3 |title=RFC 6265, HTTP State Management Mechanism, Domain matching |date=March 2014 |last1=Barth |first1=A. }}{{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. }} 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.{{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}}

Below is an example of some Set-Cookie header fields in the HTTP response of a website after a user logged in. The HTTP request was sent to a webpage within the docs.foo.com subdomain:

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

The first cookie, LSID, has no Domain attribute, and has a Path attribute set to /accounts. This tells the browser to use the cookie only when requesting pages contained in docs.foo.com/accounts (the domain is derived from the request domain). The other two cookies, HSID and SSID, would be used when the browser requests any subdomain in .foo.com on any path (for example www.foo.com/bar). The prepending dot is optional in recent standards, but can be added for compatibility with RFC 2109 based implementations.{{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 }}

==Expires and Max-Age==

The Expires attribute defines a specific date and time for when the browser should delete the cookie. The date and time are specified in the form Wdy, DD Mon YYYY HH:MM:SS GMT, or in the form Wdy, DD Mon YY HH:MM:SS GMT for values of YY where YY is greater than or equal to 0 and less than or equal to 69.{{cite ietf |rfc=6265 |section=5.1.1|title=RFC 6265, HTTP State Management Mechanism|year=2011 |last1=Barth |first1=A. }}

Alternatively, the Max-Age 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 Set-Cookie header fields that were received from a website after a user logged in:

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

The first cookie, lu, is set to expire sometime on 15 January 2013. It will be used by the client browser until that time. The second cookie, made_write_conn, does not have an expiration date, making it a session cookie. It will be deleted after the user closes their browser. The third cookie, reg_fb_gate, 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 Set-Cookie field match the values used when the cookie was created.

{{As of|2016}} Internet Explorer did not support Max-Age.{{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}}{{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}}

==Secure and HttpOnly==

The Secure and HttpOnly attributes do not have associated values. Rather, the presence of just their attribute names indicates that their behaviors should be enabled.

The Secure attribute is meant to keep cookie communication limited to encrypted transmission, directing browsers to use cookies only via 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 attacks. Therefore, for maximum security, cookies with the Secure attribute should only be set over a secure connection.

The HttpOnly 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).{{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}}

Browser settings

Most modern browsers support cookies and allow the user to disable them. The following are common options:{{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}}

  • 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.{{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}}{{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}}{{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}}{{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}}

Privacy

{{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.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{{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 United States government set strict rules on setting cookies in 2000 after it was disclosed that the White House drug policy office used cookies to track computer users viewing its online anti-drug advertising. In 2002, privacy activist Daniel Brandt found that the CIA had been leaving persistent cookies on computers that had visited its website. When notified it was violating policy, CIA stated that these cookies were not intentionally set and stopped setting them. 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 NSA immediately disabled the cookies.{{cite news |url=https://www.nytimes.com/2005/12/29/national/29cookies.html |newspaper=New York Times |title=Spy Agency Removes Illegal Tracking Files |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}}

Cookie theft and session hijacking

{{Multiple issues|section=yes|

{{Original research|section|date=September 2011}}

{{Unreferenced section|date=September 2011}}

}}

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.

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.

=Network eavesdropping=

File:Cookie-sniffing.svg

Traffic on a network can be intercepted and read by computers on the network other than the sender and receiver (particularly over 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.

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.

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, which will cause the browser to send the cookie only over an encrypted channel, such as a TLS connection.

=Publishing false sub-domain: DNS cache poisoning=

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 f12345.www.example.com 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, http://f12345.www.example.com/img_4_cookie.jpg). Victims reading the attacker's message would download this image from f12345.www.example.com. Since f12345.www.example.com is a sub-domain of www.example.com, victims' browsers would submit all example.com-related cookies to the attacker's server.

If an attacker is able to accomplish this, it is usually the fault of the Internet Service Providers 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{{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}} 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.

=Cross-site scripting: proxy request=

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 www.example.com, and the attacker's script is executed in the victim's browser. The script generates a request to www.example.com with the proxy server attacker.com. Since the request is for www.example.com, all example.com 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=

{{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.,

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.

=Cookiejacking=

Cookiejacking is an attack against Internet Explorer which allows the attacker to steal session cookies of a user by tricking a user into dragging an object across the screen.{{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}} Microsoft deemed the flaw low-risk because of "the level of required user interaction", and the necessity of having a user already logged into the website whose cookie is stolen.{{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}} Despite this, a researcher tried the attack on 150 of their Facebook friends and obtained cookies of 80 of them via social engineering.

Drawbacks of cookies

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 (REST) software architectural style.{{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}}{{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}}

=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.{{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}}

Likewise, cookies do not differentiate between multiple users who share the same user account, computer, and browser.

Alternatives to cookies

Some of the operations that can be done using cookies can also be done using other mechanisms.

=Authentication and session 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==

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)==

The query string part of the 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.

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.

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.

Other drawbacks of query strings are related to security. Storing data that identifies a session in a query string enables session fixation attacks, referer logging attacks and other security exploits. Transferring session identifiers as HTTP cookies is more secure.

==Hidden form fields==

Another form of session tracking is to use 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).

==window.name DOM property==

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. 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 tab will initially have an empty window.name property when opened.

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.

=Tracking=

==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, 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, are designed to retain Internet anonymity, rendering tracking by IP address impractical, impossible, or a security risk.

==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.

==Browser cache==

{{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, var userId = 3243242;). 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.

==Browser fingerprint==

{{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.{{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}}{{cite web |url=http://mypage.direct.ca/s/schinke/defaultbehaviors/clientCapsExtra.html |title=IE "default behaviors [sic]" 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}} Assimilation of such information into a single string constitutes a device fingerprint. In 2010, EFF measured at least 18.1 bits of entropy possible from browser fingerprinting.{{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}} Canvas fingerprinting, a more recent technique, claims to add another 5.7 bits.

=Web storage=

{{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 cookies while session storage behaves similarly to 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.{{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}}

Internet Explorer supports persistent information{{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}} 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.

Some web browser plugins include persistence mechanisms as well. For example, Adobe Flash has Local shared object and Microsoft Silverlight has Isolated storage.{{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}}

See also

References

{{reflist}}

=Sources=

  • Anonymous, 2011. Cookiejacking Attack Steals Website Access Credentials. Informationweek - Online, pp. Informationweek - Online, May 26, 2011.