[Security] Replace Math.random link codes and lock down notification channel linking
Overview & Background
The notification channel link flow trusts client-supplied address and generates its verification code with Math.random(). POST /link-code (backend/src/routes/v1/notifications.routes.ts:24-30) passes req.body.address straight to generateLinkCode, with no auth, and returns the created record including the code to the caller. The code itself is Math.random().toString(36).slice(2, 8) — 6 chars from a non-crypto PRNG (notification.service.ts:63-68). linkTelegram and setDiscordWebhook likewise accept any address. Anyone can attach their own chat to any wallet and read its notifications. Mitigating factor: the router is currently never mounted (latent), but it becomes exploitable the moment it is wired in.
Technical Specification & Architecture
- Require auth on all notification routes; enforce
address === req.user.publicKey. - Generate codes with
crypto.randomBytesand never return the code in the generate response — it must be delivered out-of-band. - Delete the unmounted router if the feature is not shipping, so the latent hole cannot be activated by a one-line mount.
Target Files
backend/src/routes/v1/notifications.routes.tsbackend/src/services/notification.service.ts
Acceptance Criteria
- [ ] No code path generates link codes with
Math.random. - [ ] Link endpoints require auth and reject mismatched addresses.
- [ ] The generate response does not contain the code.
- [ ] Unmounted/dormant routers are removed or explicitly gated behind a feature flag.
@Joyful12-tech has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
I would like to work on this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Joyful12-tech to this issue.
@king-daveed has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
i can resolve
ℹ️ Repo Maintainers: To accept this application, review their application or assign @king-daveed to this issue.
Congratulations, @king-daveed! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.
🧑💻 @king-daveed: 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 @king-daveed as part of the Stellar Wave Program's 11th Wave 🥳
😎 @king-daveed: 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.