2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cookieについて

Posted at

概要

Cookieについて調べたので備忘録として。

Cookieとは

  • ステートレスであるHTTP通信にステート(状態)を持たせる仕組み
  • ログイン後のセッションIDなどの状態情報をブラウザに記録できる
  • ブラウザの機能として、Cookieがセットされたら同ドメインへのリクエストに自動で一緒に送信する

HTTP通信

Screen Shot 2019-11-07 at 9.33.55.png
  • リクエストしてレスポンスを受け取るだけ
  • 前後のリクエストは現在のリクエストと無関係 = ステートレス
  • FTPはコネクションの状態を保持する = ステートフル

属性

属性 意味
Name 名前
Value
Domain ドメイン
Path ドメイン下の特定のパス
Expires/Max-Age 保持期間
HttpOnly JavaScriptで触れるか
Secure SSL/TLS(https)のリクエストにのみ付与
SameSite 外部ページからのリクエストに付与するか

セット方法

  1. Set-Cookie
    サーバ側からのレスポンスヘッダーに記載

  2. document.cookie
    クライエント側のJavaScriptでセット

保存場所

  • Chromiumベースのブラウザはまずメモリに保持し30秒ごとにSQLiteに保存
    例)
  • Windows
    C:/Users/user/AppData/Local/Google/Chrome/User/Default
  • Mac
    ~/Library/Application Support/Google/Chrome/Default

* Expires=Session のCookieはメモリにのみ保持し、SQLiteには書き込まれない。

Cookie関連の動向

  • GDPRの施行でCookieを使ったトラッキングに規制する傾向がある。

  • Safari、Firefoxは現在デフォルトでサードパーティCookieはセットされない。

  • Google Chrome77からSameSite=None属性でSecure属性がついていないCookieのセットに警告がでる。

  • Chrome80からは明示的に指定しなければ、デフォルトでSameSite=LaxでCookieがセットされ、他ドメインへのリクエストに対してCookieが付与されなくなる。

参考

The Chromium Projects CookieMonster
Today’s Firefox Blocks Third-Party Tracking Cookies and Cryptomining by Default

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?