Skip to content

Commit c338508

Browse files
author
Richard Jones
committed
fix random seeding for forking server
1 parent f79c622 commit c338508

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

roundup/cgi/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.171 2004-04-20 21:57:10 richard Exp $
1+
# $Id: client.py,v 1.172 2004-04-22 22:16:36 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -7,6 +7,7 @@
77
import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib
88
import binascii, Cookie, time, random, stat, rfc822
99

10+
1011
from roundup import roundupdb, date, hyperdb, password
1112
from roundup.i18n import _
1213
from roundup.cgi import templating, cgitb
@@ -97,6 +98,8 @@ class Client:
9798
# pagesize, startwith
9899

99100
def __init__(self, instance, request, env, form=None):
101+
# re-seed the random number generator
102+
random.seed()
100103
if __debug__:
101104
hyperdb.traceMark()
102105
self.start = time.time()
@@ -612,8 +615,15 @@ def set_cookie(self, user):
612615
613616
Also store away the user's login info against the session.
614617
"""
615-
# TODO generate a much, much stronger session key ;)
616-
self.session = binascii.b2a_base64(repr(random.random())).strip()
618+
sessions = self.db.getSessionManager()
619+
620+
# generate a session key
621+
s = '%s%s'%(time.time(), random.random())
622+
print s
623+
self.session = binascii.b2a_base64(s).strip()
624+
while sessions.exists(self.session):
625+
s = '%s%s'%(time.time(), random.random())
626+
self.session = binascii.b2a_base64(s).strip()
617627

618628
# clean up the base64
619629
if self.session[-1] == '=':
@@ -623,7 +633,6 @@ def set_cookie(self, user):
623633
self.session = self.session[:-1]
624634

625635
# insert the session in the sessiondb
626-
sessions = self.db.getSessionManager()
627636
sessions.set(self.session, user=user)
628637
self.db.commit()
629638

0 commit comments

Comments
 (0)