[3] HTTP の Set-Cookie:
応答頭欄は、
クライアントに対して Cookie を設定することを指示します。
[322] Set-Cookie:
頭欄は Netscape 社によってはじめに定義・実装され、
後にWebブラウザーを含む数多くの HTTP 利用者エージェントで実装されるに至りました。
なお、 Set-Cookie
(>>311) やその改訂版 Set-Cookie2
(>>308) は IETF によって RFC 2109, RFC 2965 として標準化されましたが、
Netscape の定義と互換性がないため無視され、事実上死文化しています。
[4] Set-Cookie:
欄の欄本体は
Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secureのように名前と値の組 (属性) の連続として記述します >>2。
[378] Set-Cookie:
欄の構文は次のように定義されています。
起源鯖はこの構文に従うべきです >>377。
Set-Cookie:
欄の構文set-cookie-header = "Set-Cookie:" SP set-cookie-string set-cookie-string = cookie-pair *( ";" SP cookie-av )
[321] 起源鯖は、 Set-Cookie:
欄を任意のHTTP
応答に含めて構いません >>371。
[52] WebSocket handshake でも使うことができます。
[16] 起源鯖は複数の Set-Cookie:
欄を含めて構いません
>>2, >>371。
[373] 起源鯖は複数の Set-Cookie:
欄を1つに折り畳みするべきではありません。
,
は構文上、値の中に普通に使える文字なので、折り畳みによって意味が変わってしまうことがあります。
>>371
,
の使用が禁止されていたのは複数の Set-Cookie:
頭欄を連結した時に ,
が使われることへの配慮でしょうか、と思いきや、
Expires
では ,
が曜日の後に使われています。
それならなんで禁止されているのでしょう。[18] 複数の Set-Cookie:
欄で同じ名前の Cookie
が設定されていた時の扱いはCookieの属性の項をご覧下さい。
[8] Set-Cookie:
ヘッダーの値は、次のように構文解析しなければなりません
>>7。
[28] 構文解析の結果ヘッダーが無視されなかった場合、得られた名前、値、 属性のリストに関して要求URLからクッキーを受信したといいます。 利用者エージェントがクッキーを受信した時の操作は、 >>27 を参照してください。
[82]
構文上生成は認められていないのですが、
特に何も必要がないときにヘッダー値が空文字列の
Set-Cookie:
ヘッダーを生成するサーバーがあるようです。
[382] Set-Cookie:
欄の値としては、名前と値の組 (cookie-pair)
と、それに続く0個以上の属性を指定することができます。詳しくは Cookieの属性の項をご覧下さい。
[35] 利用者エージェントは、 Set-Cookie:
ヘッダーを無視して構いません >>7。
[46] 利用者エージェントは、クッキーが無効に設定されている場合、応答の
Set-Cookie:
を処理してはなりません >>45。
[27] 利用者エージェントは、クッキーを受信したら、 次のように処理しなければなりません >>31。
Max-Age
/Expires
属性、
Domain
属性、
Path
属性に関連する処理を行います (それぞれの項を参照)。Secure
属性があれば、
クッキーの保安のみフラグを設定します。なければ設定しません。HttpOnly
属性があれば、
クッキーのHTTPのみフラグを設定します。なければ設定しません。[47] 利用者エージェントによっては、クッキーの保存の度に利用者に承認するか確認する機能を提供していることもあります。 一度に大量の確認が表示されることもよくありますが、それでもプライバシーを気にして確認を求める利用者も存在しています。 >>45
[375] Set-Cookie:
は状態符号に関わらず任意の HTTP 応答で使うことができます。
利用者エージェントは 1xx
の場合にこれを無視して構いませんが、
それ以外の場合は処理しなければなりません。 >>371
[305] 利用者エージェントは状態符号がリダイレクトであっても、
(そのリダイレクトが帰ってきた要求の URL に関して)
Set-Cookie:
頭欄に従った処理をするべきです。
[17] Domain
と
Path
と NAME
が同じ Cookie があれば、
値は上書きされて、最新のものだけが残ります。 >>2
[20] >>17 の上書き判定における Path
は完全一致 >>2 なので、
例えば /foo
と /foo/bar
で同じ名前の Cookie
が設定されると、 /foo/bar
では両方が有効になります。
NAME
が同じで
Path
、Domain
が文字列として一致するなら
>>343、RFC 2965 では NAME
が同じで
Path
が文字列として一致、 Domain
が大文字・小文字を区別しないで一致するなら上書きする >>344、
とされていました。[346] 新しい Cookie の Expires
が過去であれば、
古い Cookie は削除され、新しい Cookie も蓄積されません。
[22] 串は Set-Cookie:
頭欄をそのままクライアントに渡すべきです。
状態符号が 200
であれ 304
であれ、です。
>>2
[376] Set-Cookie:
欄の有無はキャッシュ可能性に影響しません >>371, >>5。
Set-Cookie:
や Set-Cookie2:
との関わりを考察しています
>>359, >>360。キャッシュ不能なら問題はないのですが、 pre-expired
な場合、状況によっては起源鯖による妥当性検証をスキップしてクライアントに送られてしまい、
他のクライアント向けの Cookie がそのクライアントに渡る可能性があることを指摘しています。Cache-Control:
によりもっと細かく制御できるので大丈夫ということなのでしょう。<meta http-equiv=Set-Cookie>
#✎[39] <meta http-equiv=Set-Cookie>
(Cookie setter 状態 >>38) は、
クッキーを設定するものです。
[40] この状態は不適合です >>38。著者は使ってはなりません。
[41] 利用者エージェントは、 content
属性があって空文字列でない場合、
content
属性値を UTF-8
で符号化した値を文書の番地に関して「非HTTP」API
から受信したものとして処理しなければなりません >>38。
[54] かつてはストレージミューテックスを得ると規定されていましたが、誰も従っていませんでしtあ。
[84]
Set-Cookie:
の構文は
curl のコマンドラインオプション --cookie
でも使われています。
[86]
Set-Cookie:
の構文は
ffmpeg
のオプション
cookies
でも使われています。
改行区切りとされています。
>>85
cookies
Set the cookies to be sent in future requests. The format of each cookie is the same as the value of a Set-Cookie HTTP response field. Multiple cookies can be delimited by a newline character.
[59]
Perlモジュール HTTP::Cookie
は、
クッキーをファイルシステムに保存する際のデータ形式で
Set-Cookie3
という名称を使っています。
Set-Cookie:
欄#✎[311] IETF は Cookie の標準化を試み、RFC 2109 で Netscape Cookie
とは非互換な Set-Cookie:
頭欄を定義していました。
Set-Cookie2:
欄#✎[308] RFC 2109 を廃止して代わりに発行された RFC 2965 は
Set-Cookie
を捨てて非互換な
Set-Cookie2:
頭欄 を定義していました。
[353] RFC 2965 は (廃止した RFC 2109 には触れずに) Netscape Cookie との互換性について次のように規定していました。
Set-Cookie:
と Set-Cookie2:
の両方があれば、 Set-Cookie:
を捨てなければなりません >>352。Set-Cookie2:
があれば、起源鯖は RFC 2965
の Cookie:
を理解できるとみなさなければなりません >>352。Set-Cookie:
だけを受け取ったときは、 Netscape Cookie による Cookie:
頭欄に加え、 Cookie2:
頭欄も送るべきです >>352。[357] >>356 は新 Cookie による旧 Cookie の置き換えを命じていますが、 旧 Cookie による新 Cookie の置き換えには触れていません。
[370] Set-Cookie2:
は RFC 6265 により廃止されました >>369。
[306] [JavaHouse-Brewers:31373] Re: Cookie.setMaxAge() について ( 版) http://java-house.jp/ml/archive/j-h-b/031373.html
- Cookie.serVersion(1)としたクッキーを送信した場合、 Set-CookieとSet-Cookie2ヘッダの両方がクライアントに送信されていました。
- NN4.7とIE5では、Set-Cookie2ヘッダはサポートしていないようです。
[307] IRC logs: freenode / #whatwg / 20090808 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20090808#l-417
- [18:02] <abarth> annevk42: if you're interested in the cookie stuff, you should join the mailing list and comment on the charter
- [18:02] <abarth> annevk42: in general, i'm trying to keep the focus narrow
- [18:03] <abarth> annevk42: speccing cookie2 is going to take a lot more work and a lot more time than speccing cookie0
- [18:18] <annevk2> abarth, if you're going to spec cookies as implemented set-cookie2 is relevant, no?
- [18:18] <abarth> annevk2: depends how widely its used
- [18:18] <abarth> there was a recent message to the list
- [18:19] <abarth> that suggested very few sites use it
- [18:19] <abarth> i'm not sure we want to lock down the behavior of cookie2
- [18:19] <annevk2> hmm, if we could actually get impl to remove support for it that'd be cool
- [18:19] <abarth> which user agents implement it?
- [18:20] <annevk2> I thougt set-cookie2, not cookie2, was implemented, but maybe not
- [18:20] <abarth> i know they're in opera
- [18:20] <abarth> but i'm not sure where else
- [18:20] <annevk2> interesting
- [18:22] <annevk2> if we're the only ones by all means don't spec it or simply say it's obsolete
- [18:23] <annevk2> if we need extensions we can prolly extend cookie0 somehow once the processing model is written down
- [18:23] <abarth> i don't think we want to say it's obsolete. cookie suck in a number of ways. it would be good to have a long term plan for how to dig ourselves out of the mess
- [18:23] <abarth> yeah, that's a good point
- [18:23] <abarth> that's what 2109 originally tried to do with Version=1
- [18:24] <abarth> but i think they put the cart a bit in front of the horse
- [18:24] <annevk2> besides rough consensus you need running code :p
- [18:24] <annevk2> (also, versioning sucks :))
[330] RFC 2109、RFC 2965 は以下のようなキャッシュ制御に関する規定がありました >>331, >>332。
Set-Cookie
, Set-Cookie2
のキャッシュを防ぐため、Cache-Control: no-cache="set-cookie"や
Cache-Control: no-cache="set-cookie2"を指定するべきです。
Cache-Control: private
Cache-Control: must-revalidate, max-age=0
Cache-Control: proxy-revalidate, max-age=0
Cache-Control: max-age=0
Expires:
欄を含めなければなりません。
(HTTP/1.1 串は Cache-Control
を優先するので無視します。)Set-Cookie
, Set-Cookie2
を自分で付け足してはなりません >>42, >>43。[364] CGI::Cookie - search.cpan.org ( 版) http://search.cpan.org/~lds/CGI.pm-3.49/lib/CGI/Cookie.pm
Netscape Cookie 対応と銘打っていますが、 Max-Age
と
HttpOnly
にもちゃんと対応しています。
[365] CGI::Simple::Cookie - search.cpan.org ( 版) http://search.cpan.org/~andya/CGI-Simple-1.112/lib/CGI/Simple/Cookie.pm
Netscape Cookie と HttpOnly
に対応しています。
Max-Age
には対応していません。
[362] Servlet::Http::Cookie - search.cpan.org ( 版) http://search.cpan.org/~ix/libservlet-0.9.2/lib/Servlet/Http/Cookie.pm
この Perlモジュールは、 RFC 2109 に基づいた Cookie API を提供しています。 Netscape Cookie と RFC 2109 の両方に対応しているようで、既定値は Netscape Cookie になっています。
[366] Apache2::Cookie - search.cpan.org ( 版) http://search.cpan.org/~joesuf/libapreq2-2.12/glue/perl/lib/Apache2/Cookie.pm
Comment
、CommentURL
、
Expires
には対応していますが、 Port
、
Max-Age
、HttpOnly
には対応していません。謎な実装です。
[363] Mojo::Cookie::Response - search.cpan.org ( 版) http://search.cpan.org/~kraih/Mojolicious-0.999926/lib/Mojo/Cookie/Response.pm
この Perlモジュールは RFC 2965 の実装を名乗っています。
しかし CommentURL
には対応しておらず、 Expires
や HttpOnly
には対応しています (仕様違反?)。引用文字列は Port
属性でのみ使います (仕様違反)。(対象は欄本体だけなので、
Set-Cookie2:
にも Set-Cookie
にも使えるようです。)
[1] 苦い開発: クッキーの有効期限の更新 ( 版) http://bitter-development.blogspot.com/2007/07/blog-post.html
Apache2.2 と IE6 でsetcookie()で既存の同じ名前と値を設定する場合、有効期限(期間)は更新されない。 有効期限0で一旦セットしてから同じ有効期間をセットする。
setcookie($name, $name, 0); setcookie($name, $name, time()+60*60*24*365);
[367] Web Applications 1.0 r5486 Define http-equiv='set-cookie'Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=9578 ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5485&to=5486
[368] Apache HTTP Server Project ( ( 版)) http://httpd.apache.org/docs/1.3/misc/known_client_problems.html#cookie-merge
[383] HTTP::Cookies - search.cpan.org ( ( 版)) http://search.cpan.org/dist/HTTP-Cookies/lib/HTTP/Cookies.pm
[384] Apache2::Cookie - search.cpan.org ( ( 版)) http://search.cpan.org/dist/libapreq2/glue/perl/lib/Apache2/Cookie.pm
[385] KCP端末&SSLでクッキーが保存されない現象の覚書 - Kimura.Memo ( ( 版)) http://d.hatena.ne.jp/Kimura/20111210/p1
[386] co3k.org - Blog - 【情報求ム】au のガラケーで cookie が使えなくなる場合がある? ( ( 版)) http://co3k.org/blog/20
[387] Web Applications 1.0 r7414 Require Cookies and Origin if you implement HTTP. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7413&to=7414
[388] RFC 6787 - Media Resource Control Protocol Version 2 (MRCPv2) ( ( 版)) http://tools.ietf.org/html/rfc6787#section-6.2.15
[389] Bug 3420 – XMLHttpRequest does not handle set-cookie headers ( ( 版)) https://bugs.webkit.org/show_bug.cgi?id=3420
[390] Web Applications 1.0 r5486 Define http-equiv='set-cookie' ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5485&to=5486
[391] draft-ietf-http-state-mgmt-errata-00 - HTTP State Management Mechanism (Errata) ( ( 版)) https://tools.ietf.org/html/draft-ietf-http-state-mgmt-errata-00
[392] Apache HTTP Server Project ( ( 版)) http://httpd.apache.org/docs/1.3/misc/known_client_problems.html#cookie-merge
[393] RFC Errata Report ( ( 版)) http://www.rfc-editor.org/errata_search.php?rfc=4229
[53] Cookies Lack Integrity: Real-World Implications | USENIX ( 版) https://www.usenix.org/conference/usenixsecurity15/technical-sessions/presentation/zheng
[55] Remove the storage mutex due to lack of implementation · whatwg/html@1b918cf ( 版) https://github.com/whatwg/html/commit/1b918cf72fcbba011f83b92ab5d1f483fb1cafa3
[56] Update integration with Encoding Standard · whatwg/html@6a31c26 ( 版) https://github.com/whatwg/html/commit/6a31c26cf12e39dab1a488e75dd56c03d6786d39
[57] Clarify the hooks into RFC6265 · whatwg/fetch@5a324a8 ( 版) https://github.com/whatwg/fetch/commit/5a324a891c42d42de09a01e03c3a063b9a4f882b
[58] Get multiple headers as an aray rather than a combined value? · Issue #506 · whatwg/fetch () https://github.com/whatwg/fetch/issues/506
block-cookies
The engine strips all cookies from the header before sending the request to the server. Safari's own privacy policy takes precedence, so that only cookies that would otherwise be accepted by the privacy policy can be blocked.
[69] Should "set response's CSP list" be in Main fetch? · Issue #364 · whatwg/fetch () https://github.com/whatwg/fetch/issues/364
[70] <meta http-equiv=set-cookie> is now a no-op (annevk著, ) https://github.com/whatwg/html/commit/9c135397caed7dd1a23d94ef43dcb372f89f853d
[71] <meta http-equiv=Set-Cookie> should do nothing if document is cookie averse · Issue #1950 · whatwg/html () https://github.com/whatwg/html/issues/1950
[72] Restrict <meta http-equiv=set-cookie> by annevk · Pull Request #3011 · whatwg/html () https://github.com/whatwg/html/pull/3011
[73] Remove <meta http-equiv=set-cookie> · Issue #3076 · whatwg/html () https://github.com/whatwg/html/issues/3076
[74] Block `<meta http-equiv="set-cookie" ...>` by chromium-wpt-export-bot · Pull Request #8531 · w3c/web-platform-tests () https://github.com/w3c/web-platform-tests/pull/8531
[75] Make <meta http-equiv=set-cookie> into a no-op by annevk · Pull Request #3649 · whatwg/html () https://github.com/whatwg/html/pull/3649
[76] Clarify how Headers does not support Set-Cookie (annevk著, ) https://github.com/whatwg/fetch/commit/7ab665e05e894f81d8ca741f7e7c19a334d88c08
[77] The comma-delimited combined value definition does not support Set-Cookie headers · Issue #345 · whatwg/fetch () https://github.com/whatwg/fetch/issues/345
[78] Clarify how Headers does not support Set-Cookie by annevk · Pull Request #714 · whatwg/fetch () https://github.com/whatwg/fetch/pull/714
[79] Note that cookies take effect despite CORS failures (Osintopsec著, ) https://github.com/whatwg/fetch/commit/d219389264742ce9bb3411601f680f54a77e2f3a
[80] Doc: failed CORS fetch with credentials should ignore Set-Cookie response header · Issue #855 · whatwg/fetch () https://github.com/whatwg/fetch/issues/855
[81] Change 3.2.6 Examples to reflect current state of implementations by Osintopsec · Pull Request #858 · whatwg/fetch () https://github.com/whatwg/fetch/pull/858
[83] Chrome80以降でALBの認証を使っているとcookieが4096バイトを超えて認証できないことがあり、社内サービスではcookie名を縮めて対応した - hitode909の日記 () https://blog.sushi.money/entry/2020/02/17/105927
[87] 3512 – REGRESSION (312-412): Can't log in to web mail site in Safari - www.spray.se () https://bugs.webkit.org/show_bug.cgi?id=3512