How do browser cookie domains work?
https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work
答案一
Although there is the RFC 2965 (Set-Cookie2, had already obsoleted RFC 2109) that should define the cookie nowadays, most browsers don’t fully support that but just comply to the original specification by Netscape.
There is a distinction between the Domain attribute value and the effective domain: the former is taken from the Set-Cookie header field and the latter is the interpretation of that attribute value. According to the RFC 2965, the following should apply:
- If the Set-Cookie header field does not have a Domain attribute, the effective domain is the domain of the request.
- If there is a Domain attribute present, its value will be used as effective domain (if the value does not start with a
.it will be added by the client).
Having the effective domain it must also domain-match the current requested domain for being set; otherwise the cookie will be revised. The same rule applies for choosing the cookies to be sent in a request.
Mapping this knowledge onto your questions, the following should apply:
- Cookie with
Domain=.example.comwill be available for www.example.com - Cookie with
Domain=.example.comwill be available for example.com - Cookie with
Domain=example.comwill be converted to.example.comand thus will also be available for www.example.com - Cookie with
Domain=example.comwill not be available for anotherexample.com - www.example.com will be able to set cookie for example.com
- www.example.com will not be able to set cookie for www2.example.com
- www.example.com will not be able to set cookie for .com
And to set and read a cookie for/by www.example.com and example.com, set it for .www.example.com and .example.com respectively. But the first (.www.example.com) will only be accessible for other domains below that domain (e.g. foo.www.example.com or bar.www.example.com) where .example.com can also be accessed by any other domain below example.com (e.g. foo.example.com or bar.example.com).
答案二
The previous answers are a little outdated.
RFC 6265 was published in 2011, based on the browser consensus at that time. Since then, there has been some complication with public suffix domains. I've written an article explaining the current situation - http://bayou.io/draft/cookie.domain.html
To summarize, rules to follow regarding cookie domain:
The origin domain of a cookie is the domain of the originating request.
If the origin domain is an IP, the cookie's domain attribute must not be set.
If a cookie's domain attribute is not set, the cookie is only applicable to its origin domain.
If a cookie's domain attribute is set,
- the cookie is applicable to that domain and all its subdomains;
- the cookie's domain must be the same as, or a parent of, the origin domain
- the cookie's domain must not be a TLD, a public suffix, or a parent of a public suffix.
It can be derived that a cookie is always applicable to its origin domain.
The cookie domain should not have a leading dot, as in .foo.com - simply use foo.com
As an example,
x.y.z.comcan set a cookie domain to itself or parents -x.y.z.com,y.z.com,z.com. But notcom, which is a public suffix.- a cookie with domain=
y.z.comis applicable toy.z.com,x.y.z.com,a.x.y.z.cometc.
Examples of public suffixes - com, edu, uk, co.uk, blogspot.com, compute.amazonaws.com
How do browser cookie domains work?的更多相关文章
- Browser Cookie Limits
w https://cait.calarts.edu/hc/en-us/articles/217055138-Error-Maximum-Number-of-Cookie-Values-Reached ...
- Google上的Cookie Matching
Cookie Matching This guide explains how the Cookie Matching Service enables you to make more effecti ...
- Browser security standards via access control
A computing system is operable to contain a security module within an operating system. This securit ...
- IE/Firefox/Chrome等浏览器保存Cookie的位置
IE/Firefox/Chrome等浏览器保存Cookie的位置 原文 http://smilejay.com/2013/04/browser-cookie-location/ 前面写了篇长文( ...
- Network | Cookie and Session
Cookies are arbitrary pieces of data chosen by the web server and sent to the browser. The browser r ...
- 【PC网站前端架构探讨系列】关于中小型PC网站前端架构方案的讨论与实践
目 录 1.遇到的问题 2.目标 3.探讨 4.架构设想 5.流程 6.初步实现 7.存在问题 8.最后 遇到的问题 我在这个系列上篇文章 已经讲解并开始逐步应用模块化思想,不知大家还记不记得,题 ...
- Technical analysis of client identification mechanisms
http://www.chromium.org/Home/chromium-security/client-identification-mechanisms Chromium > Chro ...
- Drupal启动阶段之一:配置
配置是Drupal启动过程中的第一个阶段,通过函数_drupal_bootstrap_configuration()实现: function _drupal_bootstrap_configurati ...
- Android安全之Intent Scheme Url攻击
0X01 前言 Intent scheme url是一种用于在web页面中启动终端app activity的特殊URL,在针对intent scheme URL攻击大爆发之前,很多android的浏览 ...
随机推荐
- CAD在一个点构造选择集
主要用到函数说明: IMxDrawSelectionSet::SelectAtPoint 在一个点构造选择集.详细说明如下: 参数 说明 [in] IMxDrawPoint* point 点坐标 [i ...
- EF-基础用法
一丶LINQ TO SQL 语法 基本格式: from c in 表名 where 条件 select c 二丶LINQ简介 LINQ是Language Integrated Query的简称,它是 ...
- spring aop 内部调用问题解决
方法1: 基于 proxy 的 spring aop 带来的内部调用问题可以使用 AopContext.currentProxy() 强转为当前的再调用就可以解决了 例如: 错误用法:public A ...
- Spring Boot 与任务
一.任务 1.异步任务 package com.yunche.task.service; import org.springframework.stereotype.Service; /** * @C ...
- 真机测试报错ERROR/AndroidRuntime: java.lang.RuntimeException: setParameters failed解决办法
这个错误是和调用相机摄像头相关的. 产生这个错误的原因主要在于代码控制分辨率的显示和真机测试分辨率不一样. 一:解决办法 WindowManager wm = (WindowManager) getS ...
- dorado 7 使用总结
最近项目上需要,使用了dorado 7 ,总体感觉还可以,快速开发很方便,然而在方便的同时,难免有些太过繁琐,很多东西都封装了起来,会造成很多不便.因此快速开发的项目可以使用,其它的不推荐.现在打算将 ...
- 多校1007 Naive Operations
>>点击进入原题测试<< 思路:好像是第一次这么印象深刻的写线段树,说实话,这个题确实很有意思,值得学习. 看了大神讲解视频,但是自己写的还是超时了. 参考来自 https:/ ...
- 常量Constant
常量通常指的是一个固定的值,例如:1.2.3.’a’.’b’.true.false.”helloWorld”等. 在Java语言中,主要是利用关键字final来定义一个常量. 常量一旦被初始化后不能再 ...
- How Can You Tell the Difference Between LINQ Methods and Query Builder Methods?
LINQ's method syntax looks very similar to the query builder methods,except for one big difference:t ...
- mysql 查询出的数组为null怎么转换成0
mysql 查询出的数组为null怎么转换成0 IFNULL(b.dayPay,0) as yesterdayPay,