{"id":1652,"date":"2010-04-12T22:29:52","date_gmt":"2010-04-12T20:29:52","guid":{"rendered":"http:\/\/daniel.haxx.se\/blog\/?p=1652"},"modified":"2024-04-12T08:43:31","modified_gmt":"2024-04-12T06:43:31","slug":"curl-and-speced-cookie-order","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2010\/04\/12\/curl-and-speced-cookie-order\/","title":{"rendered":"curl and speced cookie order"},"content":{"rendered":"\n<p>I just <a href=\"https:\/\/curl.se\/mail\/lib-2010-04\/0152.html\">posted this on the curl-library list<\/a>, but I feel it suits to be mentioned here separately.<\/p>\n\n\n\n<p>As I&#8217;ve mentioned before, I&#8217;m involved in the IETF <a href=\"https:\/\/datatracker.ietf.org\/wg\/httpstate\/charter\/\">http-state working group<\/a> which is working to document how cookies are used in the wild today. The idea is to create a spec that new implementations can follow and that existing implementations can use to become more interoperable.<\/p>\n\n\n\n<p>(If you&#8217;re interested in these matters, I can only urge you to join the&nbsp;<a href=\"https:\/\/www.ietf.org\/mailman\/listinfo\/http-state\">http-state mailing list<\/a> and participate in the discussions.)<\/p>\n\n\n\n<p>The subject of how to order cookies in outgoing HTTP Cookie: headers have been\u00a0much debated over the recent months and I&#8217;ve also <a href=\"https:\/\/daniel.haxx.se\/blog\/2010\/01\/20\/cookie-order\/\">blogged about it<\/a>. Now, the <a href=\"http:\/\/www.ietf.org\/mail-archive\/web\/http-state\/current\/msg00732.html\">issue has been closed<\/a> and the decision went quite opposite to my standpoint and now the spec will say that while the servers SHOULD not rely on the order (yeah right, some obviously already do and with this specified like this even more will soon do the same) it will recommend clients to sort the cookies in a given way that is close to the way current Firefox does it[*].<\/p>\n\n\n\n<p>This has the unfortunate side-effect that to become fully compatible with how  the browsers do cookies, we will need to sort our cookies a bit more than what  we just recently introduced. That in itself really isn&#8217;t very hard since once  we introduced qsort() it is easy to sort on more\/other keys.<\/p>\n\n\n\n<p>The biggest problem we get with this, is that the sorting uses <em>creation time<\/em> of the cookies. libcurl and curl and others mostly use the Netscape cookie  files to store cookies and keep state between invokes, and that file format  doesn&#8217;t include creation time info! It is a simple text-based file format with  TAB-separated columns and the last (7th) column is the cookie&#8217;s content.<\/p>\n\n\n\n<p>In order to support the correct sorting between sessions, we need to invent a  way to pass on the creation time. My thinking is that we do this in a way that  allows older libcurls still understand the file but just not see\/understand  the creation time, while newer versions will be able to get it. This would be  possible by extending the <em>expires<\/em> field (the 6th) as it is a numerical value  that the existing code will parse as a number and it will stop at the first  non-digit character. We could easily add a character separation and store the<br>\ncreation time after. Like:<\/p>\n\n\n\n<p>Old expire time:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2345678<\/pre>\n\n\n\n<p>New expire+creation time:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2345678\/1234567<\/pre>\n\n\n\n<p>This format might even work with other readers of this file format if they  do similar assumptions on the data, but the truth is that while we picked the  format in the first place to be able to exchange cookies with a well known  and well used browser, no current browser uses that format anymore. I assume there are still a bunch of other tools that do, like wget and friends.<\/p>\n\n\n\n<p><strong>Update:<\/strong> as my friend Micah Cowan explains: we can in fact use the order of the cookie file as &#8220;creation time&#8221; hint and use that as basis for sorting. Then we don&#8217;t need to modify the file format. We just need to make sure to store them in time-order&#8230; Internally we will need to keep a line number or something per cookie so that we can use that for sorting.<\/p>\n\n\n\n<p>[*] &#8211; I believe it sorts on path length, domain length and time of creation, but as soon as the -06 draft goes online it will be easy to read the exact phrasing. The existing -05 draft exists at: <a href=\"http:\/\/tools.ietf.org\/html\/draft-ietf-httpstate-cookie-05\">http:\/\/tools.ietf.org\/html\/draft-ietf-httpstate-cookie-05<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just posted this on the curl-library list, but I feel it suits to be mentioned here separately. As I&#8217;ve mentioned before, I&#8217;m involved in the IETF http-state working group which is working to document how cookies are used in the wild today. The idea is to create a spec that new implementations can follow &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2010\/04\/12\/curl-and-speced-cookie-order\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl and speced cookie order<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,11,13],"tags":[216,33,230,249],"class_list":["post-1652","post","type-post","status-publish","format-standard","hentry","category-curl","category-development","category-net","tag-cookies","tag-curl-and-libcurl","tag-http","tag-ietf"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/1652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=1652"}],"version-history":[{"count":14,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions"}],"predecessor-version":[{"id":24604,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions\/24604"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=1652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=1652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=1652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}