comparison roundup/scripts/roundup_server.py @ 5201:a9ace22e0a2f

issue 2550690 - Adding anti-csrf measures to roundup following https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet and https://seclab.stanford.edu/websec/csrf/csrf.pdf Basically implement Synchronizer (CSRF) Tokens per form on a page. Single use (destroyed once used). Random input data for the token includes: system random implementation in python using /dev/urandom (fallback to random based on timestamp as the seed. Not as good, but should be ok for the short lifetime of the token??) the id (in cpython it's the memory address) of the object requesting a token. In theory this depends on memory layout, the history of the process (how many previous objects have been allocated from the heap etc.) I claim without any proof that for long running processes this is another source of randomness. For short running processes with little activity it could be guessed. last the floating point time.time() value is added. This may only have 1 second resolution so may be guessable. Hopefully for a short lived (2 week by default) token this is sufficient. Also in the current implementation the user is notified when validation fails and is told why. This allows the roundup admin to find the log entry (at error level) and try to resolve the issue. In the future user notification may change but for now this is probably best.
author John Rouillard <rouilj@ieee.org>
date Sat, 18 Mar 2017 16:59:01 -0400
parents 96dc9f07340a
children 198b6e810c67
comparison
equal deleted inserted replaced
5200:16a8a3f0772c 5201:a9ace22e0a2f
373 env['SERVER_PORT'] = str(self.server.server_port) 373 env['SERVER_PORT'] = str(self.server.server_port)
374 try: 374 try:
375 env['HTTP_HOST'] = self.headers ['host'] 375 env['HTTP_HOST'] = self.headers ['host']
376 except KeyError: 376 except KeyError:
377 env['HTTP_HOST'] = '' 377 env['HTTP_HOST'] = ''
378 xfh = self.headers.getheader('X-Forwarded-Host', None)
379 if xfh:
380 env['HTTP_X-FORWARDED-HOST'] = xfh
378 if os.environ.has_key('CGI_SHOW_TIMING'): 381 if os.environ.has_key('CGI_SHOW_TIMING'):
379 env['CGI_SHOW_TIMING'] = os.environ['CGI_SHOW_TIMING'] 382 env['CGI_SHOW_TIMING'] = os.environ['CGI_SHOW_TIMING']
380 env['HTTP_ACCEPT_LANGUAGE'] = self.headers.get('accept-language') 383 env['HTTP_ACCEPT_LANGUAGE'] = self.headers.get('accept-language')
384 referer = self.headers.get('Referer')
385 if referer:
386 env['HTTP_REFERER'] = referer
387 origin = self.headers.get('Origin')
388 if origin:
389 env['HTTP_ORIGIN'] = origin
390 xrw = self.headers.get('x-requested-with')
391 if xrw:
392 env['HTTP_X-REQUESTED-WITH'] = xrw
381 range = self.headers.getheader('range') 393 range = self.headers.getheader('range')
382 if range: 394 if range:
383 env['HTTP_RANGE'] = range 395 env['HTTP_RANGE'] = range
384 396
385 # do the roundup thing 397 # do the roundup thing

Roundup Issue Tracker: http://roundup-tracker.org/