2012-03-23 181 views
3

sign.jsp,我寫了下面,這樣,如果用戶已登錄,然後他就立刻會被轉發到他的home page缺少會話Cookie的HttpOnly屬性

<% 
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

然後將我的問題得到解決或我必須做什麼?任何建議非常感謝

+0

您正在使用哪個Servlet版本? – 2012-03-23 08:11:18

回答

4

如果您使用Servlet 3.0。比 在Servlet的3.0(Java EE 6的)引入到配置的HttpOnly屬性用於會話cookie,在web.xml中採用以下配置的標準方式

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

只有這麼多我必須在'web.xml'中做或者'jsp/servlet'也需要修改? – Tom 2012-03-23 08:21:10

+0

是的,只有這個!但必須要求3.0版。 – 2012-03-23 08:22:46

+0

+1,我也接受你的回答Riddhish,我使用的是javaEE 6,所以我認爲你的方法可以工作 – Tom 2012-03-23 10:17:52

1

另一種方法是

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

閱讀本文章https://access.redhat.com/solutions/338313

我認爲你必須設置

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

屬性在「$ PROFILE \ deploy \ jbossweb.sar \ context.xml」