`

有关cookie的httponly属性相关

 
阅读更多

先记录下相关网上的链接,有时间自己再总结一份自己的理解

 

http://en.wikipedia.org/wiki/HTTP_cookie

 

http://www.cnblogs.com/downmoon/archive/2008/09/11/1289298.html

 

http://msdn.microsoft.com/zh-cn/library/system.web.httpcookie.httponly.aspx

 

http://msdn.microsoft.com/zh-cn/library/ms533046(vs.85).aspx

 

http://www.storyday.com/html/y2008/2120_javascript-and-httponly-cookies.html

 

对于很多只依赖于cookie验证的网站来说,HttpOnly cookies是一个很好的解决方案,在支持HttpOnly cookies的浏览器中(IE6以上,FF3.0以上),javascript是无法读取和修改HttpOnly cookies,或许这样可让网站用户验证更加安全。

wikipedia中对于httpOnly的描述如下:

`HttpOnly’:

Set-Cookie: RMID=732423sdfs73242; expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; domain=.example.net; HttpOnly

When the browser receives such a cookie, it is supposed to use it as usual in the following HTTP exchanges, but not to make it visible to client-side scripts.[21] The `HttpOnly` flag is not part of any standard, and is not implemented in all browsers. Note that there is currently no prevention of reading or writing the session cookie via a XMLHTTPRequest.[36]

所以,若是网站基于cookie而非服务器端的验证,请最好加上HttpOnly,当然,目前这个属性还不属于任何一个标准,也不是所有的浏览器支持,另外知名的wordpress程序也已经更改了cookie的属性为httpOnly。

javascript无法读取HttpOnly cookies,若想在js中获取cookie的属性该如何处理呢?

cosbeta也没有什么比较好的办法,所以只有告诉大家都绝招:还得动用服务器端脚本读出cookie,然后用输出js代码,或者用ajax去获取服务器端程序读出的cookie值。

于是cos-html-cache因此升级了。

 

----------------------------------------------------

 

https://www.owasp.org/index.php/HTTPOnly

 

这个链接介绍的很详细:摘抄如下

 

The goal of this section is to introduce, discuss, and provide language specific mitigation techniques for HttpOnly.

Who developed HttpOnly? When?

According to a daily blog article by Jordan Wiens, “No cookie for you!,” HttpOnly cookies were first implemented in 2002 by Microsoft Internet Explorer developers for Internet Explorer 6 SP1. Wiens, [1]

What is HttpOnly?

According to the Microsoft Developer Network, HttpOnly is an additional flag included in a Set-Cookie HTTP response header. Using the HttpOnly flag when generating a cookie helps mitigate the risk of client side script accessing the protected cookie (if the browser supports it).

  • The example below shows the syntax used within the HTTP response header:
Set-Cookie: <name>=<value>[; <Max-Age>=<age>]
[; expires=<date>][; domain=<domain_name>]
[; path=<some_path>][; secure][; HttpOnly]

If the HttpOnly flag (optional) is included in the HTTP response header, the cookie cannot be accessed through client side script (again if the browser supports this flag). As a result, even if a cross-site scripting (XSS) flaw exists, and a user accidentally accesses a link that exploits this flaw, the browser (primarily Internet Explorer) will not reveal the cookie to a third party.

If a browser does not support HttpOnly and a website attempts to set an HttpOnly cookie, the HttpOnly flag will be ignored by the browser, thus creating a traditional, script accessible cookie. As a result, the cookie (typically your session cookie) becomes vulnerable to theft of modification by malicious script. Mitigating, [2]

Mitigating the Most Common XSS attack using HttpOnly

According to Michael Howard, Senior Security Program Manager in the Secure Windows Initiative group at Microsoft, the majority of XSS attacks target theft of session cookies. A server could help mitigate this issue by setting the HTTPOnly flag on a cookie it creates, indicating the cookie should not be accessible on the client.

If a browser that supports HttpOnly detects a cookie containing the HttpOnly flag, and client side script code attempts to read the cookie, the browser returns an empty string as the result. This causes the attack to fail by preventing the malicious (usually XSS) code from sending the data to an attacker's website. Howard, [3]

Using Java to Set HttpOnly

Sun Java EE supports HttpOnly flag in Cookie interface since version 6 (Servlet class version 3)[4], also for session cookies (JSESSIONID)[5]. Methods setHttpOnly and isHttpOnly can be used to set and check for HttpOnly value in cookies.

For older versions there the workaround is to rewrite JSESSIONID value using and setting it as a custom header[6].

String sessionid = request.getSession().getId();
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; HttpOnly");

In Tomcat 6 flag useHttpOnly=True in context.xml to force this behaviour for applications[7], including Tomcat-based frameworks like JBoss[8].

Servlet 3.0 (Java EE 6) introduced a standard way to configure HttpOnly attribute for the session cookie, this can be done by applying the following configuration in web.xml

<session-config>
 <cookie-config>
  <http-only>true</http-only>
 </cookie-config>
