在服務器端,成功登錄後,我執行:Servlet的會話cookie篡改和安全
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
session.setAttribute("user", subject.getUser().getId());
session.setAttribute("logged", true);
我再假設該用戶登錄當用戶導航到一個安全的網頁,以。保存或刪除我的數據庫中的記錄,我運行此代碼。
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
if (session.getAttribute("user")!=null && session.getAttribute("logged"))
{
//delete a record using the authority of the user.
}
我擔心的是客戶端可以用不同的用戶ID來篡改瀏覽器cookie。數據庫請求將以不同的用戶啓動,跳過登錄過程。
Java會話能識別篡改,或者我應該用數字包括該行
session.setAttribute("signature", hash(secretkey + subject.getUser().getId());
然後驗證簽名更改數據庫之前有效簽署了會議。
if (session.getAttribute("signature").equals(hash(secretkey + session.getAttribute("user"))
{
//delete a record using the authority of the user.
}
即使您對Java會話如何工作的假設是錯誤的(正如下面的答案中所解釋的),我讚賞你對安全性的看法。你絕對不應該相信客戶發給你的任何東西。 –