Tell me more ×
IT Security Stack Exchange is a question and answer site for IT security professionals. It's 100% free, no registration required.

Is there any standard length of the token which should be used while generating the random tokens? Should we use the same standard which we use for generating Session IDs?

share|improve this question

2 Answers

up vote 5 down vote accepted

I would consider a 128 bits of entropy in a token to be the de-facto standard. OWASP and CWE both recommend this as a minimum. 20 characters of Base64 (capable of 120 bits) is also handy for something in the URL. I would also note that in many cases poor seeding for those tokens creates problems. For one bit of reference, see the (kind of tastelessly decorated, but very informative) slides from http://samy.pl/bh10/.

Make sure you choose your entropy source well.

share|improve this answer
2  
I think the 160 bit tokens you mentioned in the first version of your posting are so common because they are a nice round number of 20 characters. (Although it should be noted that the bit size of token is not equal to the amount of entropy dune to the limited range of printable characters). – Hendrik Brummermann Sep 9 '11 at 6:08
Should we use the same standards which we use for generating Session IDs for generating CSRF tokens as well? Just curious.. Thanks Jeff for Samy's very informative presentation. – p_upadhyay Sep 9 '11 at 6:39
@p_upadhyay I think that's a very secure approach. – Jeff Ferland Sep 9 '11 at 12:45
@Hendrik Base64 * 20 chars = 120 bits of entropy. I'll modify my answer again to be clearer... and I think 120 is "close enough" to be ok. – Jeff Ferland Sep 9 '11 at 12:46

In CSRF an attacker can make many guesses. What if an employee visits an attackers site and then goes on Christmas vacation? An attacker could make many millions of cross-site requests. We have a similar concern for session id's. If either value is obtained then session is compromised. The same standards of strength should be applied to both CSRF tokens and Session IDs.

In both cases make sure the value expires. Can the attacker can't make 2^128 requests in a week, but eventually he will be able to. If your random number generator is weak, then you may think you have a 2^128th cryptographic nonce, but it might be much less.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.