淺談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的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM