- 浏览: 164754 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
小灯笼:
RabbitMQ实战:分布式消息队列高效部署及插件集群开发信息 ...
MQ(一) rabbitmq -
快乐的小六:
分布式消息队列高效部署及插件集群开发信息数据监控、分析实战(R ...
MQ(一) rabbitmq -
lgxjob:
spring schema -
h416373073:
博主写的用心,多谢分享
spring schema -
司马饮之:
顶一个
try catch finally 关闭流标准的写法
随记Cookie
先看源码
第一 与Session的比较
十年前还单机处理业务,集群还不多的时候,Session用的还比较多,现在随便个服务都集群部署,考虑到多节点内存同步,都不太使用session。http是无状态的,保留用户信息用,采用session会话。网上资料太多,不再赘述。
第二 API
太简单,不再赘述
第二 属性信息
属性:name value
有人把cookie理解成map,name 相当key, value 相当 map里的value.
但本身Cookie是个数组。是个Cookie[]
所以这个key是可以重复的。但又经常把cookie当成map使用,所以建议把cookie操作封装下。
属性 comment
就是存储key value 的描述。没什么特别的。
属性 maxAge
cookie的生命周期,默认-1,即关闭浏览器,cookie失效。
单位是??,大于零,即使cookie关闭,cookie依然生效。
属性 version
int ASSIC 数值,准照RFC 标准。
RFC文件是纯ASCII文字档格式
RFC https://zh.wikipedia.org/wiki/RFC#RFC.E6.96.87.E4.BB.B6.E7.9A.84.E6.9E.B6.E6.A7.8B
属性 path
不瞎逼逼了,附上源码描述把
最后讲的属性 domain
参考文档:http://blog.csdn.net/alexxu1988/article/details/47805205
domain的知识点比较多。
最后一点
cookie 是不安全的
cookie是可以篡改,模拟的。因为是在客户端,之前我本地模拟了A站点的cookie, 用这个cookie是可以直接供真正的A站点使用的。那为什么还要用cookie.方便呀。
建议cookie存放的信息不是敏感信息,像密码这类东西就不要考虑放到cookie.存放的token 后台也要加个校验。cookie攻击的技术门槛是很低的。
先看源码
/** * * Creates a cookie, a small amount of information sent by a servlet to * a Web browser, saved by the browser, and later sent back to the server. * A cookie's value can uniquely * identify a client, so cookies are commonly used for session management. * * <p>A cookie has a name, a single value, and optional attributes * such as a comment, path and domain qualifiers, a maximum age, and a * version number. Some Web browsers have bugs in how they handle the * optional attributes, so use them sparingly to improve the interoperability * of your servlets. * * <p>The servlet sends cookies to the browser by using the * {@link HttpServletResponse#addCookie} method, which adds * fields to HTTP response headers to send cookies to the * browser, one at a time. The browser is expected to * support 20 cookies for each Web server, 300 cookies total, and * may limit cookie size to 4 KB each. * * <p>The browser returns cookies to the servlet by adding * fields to HTTP request headers. Cookies can be retrieved * from a request by using the {@link HttpServletRequest#getCookies} method. * Several cookies might have the same name but different path attributes. * * <p>Cookies affect the caching of the Web pages that use them. * HTTP 1.0 does not cache pages that use cookies created with * this class. This class does not support the cache control * defined with HTTP 1.1. * * <p>This class supports both the Version 0 (by Netscape) and Version 1 * (by RFC 2109) cookie specifications. By default, cookies are * created using Version 0 to ensure the best interoperability. * * * @author Various */ // XXX would implement java.io.Serializable too, but can't do that // so long as sun.servlet.* must run on older JDK 1.02 JVMs which // don't include that support. public class Cookie implements Cloneable { private static final String LSTRING_FILE = "javax.servlet.http.LocalStrings"; private static ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE); // // The value of the cookie itself. // private String name; // NAME= ... "$Name" style is reserved private String value; // value of NAME // // Attributes encoded in the header's cookie fields. // private String comment; // ;Comment=VALUE ... describes cookie's use // ;Discard ... implied by maxAge < 0 private String domain; // ;Domain=VALUE ... domain that sees cookie private int maxAge = -1; // ;Max-Age=VALUE ... cookies auto-expire private String path; // ;Path=VALUE ... URLs that see the cookie private boolean secure; // ;Secure ... e.g. use SSL private int version = 0; // ;Version=1 ... means RFC 2109++ style
第一 与Session的比较
十年前还单机处理业务,集群还不多的时候,Session用的还比较多,现在随便个服务都集群部署,考虑到多节点内存同步,都不太使用session。http是无状态的,保留用户信息用,采用session会话。网上资料太多,不再赘述。
第二 API
太简单,不再赘述
第二 属性信息
属性:name value
有人把cookie理解成map,name 相当key, value 相当 map里的value.
但本身Cookie是个数组。是个Cookie[]
所以这个key是可以重复的。但又经常把cookie当成map使用,所以建议把cookie操作封装下。
属性 comment
就是存储key value 的描述。没什么特别的。
属性 maxAge
cookie的生命周期,默认-1,即关闭浏览器,cookie失效。
单位是??,大于零,即使cookie关闭,cookie依然生效。
属性 version
int ASSIC 数值,准照RFC 标准。
RFC文件是纯ASCII文字档格式
RFC https://zh.wikipedia.org/wiki/RFC#RFC.E6.96.87.E4.BB.B6.E7.9A.84.E6.9E.B6.E6.A7.8B
属性 path
不瞎逼逼了,附上源码描述把
* Specifies a path for the cookie * to which the client should return the cookie. * * <p>The cookie is visible to all the pages in the directory * you specify, and all the pages in that directory's subdirectories. * A cookie's path must include the servlet that set the cookie, * for example, <i>/catalog</i>, which makes the cookie * visible to all directories on the server under <i>/catalog</i>. * * <p>Consult RFC 2109 (available on the Internet) for more * information on setting path names for cookies.
最后讲的属性 domain
参考文档:http://blog.csdn.net/alexxu1988/article/details/47805205
* Specifies the domain within which this cookie should be presented. * * <p>The form of the domain name is specified by RFC 2109. A domain * name begins with a dot (<code>.foo.com</code>) and means that * the cookie is visible to servers in a specified Domain Name System * (DNS) zone (for example, <code>www.foo.com</code>, but not * <code>a.b.foo.com</code>). By default, cookies are only returned * to the server that sent them.
domain的知识点比较多。
最后一点
cookie 是不安全的
cookie是可以篡改,模拟的。因为是在客户端,之前我本地模拟了A站点的cookie, 用这个cookie是可以直接供真正的A站点使用的。那为什么还要用cookie.方便呀。
建议cookie存放的信息不是敏感信息,像密码这类东西就不要考虑放到cookie.存放的token 后台也要加个校验。cookie攻击的技术门槛是很低的。
发表评论
-
软件移植
2022-01-30 20:17 0此篇是工作随笔: 基础原理: 1、OS所处的 ... -
信号量与PV java
2018-01-02 15:11 1046进程间通信: 进程通常 ... -
http资料整理
2017-09-25 11:11 630http://blog.csdn.net/java199366 ... -
ACL权限管理
2017-09-19 10:56 2436ACL : access control list 访问权限管 ... -
JVM
2017-05-02 17:47 601http://blog.csdn.net/java199366 ... -
dubbo升级dubbox
2016-11-09 14:59 5997笔者公司部分应用用dubbo暴露服务,随着一些新人加盟,很多 ... -
spring 懒加载与dubbo 客户端校验
2016-09-19 18:41 2898Dubbo的启动时服务依赖检查是,对象实例化时,判断远程调用是 ... -
标识接口
2015-01-13 14:26 694摘要:标识接口是没有任何方法和属性的接口.它仅仅表明它的类属于 ... -
排序算法
2014-12-25 16:26 631package a; public class So ... -
java 序列化
2014-11-26 15:02 1040java序列化,是把对象序列化成流,转成流的目的是为了网络传输 ... -
java SPI
2014-11-19 17:30 623Java的SPI http://singleant.iteye ... -
JAR 文件包
2014-11-19 16:19 744JAR 文件就是 Java Archive File,顾名思意 ... -
hadoop
2014-10-15 17:09 1131hadoop官方网站: http://hadoop.apach ... -
JMX
2013-07-26 11:06 608http://docs.oracle.com/javase/7 ... -
分布式事务
2013-07-17 13:57 1718JTA 与 JTS 区别 一. 链 ... -
AJAX
2013-07-07 10:08 945一. AJAX 注意事项 (1)XHR不会修改浏览器历史栈,即 ... -
相等测试equals
2013-06-24 10:29 729Object类是Java中所有类的 ... -
随记小知识点
2013-06-21 10:44 7721. 字符串 从概念上讲,java字条串就是Unicode字符 ... -
Memcache
2013-02-16 17:36 714Memcache windows http://www.cn ... -
MQ(一) rabbitmq
2012-07-23 12:20 21540rabbit mq 与JMS MQ的消费-生产者模型的一个典型 ...
相关推荐
在PHP中浅谈Cookie与Session.pdf
cookie,简单的理解。就是存储数据。通过cookie,数据可以长期保存,不随着浏览器的关闭而消失。 本文有助于初学者加深对cookie的理解,个人总结,不足之处欢迎随时交流。
一、cookie介绍 cookie 常用于识别用户。cookie 是服务器留在用户计算机中的小文件。每当相同的计算机通过浏览器请求页面时,它同时会发送 cookie。通过 PHP,您能够创建并取回 cookie 的值。 1、设置Cookie PHP用...
下面小编就为大家带来一篇浅谈Cookie的生命周期问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
下面小编就为大家带来一篇浅谈PHP Cookie处理函数。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
在服务端程序开发的过程中,cookie经常被用于验证用户登录。golang 的 net/http 包中自带 http cookie的定义,下面就来讲一下cookie的一般用法以及需要注意的问题。 http cookie的定义 先来看下golang对cookie结构体...
下面小编就为大家带来一篇浅谈cookie 和session 的区别。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了浅谈cookie和session(小结),cookie和session在java web开发中扮演了十分重要的作用,本篇文章对其中的重要知识点做一些探究和总结
一、localStorage、cookie、sessionStorage的区别与练习 1、cookie 小甜饼。它的大小限制为4KB左右,是网景公司的前雇员 Lou Montulli 在1993年3月的发明。它的主要用途有保存登录信息,比如你登录某个网站市场可以...
padding oracle攻击详解。
浅谈网络安全防护技术 摘要:随着计算机网络应用的广泛深入.网络安全问题变得日益复杂和突出。目前计 算机病毒技术和黑客技术的融合,使得计算机所受到的威胁更加难以预料。本文从常见 的网络安全防护方法入手,...
session一定要用httponly的否则可能被xxs攻击,利用js获取cookie的session_id。 要用框架的ci_session,更长的位数,httponly,这些默认都配好了。 不要用原生的phpsession,而要用ci_session。ci_session位数更长。...
本篇文章主要介绍了css sticker-footer 布局,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
一个网站一旦涉及到多用户, 就很难从 Cookies 中逃脱, Vue SSR 的 cookies 也真算是遇到的一个不小的问题, 从开始玩 SSR 开始到现在, 一共想出了3种方案, 从最早的把 Cookies 注入到 state 中, 到把 Cookies 注入到 ...
C# HttpHelper,帮助类,真正的Httprequest请求时无视编码,无视证书,无视Cookie,网页抓取 1.第一招,根据URL地址获取网页信息 先来看一下代码 get方法 public static string GetUrltoHtml(string Url,string ...
一个登录的场景,用axios发送post请求去登录,能成功返回数据,但是用作权限验证的cookie就是没有保存,经查阅,axios 默认不发送cookie,跨域也是一个原因,需要全局设置 所以我们需要这么设置 axios.defaults....