[Backend] SSE controller still generates clientId with Math.random(), not crypto.randomUUID
Labels: backend, bug, refactor, third-wave-audit File/location: backend/src/controllers/sse.controller.ts:79
Description:
const clientId = \${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;is collision-prone (Math.random is not cryptographically strong and the string is short), letting two concurrently-connecting clients theoretically collide on the same SSE client id and clobber each other's registration in sse.service. Every other id generator in the backend (sse.service.ts heartbeatWorkerId, soroban-event-worker.ts, indexerService.ts, requestId.ts) already usescrypto.randomUUID()` — this is the one remaining spot that doesn't.
Acceptance Criteria:
- [ ] sse.controller.ts generates clientId using crypto.randomUUID() (or an equivalent CSPRNG-based id) instead of Math.random()
- [ ] Existing SSE subscribe tests still pass with the new id format
Notes: Closed issue #680 ('sse.controller.ts: clientId uses Math.random — collision-prone, switch to crypto.randomUUID') already targeted this exact line and is marked CLOSED, but the code on main still shows Math.random() in use — the fix appears to not have landed on this file, or regressed.
Hi,
I have experience with similar implementations and would like to take this on.
Plan:
- Audit storage layout and state invariants ensuring strict auth guards.
- Implement deterministic state transitions with safe checked arithmetic.
- Add hermetic unit and regression tests covering authorized, unauthorized, and boundary edge cases.
- Profile instruction and CPU/gas limits under Soroban host environment.
Could you please assign this issue to me? Looking forward to delivering a clean PR.
@innocentharuna has applied to work on this issue as part of the Stellar Wave Program's 10th wave.
hey maintainer, please kindly assign this to me, i can surely fix it
ℹ️ Repo Maintainers: To accept this application, review their application or assign @innocentharuna to this issue.
@Teejay2696 has applied to work on this issue as part of the Stellar Wave Program's 10th wave.
Hi maintainer, I can fix this kindly assign
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Teejay2696 to this issue.
@fadesany has applied to work on this issue as part of the Stellar Wave Program's 10th wave.
Hello maintainer, i would like to work on this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @fadesany to this issue.
@CollinsKRO has applied to work on this issue as part of the Stellar Wave Program's 10th wave.
Hi Maintainer, I can fix this pls assign. ETA 5hrs
ℹ️ Repo Maintainers: To accept this application, review their application or assign @CollinsKRO to this issue.
Congratulations, @fadesany! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on October 22, 2026.
🧑💻 @fadesany: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
This issue has been completed by @fadesany as part of the Stellar Wave Program's 10th Wave 🥳
😎 @fadesany: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.