调用无效后重新使用会话 ID

发布于 2024-11-26 16:42:30 字数 928 浏览 3 评论 0原文

我继承了一个非常古老的 JSP 应用程序 (JDK 1.3.1_15),并试图堵塞会话固定漏洞。

使用 HttpSession.invalidate() 进行身份验证后,我成功使当前会话无效,但是创建新会话时,会重新使用旧会话 ID。

<%
// login.jsp
if (authenticated) {
    request.getSession().invalidate();

    // create new session and store data
    HttpSession session = request.getSession();
    session.putValue(...);
    // etc

    response.sendRedirect("logged-in.jsp");
    return;
}
%>

我可以在 HTTP 监视器中看到新的会话分配,它只是再次使用相同的编号。

-- Initial request response --
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=6a303082951311647336934;path=/

-- login.jsp request response --
HTTP/1.1 302 Moved Temporarily
Location: http://example.com/logged-in.jsp
Set-Cookie: JSESSIONID=6a303082951311647336934;path=/

在我使用 session.invalidate() 之前,第二个 Set-Cookie 响应标头根本不存在。

有人对如何生成新的会话 ID 有任何建议吗?我对 JRUN4 不太熟悉,但翻遍配置文档并没有发现任何东西。

I've inherited a pretty ancient JSP application (JDK 1.3.1_15) and am attempting to plug a session fixation hole.

I'm successfully invalidating the current session after authentication using HttpSession.invalidate() however when the new session is created, the old session ID is re-used.

<%
// login.jsp
if (authenticated) {
    request.getSession().invalidate();

    // create new session and store data
    HttpSession session = request.getSession();
    session.putValue(...);
    // etc

    response.sendRedirect("logged-in.jsp");
    return;
}
%>

I can see the new session assignment in my HTTP monitor, it's just using the same number again.

-- Initial request response --
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=6a303082951311647336934;path=/

-- login.jsp request response --
HTTP/1.1 302 Moved Temporarily
Location: http://example.com/logged-in.jsp
Set-Cookie: JSESSIONID=6a303082951311647336934;path=/

Prior to me using session.invalidate() the second Set-Cookie response header was not present at all.

Does anybody have any advice on how to generate a new session ID? I'm not very familiar with JRUN4 but trawling through the configuration documentation hasn't turned up anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-12-03 16:42:30

要解决此问题,您可以使用第二个非持久 cookie 来充当您可以控制其值的会话 ID。这个想法是生成一个唯一的 id 并将其存储在 cookie 和会话中。使用此 cookie 实现与您尝试通过使用 invalidate 对会话执行的相同逻辑。具体来说,在身份验证成功之前,不要发出未来请求将接受的实际标识符。然后创建一个 Servlet 过滤器来检查每个请求并将这个新 cookie 的值与会话中存储的值进行匹配。如果它们不匹配,则表示正在发生邪恶的事情。我知道这比仅仅依靠 session.invalidate() 来发出新的 id 更麻烦一些。但考虑到您的约束和 JRun 的行为,这将为防止会话固定提供足够的保护。

To work around this, you can use a second non-persistent cookie to act as a session id that you can control the value of. The idea is to generate a unique id and store it in both the cookie and the session. Implement the same logic with this cookie that you are attempting to do with the session through using invalidate. Specifically, don't issue the actual identifier that will be accepted for future requests until authentication is successful. Then create a Servlet Filter that checks each request and matches the value of this new cookie to the value stored in the session. If they don't match, something nefarious is going on. I know it is a bit more cumbersome than just relying on session.invalidate() to issue a new id. But given your constraints and JRun's behavior, this will provide sufficient protection against session fixation.

ま昔日黯然 2024-12-03 16:42:30

来自 Java Servlet 3.0 规范,你可以看到:

HttpSession 对象的范围必须位于应用程序(或 servlet
上下文)级别。 底层机制,例如用于
建立会话,对于不同的上下文可以是相同的
,但是
引用的对象,包括该对象中的属性,绝不能
由容器在上下文之间共享。

这是一个非常糟糕的想法,但我想知道 JSESSIONID cookie 是否只是被重复使用,并且实际的会话上下文被破坏了。您仍然可以访问失效会话的状态(即属性)吗?

From Section 7.3 of the Java Servlet 3.0 specification, you can see that:

HttpSession objects must be scoped at the application (or servlet
context) level. The underlying mechanism, such as the cookie used to
establish the session, can be the same for different contexts
, but the
object referenced, including the attributes in that object, must never
be shared between contexts by the container.

It's a really terrible idea, but I wonder if the JSESSIONID cookie is simply re-used and the actual session context destroyed. Can you still acess state (i.e. attributes) of the invalidated session?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文