將敏感數據存儲在永久性的 cookie 中可能導致違反保密性或危及帳戶安全。
大多數 Web 編程環境默認設置為創建非永久性的 cookie。這些 cookie 僅駐留在瀏覽器內存中(不寫入磁盤),并在瀏覽器關閉時丟失。程序員可以指定在瀏覽器會話中保留這些 cookie,直到將來某個日期為止。這樣的 cookie 將被寫入磁盤,在瀏覽器會話結束以及計算機重啟后仍然存在。
如果私人信息存儲在永久性 cookie 中,那么攻擊者就有足夠的時間竊取這些數據 — 尤其是因為通常將永久性 cookie 設置為在不久的將來到期。永久性 cookie 通常用于在用戶與某個站點交互時對其進行標識。根據此跟蹤數據的用途,有可能利用永久性 cookie 違反用戶隱私。
例:以下代碼將 cookie 設置為在 10 年后過期。
Cookie cookie = new Cookie("emailCookie", email);
cookie.setMaxAge(60*60*24*365*10);
[1] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A7 Insecure Cryptographic Storage
[2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A8 Insecure Cryptographic Storage
[3] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A8 Insecure Storage
[4] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3210.1 CAT II
[5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3210.1 CAT II
[6] Class Cookie Sun Microsystems
[7] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 539
[8] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Information Leakage
[9] Standards Mapping - FIPS200 - (FISMA) MP
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 3.4, Requirement 6.3.1.3, Requirement 6.5.8
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 3.4, Requirement 6.5.3
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 3.4, Requirement 6.5.8