Repository navigation
Keep flash messages in the session, not the store - #3
Conversation
A store is shared by every request but held one Flash, so a message one visitor set for their next request was shown to whichever visitor made the next request. Flash was already serializable but was never saved. The flash now belongs to the session (Session::Base#flash), is saved with it by every store, and is rotated when the session it belongs to is loaded, so a message reaches only the visitor it was set for and lasts for exactly one of their requests. Store#flash returns the current session's. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT5gvYGR83U2M4DyA6NA6f
Up to standards ✅🟢 Issues
|
|
The Generated by Claude Code |
Summary
Phase 0, item 12 of the plan (second part), and the follow-up flagged in #2.
A
Storeis shared by every request but held oneFlash. A message one visitor set for their next request was therefore shown to whichever visitor made the next request: one user's "Welcome back, alice" (or an error message with personal data) could be rendered for another.Session::Base#flashholds the flash. It was alreadyJSON::Serializablebut was never saved anywhere, so it now travels with the session through every store (memory, Redis, cookie).Store#flashreturns the current session's flash.next→now) when the session it belongs to is loaded, so a message reaches only the visitor it was set for and lasts for exactly one of their requests.Specs
spec/flash_isolation_spec.cr: a message set in Alice's request is not shown to Bob's request and is shown to Alice's next one (fails if the flash is shared again); a message lasts for exactly one request; the flash round-trips through the session's JSON.store_spec's "rotates flash on load" encoded the bug (it set a flash on a store with no session and expected rotation); it now rotates the flash of a loaded session.crystal tool format --checkis clean; 483 examples, 0 failures on Crystal 1.22.0.Behaviour change
Code that wrote to
store.flashbefore a session existed for the request now writes to the (new) current session, whichSessionHandlersaves as usual. CustomSession::Basesubclasses with their ownflashmember will clash.Still to do from the plan
CookieStore#cookiesis still per-request state kept on the shared store;regenerate_idon authentication; refusing the default secret outside development; and a real client binding (validate_session_bindingis a stub).Generated by Claude Code