Repository navigation
Keep the current session per request, not per store - #2
Merged
Merged
Conversation
A store is shared by every request but held the session in one field. A visitor with no cookie therefore kept the previous request's session and was sent that session's id as a cookie, which hands over the previous user's session. Concurrent requests overwrote each other the same way. Store now keeps the current session per fiber and SessionHandler releases it when the request ends, so each request starts from a fresh session unless its cookie names a stored one. Flash messages and the cookie store's request cookies are still shared state and are not changed here. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT5gvYGR83U2M4DyA6NA6f
Up to standards ✅🟢 Issues
|
Review found that the getter inserted a session for any fiber that read it and only SessionHandler released, so fibers that read the session outside a request (a spawned task, a WebSocket channel) were kept for good. Inserting now drops entries of fibers that have finished. A fiber spawned during a request still starts with a blank session; the store documents that it must capture the session before spawn. The release spec now materializes the session before raising, so it fails without the ensure, and the cookie spec asserts the cookie exists. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT5gvYGR83U2M4DyA6NA6f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 0, item 12 of the plan (first part): requests shared one session through the store.
A
Storeis shared by every request but held the session in a singlecurrent_sessionfield. Reproduced with a failing spec:current_sessionbecomes Alice's.load_fromfinds nothing to load, socurrent_sessionstays Alice's, andset_cookiesanswers with aSet-Cookiecarrying Alice's session id.So a visitor with no cookie was handed the previous user's session. Concurrent requests overwrote each other's session the same way.
Fix
Storekeeps the current session per fiber (current_session,current_session=,release). The four stores no longer define their own field.SessionHandlercallsreleasewhen the request ends (ensure), so a keep-alive connection's next request starts fresh, unless its cookie names a stored session.Specs
spec/request_isolation_spec.crhas two examples:Full suite: 395 examples, 0 failures on Crystal 1.22.0.
crystal tool format --checkis clean.Not in this PR
@flashis also one instance shared by all requests, so flash messages can reach another user. It needs to live in the session data, which changes theFlashAPI.CookieStore#cookiesis shared per-request state of the same kind.regenerate_idon authentication, refusing the default secret outside development, and a real client binding (validate_session_bindingis a stub) remain from the plan.Generated by Claude Code