Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing HttpOnly Attribute in Session Cookie

in sign.jsp, I have written the following so that, if a user is already logged in then immediately he would be forwarded to his 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
}
%>

Security scan is telling that Missing HttpOnly Attribute in Session Cookie in sign.jsp.

If i will set: <Context useHttpOnly="true"> ... </Context>

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

then will my problem be solved or what else i have to do? Any suggestion is much appreciated

like image 261
Tom Avatar asked Aug 23 '26 23:08

Tom


2 Answers

If you using Servlet 3.0. Than In Servlet 3.0 (Java EE 6) introduced a standard way to configure HttpOnly attribute for the session cookie, applying the following configuration in web.xml

<session-config>
 <cookie-config>
  <http-only>true</http-only>
 </cookie-config>
<session-config>
like image 137
Riddhish.Chaudhari Avatar answered Aug 25 '26 14:08

Riddhish.Chaudhari


Another approach is

Cookie cookie = new Cookie(cookieName, cookieValue);
cookie.setHttpOnly(true);
httpResponse.addCookie(cookie); 
like image 22
user1090509 Avatar answered Aug 25 '26 13:08

user1090509



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!