会话Cookie中缺少HttpOnly属性

时间:2012-03-23 06:29:36

标签: java security jsp jsessionid httponly

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 Cookie中的sign.jsp

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

in:C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.20\conf

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

3 个答案:

答案 0 :(得分:4)

如果您使用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>

答案 1 :(得分:1)

另一种方法是

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

答案 2 :(得分:0)

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

我认为你必须设置

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

$ PROFILE \ deploy \ jbossweb.sar \ context.xml&#34;

中的

属性

相关问题