在 HTTP 和 HTTPS 之间切换时,JSessionID 会被覆盖。怎么解决?
我们遇到以下情况:
转到 http://website/ 并单击 http://website/appX
的链接 检查 cookie 是否显示带有 secure = NO 的 JSessionID。打开另一个浏览器窗口或选项卡,然后转到 https://website/ 并单击指向 https://website/appY 的链接。
检查 cookie 是否显示 JSessionID 且 secure = YES。尝试与步骤 1 中创建的窗口/选项卡进行交互。我的会话已过期...
如果我们重复这些步骤,但在步骤 2 中使用 https://website/appX 而不是 https://website/appY,则 JSessionID cookie 仍保留为 Secure =不。
所有 cookie 都有 JSessionId,最后附加 jvmRoute。
--
我们正在使用:
Apache (2.2.3-43.el5_5.3) + mod_jk(带粘性会话)和配置到多个 JBoss 实例的负载均衡器(v 4.3.0)。
我只找到了一个具有完全相同问题的链接(通常其他链接都使用 PHP): http://thirdbit.net/mail-archive/tomcat-users/msg17687.html
问:如何防止 JSessionId cookie 被重写?
We have the following situation going on:
Go to http://website/ and click on a link to http://website/appX
Check that the cookie shows JSessionID with secure = NO.Open another browser window or tab and go to https://website/ and click on a link to https://website/appY.
Check that the cookie shows JSessionID with secure = YES.Try to interact with the window/tab created in step 1. I'm getting a session expired...
If we repeat the steps but use https://website/appX instead of https://website/appY in step2, then the JSessionID cookie remains with Secure=NO.
All cookies have JSessionId with jvmRoute appended in the end.
--
We are using:
Apache (2.2.3-43.el5_5.3) + mod_jk (w/ sticky sessions) and load balancer configured to several JBoss instances (v 4.3.0).
I have found only a link with the exact same issue (normally the other ones are using PHP):
http://threebit.net/mail-archive/tomcat-users/msg17687.html
Q: How can we prevent the JSessionId cookie from being rewritten ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从安全角度来看,这是正确的行为,因为如果在 http 中也使用相同的会话 id/cooki,则攻击者可以窃取 https 中使用的会话 id/cooki。
有关更多详细信息,请参阅我的答案
因此,如果您想构建一个安全的应用程序(我希望如此,因为您使用 https),那么您一定不要更改它!
From a security point of view, it is the correct behavior, because a attacker could steal the session id/cooki used in https if the same session id/cooki is used in http too.
For more details see my answer here.
So if you want to build a secure application (I excpect this, because you use https), then you must not change this!
从 HTTPS 切换到 HTTP 时,SessionID/Cookie 将不会被保留,反之亦然。您可以在 URL 中传递这些参数来传递值。
SessionID/Cookie will not be preserved when making switch from HTTPS to HTTP or vice versa. You can pass these parameters in URL to pass the values.
在deploy/jboss-web.deployer/server.xml中的连接器配置(对于JBoss中的Tomcat捆绑版本)中,有一个
emptySessionPath
属性控制是否在上下文路径上设置会话cookie 。如果将此设置为 false,则每个应用程序将拥有一个 cookie,从而防止问题发生。
In the connector configuration (for Tomcat's bundled version in JBoss) in deploy/jboss-web.deployer/server.xml, there's an
emptySessionPath
attribute that controls whether the session cookie is set on the context path or not.If you set this to false, you'll have one cookie per application, which prevents the problem from happening.