Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a sessionID generated?

When running a java web application with the servlet api (like JSF or JSP pages), somewhere along the line a 'unique' SessionID is generated to identify the user's session.

I'm wondering how these sessionID's are generated. Do they include the IP of the client? A timestamp? Random numbers?

Secondly, I'm wondering where this generation happens? Is this dependent on the server that runs the application?

like image 392
Steven De Groote Avatar asked Oct 11 '12 09:10

Steven De Groote


3 Answers

It is container specific. Tomcat: http://tomcat.apache.org/tomcat-7.0-doc/security-howto.html#Manager

like image 133
Aleksandr M Avatar answered Oct 06 '22 23:10

Aleksandr M


A java.security.MessageDigest algorithm is normally used.

Usually the generated ID is just a set of random numbers, up until the required length, but it varies according to the algorithms used in the various servlet containers.

In Tomcat6, for example, have a look at:

ManagerBase.sessionIdLength

and

ManagerBase.createSession() //which calls generateSessionId()

See http://www.docjar.com/html/api/org/apache/catalina/session/ManagerBase.java.html

like image 29
Nic Avatar answered Oct 07 '22 01:10

Nic


http://docs.oracle.com/cd/E17802_01/products/products/servlet/2.3/javadoc/javax/servlet/http/HttpSession.html#getId()

"The identifier is assigned by the servlet container and is implementation dependent."

The jsessionid is generated whenever a new session is created.

like image 38
dvsander Avatar answered Oct 07 '22 01:10

dvsander