You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug][grounded-shop-assistant]: chat widget session ids come from Math.random() but act as a bearer secret for history #492
The server trusts that id completely. sessions.get(sessionId, ...) returns whatever session has that key, and chat-core puts that session's history straight into the LLM prompt (packages/chat-core/src/index.ts:66). So the session id is effectively a bearer secret for a shopper's conversation. Anyone who sends another shopper's id gets that shopper's last 12 turns as context, and the model can repeat them back.
Math.random() isn't meant for secrets: it isn't cryptographically random, and the output length varies (toString(36) of a double gives roughly 10–11 chars).
Expected Behavior
Session ids are unguessable.
Suggested fix
constsessionId=`sess_${crypto.randomUUID()}`;
crypto.randomUUID() is available in every browser the widget targets and in Node ≥ 19 (and in Node 18 as globalThis.crypto with the webcrypto flag, which only matters for tests). Pairs well with capping sessionId length server-side (#477).
Environment
main @ d4f0ac0.
Severity
Low — demo app, but the pattern gets copied into real widgets.
Hi! I'd like to work on this. My plan is to replace Math.random() in packages/chat-widget/src/mount.ts with crypto.randomUUID() (falling back to crypto.getRandomValues), and optionally validate the session ID format server-side.
Activity
GallaGit commentedon Oct 10, 2026
Hi! I'd like to work on this. My plan is to replace Math.random() in packages/chat-widget/src/mount.ts with crypto.randomUUID() (falling back to crypto.getRandomValues), and optionally validate the session ID format server-side.