Web Security · Senior · Question 41 of 75
Which source of randomness should be used for session IDs and reset tokens in a browser or Node.js?
- ✓Correct answer: A CSPRNG:
crypto.getRandomValues(),crypto.randomUUID()orcrypto.randomBytes() - 2The current timestamp with the user ID
- 3
Math.random(), converted to a string
Explanation
Math.random() isn't designed to be unpredictable. Security tokens need a cryptographically secure generator.