In my previous post Creating a custom Valve in tomcat I descibed the valve solution I tried to secure the JSESSIONID cookie but it didnt worked so finally I had to patch the tomcat class to get it working. We are using tomcat 5.5.28 so I downloaded the source and modify the class apache-tomcat-5.5.24-src/container/catalina/src/share/org/apache/catalina/connector/Response.java. In addCookie method I had to add this code
Then compile the code and replace the catalina.jar in tomcathome/server/lib
String cookieName = cookie.getName();
if (request != null && "JSESSIONID".equals(cookieName)) {
String clientId = request.getHeader("X-Forwarded-For");
if (clientId != null) {
cookie.setSecure(true);
}
}
Then compile the code and replace the catalina.jar in tomcathome/server/lib
Cool! Did you send patch back to ASF guys? :)
ReplyDeleteno no its not a tomcat bug, but its the way we put apache/nginx in front of tomcat so that we don't want tomcat to handle SSL traffic. Apache handles SSL and by the time it reaches tomcat the request is no longer secure and thats why tomcat was not creating secure cookie. So it was a workaround to do it. This can also be used to set JSESSIONID a domain wide cookie in case you have diff tomcats using diff subdomain. I think newer tomcat may support this as an attribute already but we couldnt upgrade to new tomcat in this short timeframe.
ReplyDelete