I have a website running on JSP that is using an external service for payment. When a user pays they are redirected to an external url and when payment is finished they return. My problem is that sometimes (about 70% of the time) when the user returns, the session is lost (JSP creates a new empty session). This problem does not occur in Firefox or IE11.
I have confirmed that the server IP stays the same before and after the session changes so the load balancer is not the problem. I have also confirmed that response.encodeURL
and response.encodeRedirectURL
are used (the before/after URLs are equal) so the browser should have no problem with the cookie.
The website and the external service are both running on https, so the cookie setting should also not cause any problems.
Does anyone have an idea on what could cause this problem? The code is literally just (except that the return_to is url-encoded).
response.sendRedirect("https://paymentservice.com/pay?token=asd&return_to=https://mywebsite.com/finishtransaction.jsp");
The session is configured as sticky and only external links like the one above reset the session. I could not reproduce the problem with an URL shortener (tinyurl):
<%
out.println(session.getId() + "<br>");
out.println(request.getParameter("step") + "<br>");
%>
<script type="text/javascript">
function redirect_window(redirectUrl){
if((window.opener && !window.opener.closed)){
window.opener.location.href = redirectUrl;
window.open('about:blank','_self').close();
}else{
window.close();
location.href=redirectUrl;
}
}
setTimeout(function() {
<c:if test="${param.step == null}">
var options;
if (navigator.appName.charAt(0)=='M'){
options = "fullscreen=1,scrollbars=yes";
}else if (navigator.appName.charAt(0)=='N'){
options = "left=0,top=0"
+ ",width=" + screen.width
+ ",height=" + screen.height
+ ",scrollbars=yes";
}
window.open("/test_session.jsp?step=1","test",options);
</c:if>
<c:if test="${param.step == 1}">
redirect_window("/test_session.jsp?step=2");
</c:if>
}, 3000);
</script>