对于很多只依赖于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因此升级了。
标签:javascript
曲线救国额,呵呵