What is a host only cookie?
What is a host only cookie?
First of all, it is not possible for foo.com
to set a cookie that can be read by bar.com
. Host-only
only protects example.com
cookies from being read by bar.example.com
.
From RFC 6265 regarding setting a cookie and its Domain
attribute:
If the domain-attribute is non-empty:
If the canonicalized request-host does not domain-match the domain-attribute:
Ignore the cookie entirely and abort these steps.
Otherwise:
Set the cookie's host-only-flag to false.
Set the cookie's domain to the domain-attribute.
Otherwise:
Set the cookie's host-only-flag to true.
Set the cookie's domain to the canonicalized request-host.
What this means
The above can be summed up by "Host-only is the default". That is, if Domain
is not specified, the cookie can only be read by the exact domain that has set the cookie. This can be loosened by setting the Domain
attribute when setting a cookie.
For example, if the cookie is set by www.example.com
and the Domain
attribute is not specified, the cookie will be set with domain www.example.com
and the cookie will be a host only cookie.
Another example: If the cookie is set by www.example.com
and the Domain
attribute is specified as example.com
(so the cookie will be sent to foo.example.com
too), the cookie will be set with domain example.com
(or possibly .example.com
by some browsers that use the dot from the previous RFC 2109 to denote not host-only) and the cookie will not be a host only cookie.
Sending of cookies is covered in section 5.4 regarding the when the cookie header is sent by the browser:
The cookie's host-only-flag is true and the canonicalized
request-host is identical to the cookie's domain.
Or:
The cookie's host-only-flag is false and the canonicalized
request-host domain-matches the cookie's domain.
So a cookie with domain example.com
and host-only
as false is sent to foo.example.com
. If host-only is true, the example.com
cookie is sent to example.com
only.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-06-18 sqlmap
2020-06-18 C# Type Comparison: Type.Equals vs operator ==
2020-06-18 What does “Use of unassigned local variable” mean?
2020-06-18 Interface Definition Language
2019-06-18 538. Convert BST to Greater Tree