浅谈Js 操作Cookie,以及HttpOnly 的限制

. Js 操作 Cookie.

一般来说,只有服务器操作Cookie 才能保证一些必要的安全。但有时候,可能需要前端来增删改查 Cookie, 这个时候咱们的主角出现了——HttpOnly(๑•̀ㅂ•́) ✧.

HttpOnly: 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).

来着谷歌翻译:

HttpOnly是包含在Set-Cookie HTTP响应头文件中的附加标志。生成cookie时使用HttpOnly标志有助于降低客户端脚本访问受保护cookie的风险(如果浏览器支持)。

这个意思就是说,如果某一个Cookie 选项被设置成 HttpOnly = true 的话,那此Cookie 只能通过服务器端修改,Js 是操作不了的,对于 document.cookie 来说是透明的。话不多说,直接上图:



image


console里面输入

document.cookie
"wd=1922x912; c_user=1201711570"

可以看到只能看到非httpOnly的

posted on 2020-05-29 15:29  katago  阅读(9544)  评论(0编辑  收藏  举报