【问题标题】:Missing HttpOnly Attribute in Session Cookie会话 Cookie 中缺少 HttpOnly 属性
【发布时间】:2012-04-07 18:23:25
【问题描述】:

sign.jsp,我写了以下内容,这样,如果用户已经登录,那么他会立即被转发到他的home page

<%
try{

HttpSession session1 = request.getSession(false);

if(session1.getAttribute("authenticated")!=null &&  
 session1.getAttribute("authenticated").equals(true))
{
response.sendRedirect("userhome.jsp");
}
else{

// users have to login here
}
%>

安全扫描表明Missing HttpOnly Attribute in Session Cookiesign.jsp 中。

如果我设置:<Context useHttpOnly="true"> ... </Context>

输入:C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.20\conf

那么我的问题会得到解决还是我还需要做什么?任何建议都非常感谢

【问题讨论】:

  • 您使用的是哪个 Servlet 版本?

标签: java security jsp jsessionid httponly


【解决方案1】:

阅读这篇文章https://access.redhat.com/solutions/338313

我认为你必须设置

<Context cookies="true" crossContext="true">
  <SessionCookie secure="true" httpOnly="true" />

“$PROFILE\deploy\jbossweb.sar\context.xml”中的属性

【讨论】:

    【解决方案2】:

    另一种方法是

    Cookie cookie = new Cookie(cookieName, cookieValue);
    cookie.setHttpOnly(true);
    httpResponse.addCookie(cookie); 
    

    【讨论】:

      【解决方案3】:

      如果您使用 Servlet 3.0。比 在 Servlet 3.0 (Java EE 6) 中引入了一种为会话 cookie 配置 HttpOnly 属性的标准方法,在 web.xml 中应用以下配置

      <session-config>
       <cookie-config>
        <http-only>true</http-only>
       </cookie-config>
      <session-config>
      

      【讨论】:

      • 我在web.xml 中只需要做这么多,还是在jsp/servlet 中也需要一些修改?
      • +1 我也接受了你的回答 Riddhish,我使用的是 javaEE 6,所以我认为你的方法会起作用
      猜你喜欢
      • 2013-09-10
      • 2017-05-11
      • 2023-04-01
      • 2023-03-31
      • 2013-07-19
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      相关资源
      最近更新 更多