Commits

Anonymous committed fa58a3f

2.x backport of [1239] (more secure session key). See #567.

  • Participants
  • Parent commits 963340a
  • Branches cherrypy-2.x

Comments (0)

Files changed (1)

File cherrypy/filters/sessionfilter.py

             (now,))
 
 
-def generate_session_id():
-    """ Return a new session_id """
-    return sha.new('%s' % random.random()).hexdigest()
+try:
+    os.urandom(20)
+except (AttributeError, NotImplementedError):
+    # os.urandom not available until Python 2.4. Fall back to random.random.
+    def generate_session_id():
+        """Return a new session id."""
+        return sha.new('%s' % random.random()).hexdigest()
+else:
+    def generate_session_id():
+        """Return a new session id."""
+        return os.urandom(20).encode('hex')
+
 generateSessionID = generate_session_id
 
 # Users access sessions through cherrypy.session, but we want this