我想将 'secure' 标志设置为 JSESSIONID cookie 。tomcat 6中是否有此配置?
我尝试在 server.xml 的 'Connector' (8080) 元素中设置 'secure="true"' ,但它会产生问题 ....thats Connection is getting reset 。
请注意,在我的应用程序中,JSESSIONID 是以“http”模式(索引页面)创建的,当用户登录时,它将切换到“https”模式。
我想将 'secure' 标志设置为 JSESSIONID cookie 。tomcat 6中是否有此配置?
我尝试在 server.xml 的 'Connector' (8080) 元素中设置 'secure="true"' ,但它会产生问题 ....thats Connection is getting reset 。
请注意,在我的应用程序中,JSESSIONID 是以“http”模式(索引页面)创建的,当用户登录时,它将切换到“https”模式。
如果您使用的是 tomcat 6,则可以执行以下解决方法
String sessionid = request.getSession().getId();
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; secure ; HttpOnly");
有关更多信息,请参见https://www.owasp.org/index.php/HttpOnly
使用属性 useHttpOnly="true"。在 Tomcat9 中,默认值为 true。
对于 nginx 代理,可以在 nginx 配置中轻松解决:
if ($scheme = http) {
return 301 https://$http_host$request_uri;
}
proxy_cookie_path / "/; secure";