資安JAVA(二一): Anti-Caching Header

來源:John Melton's Weblog
標題:YEAR OF SECURITY FOR JAVA – WEEK 21 – ANTI-CACHING HEADERS
作者:John Melton
What is it and why should I care?
It's under the mat, I knew it.
快取( Caching )是一種技巧,將伺服器上遠地的資料儲存一份副本在本地端,減少重複下載的動作,增加使用效能。只考慮效能的話,快取真是太棒。從資安的角度來看,可能成為很嚴重的問題。假設現在螢幕上顯示你的個人銀行帳戶或醫療紀錄,下個使用者甚至不需要登入就可以看到剛剛的資料。

幸運的是,我們可以藉由指令啟用或關閉快取。

What should I do about it?

從資安的角度來看,敏感資料應禁止使用快取,相信每個人都有自己的規則。

當你設定快取指令,通常會標記在HTTP Header、Cache-Control、Expires、Pragma。以下是以 Java 設定快取 header 的範例:

// for HTTP 1.1
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
// for HTTP 1.0
response.setHeader("Pragma", "no-cache");
// setting to 0 means epoch + 0 seconds, or expired in 1970, thus invalid now.
// the setDateHeader method sets a date in the RFC-required date format
response.setDateHeader("Expires", 0);


只要幾行的程式碼,你就可以關閉快取。作者介紹給許多同事,並用在 J2EE filter ,獲得很多好評。然而,千里之行始於足下,請你動手試試看,才知道這幾行程式碼真的可以保護使用者和資料!

參考資料
http://code.google.com/p/doctype-mirror/wiki/ArticleHttpCaching
http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers
http://www.mnot.net/cache_docs/#CONTROL
http://securesoftware.blogspot.com/2008/02/web-caches-and-security-problems-in-web.html
https://www.golemtechnologies.com/articles/web-cache-security
http://palizine.plynt.com/issues/2008Jul/cache-control-attributes/
http://support.microsoft.com/kb/234067
http://owasp-esapi-java.googlecode.com/svn/trunk/src/main/java/org/owasp/esapi/reference/DefaultHTTPUtilities.java

———–———–
資安Java: 上一篇 || 下一篇
———–———–

留言

這個網誌中的熱門文章

資安JAVA(八):HTTP強制傳輸安全(HSTS)

以 SharpPcap 實作可收聽封包的 C# 程式

資安JAVA(四):Session Cookie HTTPOnly Flag