user886596
user886596

Reputation: 2440

Is the order in which cookies show up in document.cookie deterministic?

It's possible to have two cookies with the same name but different values in document.cookie if a subdomain and a domain set the same cookie.

For example, if I:

  1. Visit subdomain.domain.com first, which sets a my_cookie=foocookie.
  2. And then visit domain.com second, which sets a my_cookie=boocookie.

document.cookie in Chrome 81 will show my_cookie=foo; my_cookie=boo on subdomain.domain.com, in the order in which the cookies were set with the most recent cookie last.

My question is, can this ordering be relied on (and is there a rfc that talks about this)?

Upvotes: 3

Views: 241

Answers (1)

amprew
amprew

Reputation: 261

Interestingly found this in an RFC about not relying on cookie orders between different subdomians:

enter image description here

reference: https://tools.ietf.org/rfc/rfc6265.txt

4.2.2. Semantics

Upvotes: 2

Related Questions