Replace Random with SecureRandom for improved randomness in SAML2SSOTestBase#26929
Replace Random with SecureRandom for improved randomness in SAML2SSOTestBase#26929HarishRock0 wants to merge 1 commit intowso2:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughA security improvement was made to switch the random number generation in SAML2 SSO testing from a non-cryptographic Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens SAML AuthnRequest ID generation in the product scenario test utilities by switching from java.util.Random to java.security.SecureRandom in SAML2SSOTestBase, improving unpredictability of generated request IDs.
Changes:
- Replace
Randomimport withSecureRandom. - Update the static RNG field to use
SecureRandomwhile keeping the existingcreateID()logic intact.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
Hi @NipunaMadhushan , I’ve submitted this PR to WSO2 Identity Server and all automated checks have passed. Regards, |



Problem
The createID() method used java.util.Random, which relies on a linear congruential generator (LCG). LCGs are not cryptographically secure — an attacker who observes a sufficient number of generated SAML request IDs can predict future values, enabling:
SAML request ID spoofing
Replay attacks against the SAML authentication flow
This is a violation of OWASP Top 10 — A02: Cryptographic Failures.
Changes
SAML2SSOTestBase.java: Replaced import java.util.Random with import java.security.SecureRandom
SAML2SSOTestBase.java: Changed field declaration from private static Random random = new Random() to private static SecureRandom random = new SecureRandom()
Impact
SecureRandom is backed by OS-level entropy sources and satisfies cryptographic unpredictability requirements. The nextBytes() call site at createID() requires no changes — the API is identical.
No functional behaviour changes; this is a security hardening fix.
Summary by CodeRabbit