How to Reproduce sendRedirect issue - HTTPS change to HTTP

param83 picture param83 · Sep 19, 2013 · Viewed 15.5k times · Source

I am using response.sendRedirect() to redirect the user to Home page, once the user gets authenticated successfully. This is to avoid the "Login redirect vulnerability".

However, because of above change, One of my customer is facing issue where his HTTPS request are getting converted to HTTP (with ip address in the URL). The reason for the same is explained here

http://geekexplains.blogspot.in/2008/06/https-becoming-http-in-case-of.html

Now, How can i reproduce the issue (or setup the environment) so that I can verify my fix. I thought I could reproduce by setting up Apache server infront of tomcat but I am not able to reproduce above mentioned issue.

In Apache httpd.conf i have below entries

ProxyPass /myconsole ajp://localhost:8009/myconsole
ProxyPassReverse /myconsole ajp://localhost:8009/myconsole

Accessed the application like,

http://myapacheserver/myconsole/Login.jsp

After the successful login, I am getting redirected to

http://myapacheserver/myconsole/Home.jsp

I am expecting to redirect to the IP address. something like http://10.32.24.14:8080/myconsole/Home.jsp.

In the customer environment he is getting redirected to the ip address of App server (tomcat).

Any pointer would be helpful.

Thanks

Note: For those interested, I am building the full URL by getting the first part of URI from the configuration file.

//Get the LB URI part. Eg: https://dev.loadbalancer.com/
String loadBalancerURI = getConfig().getLoadBalancerRequestURI();
String redirectURL = request.getContextPath() + "/Home.jsp";

//Prepend the LoadBalancer URI with redirect URI
if(loadBalancerURI != null)
{
    redirectURL = loadBalancerURI + "/" + redirectURL;  
}

//redirect to home page
response.sendRedirect(redirectURL);

return;

Edit: More info on the setup. The customer has F5 load balancer where the SSL traffic stops and then there is a Apache Reverse Proxy servers which proxy to pool of tomcat servers. The issue is when we do redirect the redirect URL is for Tomcat Servers. What we are expecting is to have the load balancer URL in the redirect URL.

Is it possible to do some change in the Apache server which will rewrite the URL in the HTTP header in the response send by Tomcat?

Answer

developerwjk picture developerwjk · Sep 19, 2013

I'm not sure if you're really using a load balancer or if you just called one of your methods getLoadBalancerRequestURI, but where you only have one server, just use :

response.sendRedirect("./Home.jsp");

Its not necessary to specify the full url.

But if you do need to build the full url as you are doing, you can use something like this to check if its https://

String protocol = "https";
if( request.getRequestURL().toString().toLowerCase().startsWith("http://" ) )
{
    protocol = "http";
}

Then make sure to build the url with the proper protocol.