3

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

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

4

3 回答 3

4

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

<session-config>
 <cookie-config>
  <http-only>true</http-only>
 </cookie-config>
<session-config>
于 2012-03-23T08:18:30.677 回答
1

另一种方法是

Cookie cookie = new Cookie(cookieName, cookieValue);
cookie.setHttpOnly(true);
httpResponse.addCookie(cookie); 
于 2012-05-02T20:51:11.363 回答
0

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

我认为你必须设置

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

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

于 2017-11-16T05:42:55.070 回答