torndsession icon indicating copy to clipboard operation
torndsession copied to clipboard

use of uuid4.hex() for token generation is not secure

Open socketpair opened this issue 8 years ago • 4 comments

binascii.b2a_base64(os.urandom(24))[:-1] is faster and much secure since:

  1. does not involve uuid, that is not suitable for secure token generations
  2. use OS provided much more secure random as opposed to python random
  3. generate 32-byte length string too, but, 64**24 = 2**144 random items, while your way generates 256**16 = 2**128 variants

it needs to be checked for special symbols like / and +

socketpair avatar Oct 27 '15 18:10 socketpair

Thanks for your comment. in my opinion, slash and plus are legal in cookies' value. What is the risk for generate token with base64 directly?

MitchellChu avatar Nov 08 '15 07:11 MitchellChu

base64 is just a way to encode binary value. It have nothing common with generating random data.

socketpair avatar Nov 08 '15 15:11 socketpair

If you ask about base64 module — it is just wrapper over binascii module — see sources. Using binascii directly is just faster in you case.

socketpair avatar Nov 08 '15 15:11 socketpair

this feature is added in version 1.1.5, thank you for your suggestion.

MitchellChu avatar Jan 19 '17 15:01 MitchellChu