M12i.

学術書・マンガ・アニメ・映画の消費活動とプログラミングについて

仮定されたSet-Cookie: ...; Domain=example.com

職場でメンテしているアプリで特定のオペレーションをするとセッションタイムアウトになってしまう問題が発生してこの2・3日大変だった。

結果としてはなんのことはない、例によって例のごとく、原因はIEのバグ。というかこれは、もはや/むしろ仕様?

問題の動作はクッキー(Cookie)の仕様RFC-6265にまでばっちり言及されている「既知の問題」の1つだった。

4.1.2.3. The Domain Attribute

The Domain attribute specifies those hosts to which the cookie will be sent. For example, if the value of the Domain attribute is "example.com", the user agent will include the cookie in the Cookie header when making HTTP requests to example.com, www.example.com, and www.corp.example.com. (Note that a leading %x2E ("."), if present, is ignored even though that character is not permitted, but a trailing %x2E ("."), if present, will cause the user agent to ignore the attribute.) If the server omits the Domain attribute, the user agent will return the cookie only to the origin server.

WARNING: Some existing user agents treat an absent Domain attribute as if the Domain attribute were present and contained the current host name. For example, if example.com returns a Set- Cookie header without a Domain attribute, these user agents will erroneously send the cookie to www.example.com as well.

すなわち、

4.1.2.3. Domain属性

Domain属性はクッキーの送信先となるホスト群を指定するものです。例えば、もし〔あるクッキーの〕Domain属性の値が "example.com”であれば、ユーザーエージェントは、example.comwww.example.com、それにwww.corp.example.comといったホストに対するHTTPリクエストを生成するとき、Cookieヘッダーにそのクッキーを含めることになるでしょう。(気に留めておくべきことは、先頭の%x2E (".”)は、それがもし存在した場合でも、許可された文字でないにもかかわらず無視されるだけであるのに対して、末尾の%x2E (".”)は、それがもし存在した場合、ユーザーエージェントに対してその属性を無視させる結果となることです。)もしサーバー側がDomain属性を省略した場合、ユーザーエージェント側はそのクッキーを当該のサーバーにしか送信しません。

注意: いくつかの既存のユーザーエージェントは、Domain属性が存在しない場合に、あたかもDomain属性が存在し、そこに現在のホスト名が設定されているかのように取り扱います。例えば、example.com というホストがSet-CookieヘッダーをDomain属性なしで返すとき、それらのユーザーエージェントは当該のホストだけでなくwww.example.com というホストに対してもそのクッキーを誤送信してしまうのです。

この注意事項にIE9やIE11が該当する。ケータイのブラウザにも該当するものがあるらしい。FirefoxChromeSafariOperaは該当しない(こちらの記事でちょっとした調査結果が公開されている)。