HTTP cookie: Difference between revisions

Content deleted Content added
OAbot (talk | contribs)
m Open access bot: doi, hdl added to citation with #oabot.
Citation bot (talk | contribs)
Alter: template type. Add: year, website, s2cid, doi, journal, date, newspaper, authors 1-2. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | Suggested by Whoop whoop pull up | Linked from User:UBX/Userboxes/Wikipedia | #UCB_webform_linked 17/42
Line 26:
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.{{cn|date=October 2022|reason=This is most likely incorrect, as at least Internet Explorer had very prominent cookie warnings and required explicit permission to accept any.}} 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 [[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 webnews|url=https://datatracker.ietf.org/doc/html/rfc2109#section-8.3|title = Rfc2109| newspaper=Ietf Datatracker | date=February 1997 }}</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>
Line 49:
 
==={{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>. The attribute <code>SameSite</code> can have a value 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.|websitenewspaper=tools.ietf.orgIetf 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.<ref name="wi75q">{{Cite web|title=Using the Same-Site Cookie Attribute to Prevent CSRF Attacks|url=https://www.netsparker.com/blog/web-security/same-site-cookie-attribute-prevent-cross-site-request-forgery/|access-date=2021-04-05|website=www.netsparker.com|date=23 August 2016 |language=en}}</ref> 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>
 
The Same-site cookie is incorporated into [https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-07 a new RFC draft for "Cookies: HTTP State Management Mechanism"] to update RFC 6265 (if approved).
Line 157:
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>.
 
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 webjournal |url=http://tools.ietf.org/html/rfc6265#section-4.1.2.4 |workjournal=IETF |title=HTTP State Management Mechanism, The Path Attribute |date=March 2014 |doi=10.17487/RFC6265 |access-date=2011-05-12 |archive-url=https://web.archive.org/web/20110501105323/http://tools.ietf.org/html/rfc6265#section-4.1.2.4 |archive-date=2011-05-01 |url-status=live|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 webjournal |url=http://tools.ietf.org/html/rfc6265#section-5.1.3 |workjournal=IETF |title=RFC 6265, HTTP State Management Mechanism, Domain matching |date=March 2014 |doi=10.17487/RFC6265 |access-date=2011-05-12 |archive-url=https://web.archive.org/web/20110501105323/http://tools.ietf.org/html/rfc6265#section-5.1.3 |archive-date=2011-05-01 |url-status=live|last1=Barth |first1=A. }}</ref><ref name="5Qixt">{{cite webjournal |url=http://tools.ietf.org/html/rfc6265#section-4.1.2.3 |workjournal=IETF |title=RFC 6265, HTTP State Management Mechanism, The Domain Attribute |date=March 2014 |doi=10.17487/RFC6265 |access-date=2011-05-12 |archive-url=https://web.archive.org/web/20110501105323/http://tools.ietf.org/html/rfc6265#section-4.1.2.3 |archive-date=2011-05-01 |url-status=live|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>
 
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:
Line 168:
</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 webjournal |url=http://tools.ietf.org/html/rfc2109#section-4.2.2 |workjournal=IETF |title=RFC 2109, HTTP State Management Mechanism, Set-Cookie syntax |date=March 2014 |doi=10.17487/RFC2109 |access-date=2014-03-04 |archive-url=https://web.archive.org/web/20140313071934/http://tools.ietf.org/html/rfc2109#section-4.2.2 |archive-date=2014-03-13 |url-status=live|last1=Kristol |first1=D. |last2=Montulli |first2=L. |s2cid=6914676 }}</ref>
 
====Expires and Max-Age====
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 webjournal|url=http://tools.ietf.org/html/rfc6265#section-5.1.1|title=RFC 6265, HTTP State Management Mechanism|workwebsite=ietf.org|year=2011 |doi=10.17487/RFC6265 |access-date=2011-05-12|archive-url=https://web.archive.org/web/20110501105323/http://tools.ietf.org/html/rfc6265#section-5.1.1|archive-date=2011-05-01|url-status=live|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: