![](/img/trans.png)
[英]Why is an URL marked as CONFIDENTIAL in web.xml not being rewritten with HTTPS by HttpServletResponse.encodeURL()?
[英]How to configure Tomcat to not encode the session id into the URL when HttpServletResponse.encodeURL() is invoked
看起来像一个愚蠢的问题,答案是“不要使用encodeURL()!” 但我正在使用在JSP中使用netui锚标签的代码库,我需要禁用将JSESSIONID写入URL,因为这是一个安全风险。
在WebLogic中,您可以通过在weblogic.xml中配置url-rewriting-enabled来配置它(我知道,因为我在WebLogic服务器中编写了该功能!)。 但是,我找不到Tomcat的等效配置选项。
Tomcat 6支持disableURLRewriting
属性,可以在Context元素中设置为true
:
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Common_Attributes
没有设置想到。 但是这很容易通过创建一个第一个条目Filter
监听感兴趣的url-pattern
(可能是/*
?)并用HttpServletResponseWrapper
实现替换ServletResponse
,其中encodeURL()
返回未修改的相同参数。
开球示例:
public void doFilter(ServletRequest request, ServletResponse response) throws ServletException, IOException {
chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) {
public String encodeURL(String url) {
return url;
}
});
}
如https://fralef.me/tomcat-disable-jsessionid-in-url.html中所示 - 有一个servlet规范功能来执行此操作
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.