gpt4 book ai didi

java - 使用 servlet 3.0 的 JBoss 6 session 安全特性的问题

转载 作者:搜寻专家 更新时间:2023-10-30 21:12:45 27 4
gpt4 key购买 nike

我们将应用程序从 JBoss 5 迁移到 JBoss6,其中一个主要原因是要利用 servlet 3.0 的新功能。除了 JBoss 6 和 servlet 3.0 的一项新功能外,一切都很好:将 session cookie 设置为仅通过安全通道传输,即使请求是通过纯 HTTP 发出的。这对我们来说是一个非常重要的安全功能,可以通过添加

<secure>true</secure>

在 web.xml 中。这是我们的 web.xml 的一部分:

<session-config>
<session-timeout>25</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>

当我们删除

<secure>true</secure>

一切正常。当它存在时,即使在安全页面 (HTTPS) 或不安全页面 (HTTP) 上,也会为每个请求生成一个新的 jsessionid。此外,登录不起作用,因为在使用安全凭据登录后,用户将被重定向回登录页面。

我想这可能也是 Tomcat 7 的一个问题,因为它也使用 servlet 3.0 规范。任何建议将不胜感激。

问候

最佳答案

根据HTTP Specification :

Secure

Optional. The Secure attribute (with no value) directs the user agent to use only (unspecified) secure means to contact the origin server whenever it sends back this cookie.

The user agent (possibly under the user's control) may determine what level of security it considers appropriate for "secure" cookies. The Secure attribute should be considered security advice from the server to the user agent, indicating that it is in the session's interest to protect the cookie contents.

这意味着规范让浏览器(用户代理)可以定义什么是“安全的”。

web.xml 中的Secure 元素是对HTTP Cookie Secure property 的引用。 ,您可以使用浏览器的调试工具跟踪该值。

如果通信不“安全”,浏览器将不会根据以下请求将收到的 cookie 发送到服务器。

问题不在于 JBoss 总是返回新的 cookie,而是因为通信不安全而没有将其发回的浏览器。 JBoss 然后为每个请求创建一个新 session 。

很明显,对于非加密通信(不是 HTTPS),浏览器不会发送 cookie,这是预期的,因为您将 cookie 标记为 secure = true

但是,即使您正在使用 HTTPS,“安全”相对于浏览器的安全概念,例如:

  • 证书可以过期
  • 证书是自签名的
  • 您使用的主机名与签署证书的主机名不同

使用 TLS 可能会发生这些和其他安全问题,这意味着通信安全。

问题一定出在您的 SSL/TLS 或 Cookie 配置上,这意味着您必须检查您的操作并找出问题所在。我认为 JBoss 或 JBossWeb(Tomcat 6 分支)中没有任何错误导致它,并且可以肯定这不是规范错误。

我能够使用 TLS 和您的 web.xml 配置配置 JBoss 6.1.0 Final,一切都按预期工作。

我建议您仔细检查您的配置、浏览器调试和警报。

关于java - 使用 servlet 3.0 的 JBoss 6 session 安全特性的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479656/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com