• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How is jsessionId handled when moving from http --> https?

 
Rex Norm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say that I've never visited a site, and I go to it using http://mysite.com.

The servlet container is supposed to assign a jsessionId and try to set a cookie. If I have cookies enabled, I should no longer see the jsessionId, correct?

Now, what happens when I redirect (or forward) from a page on http://mysite.com/servlet1 to another https://mysite.com/servlet2? Will URL rewriting kick in? Will the SAME sessionId be used (and is this good practice in terms of security?)

If URL rewriting does kick in for the scheme change (http --> https), should i expect it to break my URLs by adding the ";jsessionId=xxxx"? and what can I do to prevent this? (servlet filter to intercept and strip this out)?

I would even appreciate an RTFM reference if this is too basic.

thanks in advance.

_R
 
Rex Norm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry one more question to be complete-- is the behavior different when coming from https:// and redirecting (or forwarding??) to http://?

that is, is jsessionID (URL rewriting) used in the reverse direction or can the cookie be used? Can I force this?

thanks,

_r
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should never perform url rewriting yourself since they container can do it if you tell it to. If you are creating URLs in a Servlet, you should use the javax.servlet.http.HttpServletRequest encodeURL method. In a JSP you should use the JSTL url tag <c:url> example. These will automatically perform url rewriting if needed. If you use encodeURL or url tags anytime you have a link then you should be set.
 
Rex Norm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, thanks for your response.

You should never perform url rewriting


I plan to avoid this.

If you are creating URLs in a Servlet, ...

yes, this is my intent... I need to redirect from an insecure page to a secure login page (SSL) and then redirect to another secure page on success.
...you should use the javax.servlet.http.HttpServletRequest encodeURL method. In a JSP you should use the JSTL url tag <c:url> example.

So does this mean that the same sessionId is used for both http and https? Meaning that a redirect from http --> https will be handled by the tag and container? I seemed to read somewhere that setting a new sessionId is a good idea for the secure component. I guess nothing is preventing me from setting a new cookie with a new (self generated) ID with quick expiration for the secure part and relying on that, right?

Also, is there a difference between <html:link> and <c:url>? do they do the same thing?


thanks for your help.
_R
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:link> is a proprietary struts tag.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic