在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>
在:C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.20\conf
那么我的问题会得到解决还是我还需要做什么?非常感谢任何建议
最佳答案
如果您使用 Servlet 3.0。比 在 Servlet 3.0 (Java EE 6) 中引入了一种标准的方法来为 session cookie 配置 HttpOnly 属性,在 web.xml 中应用以下配置
<session-config>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
<session-config>
关于java - session Cookie 中缺少 HttpOnly 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9835019/