views:

411

answers:

1

Seems like a stupid question to which the answer would be "Don't use encodeURL()!" but I'm working with a codebase that uses netui anchor tags in the JSPs and I need to disable the writing of JSESSIONID into the URLs as it is a security risk.

In WebLogic, you can configure this by configuring url-rewriting-enabled in weblogic.xml (I know because I wrote that feature in the WebLogic server!). However, I can't find an equivalent config option for Tomcat.

+1  A: 

No setting comes to mind. But this is fairly easy to do by creating a first-entry Filter listening on the url-pattern of interest (maybe /* ?) and replaces the ServletResponse by a HttpServletResponseWrapper implementation where the encodeURL() returns the very same argument unmodified back.

Kickoff example:

public void doFilter(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) {
        public String encodeURL(String url) {
            return url;
        }
    });
}
BalusC
Beat me to it... remember, though, there are 4 different url-rewriting methods on the response, some or all of which might need "disabling".
skaffman
Correct. 2 of them are however deprecated (ending in `Url` instead of `URL`). The other one which you may want to override as well is the `encodeRedirectURL()`. Also see http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletResponse.html#encodeRedirectURL%28java.lang.String%29
BalusC
Thanks! That's exactly what I did for Tomcat and I can confirm that it works.
Alex Worden