Login Cookie
其實我一直在想像 Google 或 手機王 記得我 功能要怎麼作,只是我一直沒有恰當的關鍵字可以去搜尋,從 HTTP Request 去看又看不出所以然。
今天在找有關 Cookie 的資料時恰好看到 [把 NoScript 移除] 裡面提到 login cookie這個關鍵字,用它去找,果然找到了不錯的東西。
首先是這篇1 詳細地提到一個漂亮解法來達成記憶使用者登入,而且又避免了密碼洩漏的危險,首先關於這個功能有幾個前提
- Cookie 是危險的,有許多漏洞、攻擊都可能洩漏 cookie 裡的資訊。
- Persistent login cookies 是足以取代 username/password 來作認證及登入的功能
- Users reuse passwords. Hence, any login cookie from which you can recover the user’s password holds significantly more potential for harm than one from which you can not. (看不太懂)
- 將 cookie 的使用限定在某個特定 IP 反而會限制了 persistent cookie 的功用。
- 使用者希望 persistent cookie 可以同時在多個不同的 browser或機器上使用。
而他所提出的作法如下:
- 當使用者利用帳號/密碼登入時,產生 account name/random token pair 並儲存到資料庫及使用者的電腦(Cookie)中
- 下次當使用者開啟網站時,Browser會傳送 Cookie 給 Server,檢查 Login Cookie 是否有效
- 有效 – 登入成功,並產生新的 token以供下次使用
- 無效 – 忽略 Login Cookie,當成是新的使用者
- 基於安全考量,使用 Login Cookie 的 Session必須被限制使用某些功能,例如修改密碼、檢視/修改使用者個人資訊(包括email,因為可以被拿來重設密碼)、刷卡/付費,要使用這些被限制的功能,必須再明確使用密碼登入。
- 當使用者登出(logout)時,目前使用的 token 同時也失效。
- 可以提供一個選項,讓使用者移除自己目前所有的 token。
- 一個使用者可以擁有許多 token ,所以可以同時在許多電腦上運作。
- 萬一某個 token 被洩漏,也只會有一個駭客可以拿來作較低程度的傷害,危害並不會擴散。
這個方法,看起來已經很棒了,但還是有缺點,而且有人又提出更好的方法來改善2
原本的作法缺點是當 token 洩漏以後,駭客可能持續使用這組 token 以及其後的新 token 來登入。而使用者下次登入時會因為 token 失效,而發現需要重新以密碼登入,但使用者通常不會在意原因,即使可以用 Last Login Info 來檢查,但這項資訊通常會被忽視。
而在新的作法裡,多加了一個 series identifier 到 Login Cookie 中,並限制每組 account name/series identifier 只有一組 token 可以使用。
明確的作法如下:
- 當使用者利用帳號/密碼登入時,產生 account name/series identifier/random token pair 並儲存到資料庫及使用者的電腦(Cookie)中
- 下次當使用者開啟網站時,Browser會傳送 Cookie 給 Server,檢查 Login Cookie 是否有效
- The triple is present – 登入成功,並產生新的 token以供下次使用
- account name/series identifier are present, but token does not match – 表示極可能有非法駭客使用這組 Cookie 登入過了,用明顯的訊息提示使用者,並且清除該使用者所有的 session
- account name/series identifier are not present – 忽略 Login Cookie,當成是新的使用者
新的作法除了包含原本的作法的優點以外,還具有
- 駭客得到了 Login Cookie 只能使用到使用者下次登入的時候,原本的作法他可以一直無限制使用。
- 使用者可以明確被提示說 『Something is wrong』
漂亮的作法
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
Leave a Reply