← Java / Spring · Contents

JAVA-084 / Intermediate

Cryptographically weak session IDs or predictable sequential IDs

A07:2021 · CWE-330 Insufficiently Random Values · CWE-340

Why is this a problem?

Sequential IDs or timestamp-based tokens are guessable.

How to fix it

java
String id = UUID.randomUUID().toString();   // v4 based on internal SecureRandom; prefer direct SecureRandom for sensitive tokens

Further reading