Para las cookies de sesión todavía no parece ser compatible con Tomcat. Consulte el informe de error Need to add support for HTTPOnly session cookie parameter. Por ahora, se puede encontrar una solución algo complicada, here, que básicamente se reduce a parches manuales de Tomcat. Realmente no puedo encontrar una manera fácil de hacerlo en este momento, en este punto tengo miedo.
para resumir el trabajo en torno, se trata de la descarga del 5,5 source, y luego cambiar la fuente en los siguientes lugares:
org.apache.catalina.connector.Request.java
//this is what needs to be changed
//response.addCookieInternal(cookie);
//this is whats new
response.addCookieInternal(cookie, true);
}
org.apache.catalina.connectorResponse.addCookieInternal
public void addCookieInternal(final Cookie cookie) {
addCookieInternal(cookie, false);
}
public void addCookieInternal(final Cookie cookie, boolean HTTPOnly) {
if (isCommitted())
return;
final StringBuffer sb = new StringBuffer();
//web application code can receive a IllegalArgumentException
//from the appendCookieValue invokation
if (SecurityUtil.isPackageProtectionEnabled()) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run(){
ServerCookie.appendCookieValue
(sb, cookie.getVersion(), cookie.getName(),
cookie.getValue(), cookie.getPath(),
cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure());
return null;
}
});
} else {
ServerCookie.appendCookieValue
(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
cookie.getPath(), cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure());
}
//of course, we really need to modify ServerCookie
//but this is the general idea
if (HTTPOnly) {
sb.append("; HttpOnly");
}
//if we reached here, no exception, cookie is valid
// the header name is Set-Cookie for both "old" and v.1 (RFC2109)
// RFC2965 is not supported by browsers and the Servlet spec
// asks for 2109.
addHeader("Set-Cookie", sb.toString());
cookies.add(cookie);
}
Estoy ejecutando Tomcat 5.5.36. Este atributo useHttpOnly parece funcionar solo para la cookie JSESSIONID. Agregué este indicador en todos mis contextos para asegurarme de que todas las cookies se agregarían al final "; HttpOnly". Sin embargo, solo JSESSIONID se vio afectado de la siguiente manera: 'Set-Cookie =' JSESSIONID = 25E8F ...; Path =/custompath; HttpOnly mycustomcookie1 = xxxxxxx; Path =/ mycustomcookie2 = 1351101062602; Path =/ mycustomcookie3 = 0; Path =/ mycustomcookie4 = 1; Ruta = /; Seguro mycustomcookie5 = 4000; Caduca = sáb, 22-oct-2022 17:51:02 GMT; Path =/ ¿Algo más estoy haciendo mal? –
Esta documentación parece indicar que el indicador useHttpOnly solo se refiere a la cookie de identificación de sesión: http://tomcat.apache.org/tomcat-5.5-doc/config/context.html#Common_Attributes Creo que esto fue un paso intermedio medida destinada a proteger la cookie de sesión. La capacidad de marcar cookies como HttpOnly no formaba parte de las especificaciones de Servlet hasta 3.0 (cubierto por Tomcat 7): http://today.java.net/pub/a/today/2008/10/14/introduction-to- servlet-3.html # other-miscellaneous-changes –