<session-config>

 

 

目前发现tomcat6的该属性缺省是false,在context.xml里配置,weblogic10.3.1,10.3.2不支持该属性的配置,只能编码写,weblogic10.3.3,

10.3.4,10.3.5支持在weblogic.xml里配置该属性,切缺省值为true

 

JAVAEE从6.0支持专门的setHttpOnly和isHttpOnly方法,即servlet3.0规范中添加了这两个方法得API,在此以前的版本只能用response.setHeader("SET-COOKIE,...")的方式来支持,另外还需要看浏览器对httpOnly的支持,IE从6开始支持,其它版本在上面引入的链接里写的很清楚。

分享到:
评论
1 楼 xuxiaoyinliu 2015-11-30  
谢谢,不错哦

相关推荐

    Session Cookie的HttpOnly和secure属性

    首先,secure属性是防止信息在传递的过程中被监听捕获后信息泄漏,HttpOnly属性的目的是防止程序获取cookie后进行攻击。 其次,GlassFish2.x支持的是servlet2.5,而servlet2.5不支持Session Cookie的"HttpOnly"属性...

    cookie设置httpOnly和secure属性实现及问题

    该文档整合了cookie的httponly和secure的简介,已经设置该属性时会遇到的问题,以及设置属性的方式

    PHP设置Cookie的HTTPONLY属性方法

    下面小编就为大家带来一篇PHP设置Cookie的HTTPONLY属性方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击.zip_js设置cookie值

    java后台和php后台如何设置HttpOnly到前台浏览器的cookie中.cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击.zip

    mvc中cookie安全

    在mvc中验证如何存取cookie,并通过cookie的httponly属性防止cookie被jquery脚本窃取。

    session配置secure和httpOnly

    本文档描述了关于cookie的http-only和secure的简介,和如何设置该属性,以及设置该属性会遇到的问题解决方法

    js操作cookie

    这是一个封装好的js对象函数,用于对cookie的增删改查。

    Web应用安全:XSS的辅助性对策.pptx

    浏览器将禁止页面的JavaScript访问带有HttpOnly属性的Cookie。也就是说HttpOnly是为了对抗XSS后的Cookie劫持。 HttpOnly是在Set-Cookie时被标记的。服务器可能会设置多个Cookie,而HttpOnly可以有选择性地加在任何一...

    饼干

    HttpOnly属性) 同一站点的cookie(属性SameSite的值可以为Strict,Lax或None) 第三方Cookie(横幅广告) 执行 设置或更新cookie,在HTTP响应中使用Set-Cookie标头 读取cookie使用HTTP请求中的Cookie标头 删除...

    网站的安全架构

    因为恶意脚本中有一些特殊字符,可以通过转义的方式来进行防范-HttpOnly对cookie添加httpOnly属性则脚本不能修改cookie。就能防止恶意脚本篡改cookieSQL注入攻击需要攻击者对数据库结构有所了解才能进行,攻击者获取...

    带你了解web的本地储存

    5.1 设置5.1.1 客户端设置5.1.2 服务器端设置5.2 读取5.3 修改 cookie5.4 删除5.5注意6、cookie的属性(可选项)6.1过期时间7、cookie的域概念(domain选项)7.1客户端设置7.1服务端设置8、cookie的路径概念(path...

    learn-cookie-in-depth:文章的源代码

    用于提供API并演示相同的原始Cookie用法一个React前端项目,以演示跨源Cookie使用的问题测试案例测试从服务器端获取cookie 测试在客户端通过javascript生成Cookie 测试所有Cookie属性最大年龄安全的httpOnly-需要...

    CyberDragon Browser:Cyber​​Dragon Browser - 隐私增强的便携式浏览器-开源

    默认情况下,只允许设置了 Secure 和 HttpOnly cookie 属性的会话 cookie。 此外,默认情况下会阻止所有 3rd 方 cookie。 这些设置可以被站点覆盖,阻止或允许特定的 cookie,允许非常细粒度的 cookie 控制。 - ...

    会话:Express的简单会话中间件

    表达会议 安装 这是通过提供的模块。 使用完成 : $ npm install express-session API var session = require ( 'express-session' ) ... 默认值为{ path: '/', httpOnly: true, secure: false, maxAge: null }

    secure_headers:使用许多安全默认值管理安全头的应用

    它还可以使用Secure,HttpOnly和SameSite属性标记所有http cookie。 这是默认设置,但可以使用config.cookies = SecureHeaders::OPT_OUT 。 secure_headers是一个具有全局配置,每个请求覆盖和机架

    TOWCMS乐酷三合一建站程序 v7.3.zip

    6.[增加]给cookie添加httponly支持,减少XSS攻击 7.[优化]infolist标签增加省/市/区县/乡镇4筛选属性 8.[增加]增加arealist省/市/区县/乡镇标签 9.[增加]会员后台订单管理集成物流查询功能,可以实时查看当前物流...

Global site tag (gtag.js) - Google Analytics