LoginSignup
4
0

Set-CookieのDomainの先頭のドットは無視されるということを、Railsのアップデートに関する調査をしている際に知りました。

↓ Cookieを確認すると表示される、この .qiita.com の先頭のドットです。
image.png

Contrary to earlier specifications, leading dots in domain names (.example.com) are ignored.

背景等について

RailsのPull Requestに詳しく説明されていました。

This leading dot was required in cookies based on RFC 2965 (October 2000), but RFC 6265 (April 2011) changed that behaviour

とあるように、仕様が変わったようです。

現在では、レスポンスヘッダの Set-Cookiedomainの先頭にドットがついていても無視されるので、動作の確認をしてみたところ、

  • 元々ドットありでCookieをセットしていたとしても、ドットなしのSet-Cookieで値を上書きできる
  • 元々ドットなしでCookieをセットしていたとしても、ドットありのSet-Cookieで値を上書きできる

という挙動をするので、Set-Cookieのdomainの値を変更しても挙動に影響がなさそうでした。

ただ、Chrome等の開発者ツールでCookieの値を確認すると (冒頭の画像) 先頭にドットが表示されたままでした。

補足: Set-Cookieの domain について

MDNから引用しますが、

Defines the host to which the cookie will be sent.

Domainはどのホストにcookieを送信するかを定義します。

Setting the domain will make the cookie available to it, as well as to all its subdomains.
If omitted, this attribute defaults to the host of the current document URL, not including subdomains.

Domainを指定しない場合、現在のURLのホストのみにCookieを送信しますが、
Domainを指定する場合、そのサブドメインにも送信されるようになります。

そのため、サブドメインに送信する必要がないのであれば、domainを指定しないほうが条件が厳しくなります。

参考

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0