🐛 bug: fix query/form/param/custom extractor session IDs being discarded on first use#4235
Draft
🐛 bug: fix query/form/param/custom extractor session IDs being discarded on first use#4235
Conversation
3 tasks
… no data found in store Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/eb400386-f910-4188-a7b8-33bb8fba5d4f Co-authored-by: ReneWerner87 <[email protected]>
…curity note Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/eb400386-f910-4188-a7b8-33bb8fba5d4f Co-authored-by: ReneWerner87 <[email protected]>
Copilot
AI
changed the title
[WIP] Fix query extractor failure for session ID
🐛 bug: fix query/form/param/custom extractor session IDs being discarded on first use
Apr 25, 2026
Member
|
@ReneWerner87 The solution it implemented seems kind of weird |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4235 +/- ##
==========================================
- Coverage 91.17% 91.12% -0.06%
==========================================
Files 123 123
Lines 12084 12103 +19
==========================================
+ Hits 11018 11029 +11
- Misses 668 674 +6
- Partials 398 400 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
I will check it tomorrow |
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.
When using read-only session extractors (query, form, param, custom), the client-provided session ID was silently discarded whenever no session data existed in storage for that ID. A new random ID was generated instead — but never communicated back to the client (these sources are write-only; no
Set-Cookie/response header is written). Every request created an orphaned session, making persistent sessions via query parameters impossible.Root cause
In
Store.getSession, therawData == nilbranch unconditionally resetid = ""and calledKeyGenerator(). This is correct for cookie/header sources (prevents session fixation) but wrong for read-only sources where the client re-presents the same ID on every request and has no way to discover a server-generated replacement.Changes introduced
middleware/session/store.gogetSessionIDnow returns(string, bool)— the session ID and whether the extraction source is writable (cookie or header). For chained extractors, the function iterates sub-extractors in order so writability is determined by the source that actually matched, not the chain's primary source.getSessionbranches onwritableSourcewhen no storage data is found:A security note is added to the read-only branch explaining the inherent tradeoff.
middleware/session/store_test.goTest_Store_getSessionIDfor the new two-value return; asserts writability per source type.Cookie→Querystill rejects an unknown cookie ID; chainedCookie→Querypreserves the query fallback ID when no cookie is present.Example — now works as documented
getSessionID) only; no public API affected.Type of change
Checklist
/docs/directory for Fiber's documentation.