簡體   English   中英

Spring 引導:注銷后,帶有過期 Cookie 的請求仍然可用

[英]Spring boot: Requests with an expired Cookie is still available after logging out

在 spring 引導項目中,當用戶注銷時,我們使用以下代碼塊使 cookie 失效:

//name = "Token"
//value = "expired"
//age = 0
private void setExpiredCookie(HttpServletResponse response, String name, String value, int age) {
    Cookie cookie = new Cookie(name, value);
        cookie.setSecure(true); //Send cookie to the server only over an encrypted HTTPS connection
        cookie.setHttpOnly(true); //Preventing cross-site scripting attacks
        cookie.setPath("/"); //Global cookie accessible every where
        cookie.setMaxAge(age); //Deleting a cookie. I Passed the same other cookie properties when you used to set it

        response.addCookie(cookie);
}

然而,在注銷后,我用一個應用程序測試了我的網站,以捕獲請求並通過中繼器重新發送它,並使用准確的值,例如令牌和有效負載。

例如,我拒絕了更改 email 地址的請求,盡管已注銷,但此請求在 15 分鍾內有效(對於原始 cookie 的生命周期)。

我錯過了什么? 因為我正在妥善刪除和保護 cookies。

您只是在創建新的 cookie。 您應該使用 session id 使 cookie 無效,該 id 在您進行身份驗證時提供給您。 只需使用這個:

HttpSession session = httpServletRequest.getSession(false);
session.invalidate();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM