feat(middleware/session): Introduce Extractor pattern for session ID retrieval#3625
feat(middleware/session): Introduce Extractor pattern for session ID retrieval#3625ReneWerner87 merged 19 commits intomainfrom
Conversation
- Replaced string-based KeyLookup with a flexible Extractor function pattern. - Updated session middleware to support Extractor for cookie, header, query, and form. - Added new Regenerate method to preserve session data while changing session ID. - Enhanced session lifecycle management by requiring manual session release. - Updated tests to reflect changes in session ID extraction and regeneration. - Introduced error handling for missing session IDs in various contexts.
…in session management
WalkthroughThis update modernizes the Fiber session middleware by replacing the string-based Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FiberApp
participant SessionMiddleware
participant Extractor
participant Store
Client->>FiberApp: Sends HTTP request
FiberApp->>SessionMiddleware: Passes request
SessionMiddleware->>Extractor: Extract session ID (e.g., FromCookie)
Extractor-->>SessionMiddleware: Returns session ID or error
alt session ID found
SessionMiddleware->>Store: Retrieve session by ID
else no session ID
SessionMiddleware->>Store: Create new session
end
SessionMiddleware-->>FiberApp: Attach session to context
FiberApp->>SessionMiddleware: (on response) Save session
SessionMiddleware->>Store: Save session data
Store-->>SessionMiddleware: Ack
SessionMiddleware->>Client: Set cookie with session ID
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)docs/**📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (2)📓 Common learningsdocs/middleware/session.md (31)Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: ReneWerner87 Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: hcancelik Learnt from: hcancelik Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: sixcolors Learnt from: gaby Learnt from: mdelapenya Learnt from: gaby Learnt from: gaby Learnt from: efectn Learnt from: sixcolors Learnt from: sixcolors 🪛 LanguageTooldocs/middleware/session.md[style] ~338-~338: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym. (ADVERB_REPETITION_PREMIUM) [style] ~339-~339: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym. (ADVERB_REPETITION_PREMIUM) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @sixcolors, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a more robust and flexible session ID extraction mechanism, moving from a simple string lookup to a powerful function-based Extractor pattern. It also enhances session security by adding a Regenerate method to prevent session fixation and provides comprehensive documentation updates to guide users on best practices for session management and security in Fiber applications.
Highlights
- Flexible Session ID Extraction: The previous string-based
KeyLookupconfiguration for session ID retrieval has been replaced with a new, more flexibleExtractorfunction pattern. This allows session IDs to be extracted from various sources including cookies, headers, URL queries, form data, and URL path parameters. AChainfunction is also introduced to allow multiple extraction methods with fallback. - Enhanced Session Lifecycle Management: A new
Regeneratemethod has been added to the session middleware. This method allows changing the session ID while preserving all existing session data, which is a critical security feature to prevent session fixation attacks, especially after user authentication. The documentation now clearly distinguishes betweenRegenerate,Reset(change ID, clear data), andDestroy(keep ID, clear data). - Improved Security Practices and Documentation: The session middleware documentation has been significantly updated to provide clearer guidance on usage patterns, security best practices (including session fixation prevention), and detailed configuration options. It also clarifies the manual session release requirement for the advanced 'Store Pattern' usage.
- Refined Session Timeout Handling: The session expiration logic has been refined, replacing the single
Expirationfield with distinctIdleTimeout(inactivity timeout) andAbsoluteTimeout(maximum session duration) fields for more precise control over session lifespan.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces the Extractor pattern for session ID retrieval, enhancing session middleware flexibility. The documentation has been extensively updated. I have provided suggestions to improve clarity in the documentation and address a potential point of confusion in the configuration.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
docs/whats_new.md (1)
1309-1309: Fix duplicate heading to resolve markdownlint warning.The heading "### Session" appears twice in this section, causing a markdownlint violation. Consider differentiating the headings to clearly distinguish their content.
-### Session +### Session Extractor PatternOr alternatively, consider combining the content under a single section with appropriate subheadings.
middleware/session/extractors.go (1)
40-49: FromForm implementation with minor documentation improvement needed.The implementation correctly uses
c.FormValue(param)which handles both multipart and URL-encoded forms. However, the comment on line 40 says "multipart-form" when it actually supports both form encoding types.Consider updating the comment for accuracy:
-// FromForm returns a function that extracts session ID from a multipart-form. +// FromForm returns a function that extracts session ID from form data (both multipart and URL-encoded).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
docs/middleware/session.md(1 hunks)docs/whats_new.md(1 hunks)middleware/csrf/csrf_test.go(3 hunks)middleware/session/config.go(4 hunks)middleware/session/config_test.go(2 hunks)middleware/session/extractors.go(1 hunks)middleware/session/extractors_test.go(1 hunks)middleware/session/middleware.go(1 hunks)middleware/session/middleware_test.go(4 hunks)middleware/session/session.go(1 hunks)middleware/session/session_test.go(2 hunks)middleware/session/store.go(2 hunks)middleware/session/store_test.go(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/**
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Review and update the contents of the
docsfolder if necessary when modifying code
Files:
docs/whats_new.mddocs/middleware/session.md
🧠 Learnings (14)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
middleware/session/session_test.go (23)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-02T23:02:12.306Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
middleware/session/middleware.go (16)
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
middleware/session/config_test.go (16)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in DecryptCookie have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in DecryptCookie have been added to ensure consistency and security in the encryption processes.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: efectn
PR: #3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the require methods from the testify package for assertions instead of manual comparisons and calls to t.Fatal or t.Fatalf.
Learnt from: gaby
PR: #3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in ctx_test.go, it is acceptable to use invalid CIDR notation such as "0.0.0.1/31junk" for testing purposes.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
middleware/session/store_test.go (15)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
docs/whats_new.md (11)
Learnt from: ckoch786
PR: #3230
File: docs/whats_new.md:944-951
Timestamp: 2024-12-15T19:56:45.935Z
Learning: Detailed usage examples and explanations for new methods like RemoveRoute and RemoveRouteByName are documented in docs/api/app.md, so it's unnecessary to duplicate them in docs/whats_new.md.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
middleware/session/store.go (15)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-02T23:02:12.306Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
middleware/session/middleware_test.go (20)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
middleware/session/session.go (12)
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
middleware/csrf/csrf_test.go (17)
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
middleware/session/extractors.go (10)
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
middleware/session/config.go (14)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the Test method in app.go.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: mdelapenya
PR: #3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-09-26T03:08:50.917Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
middleware/session/extractors_test.go (15)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in DecryptCookie have been added to ensure consistency and security in the encryption processes.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
docs/middleware/session.md (12)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
🧬 Code Graph Analysis (7)
middleware/session/session_test.go (2)
middleware/session/extractors.go (1)
FromHeader(52-60)middleware/csrf/extractors.go (1)
FromHeader(43-51)
middleware/session/middleware.go (1)
middleware/session/session.go (1)
Session(17-25)
middleware/session/store_test.go (1)
middleware/session/extractors.go (2)
FromHeader(52-60)FromQuery(63-71)
middleware/session/middleware_test.go (3)
constants.go (4)
StatusInternalServerError(103-103)StatusOK(52-52)MethodPost(7-7)HeaderSetCookie(197-197)middleware/session/middleware.go (1)
FromContext(178-184)middleware/session/extractors.go (1)
FromCookie(19-27)
middleware/session/session.go (1)
constants.go (3)
CookieSameSiteStrictMode(313-313)CookieSameSiteNoneMode(314-314)CookieSameSiteLaxMode(312-312)
middleware/csrf/csrf_test.go (1)
middleware/session/extractors.go (1)
FromCookie(19-27)
middleware/session/extractors_test.go (3)
middleware/session/extractors.go (10)
FromCookie(19-27)ErrMissingSessionIDInCookie(15-15)FromHeader(52-60)ErrMissingSessionIDInHeader(11-11)FromQuery(63-71)ErrMissingSessionIDInQuery(12-12)FromForm(41-49)FromParam(30-38)Chain(77-104)ErrMissingSessionID(10-10)ctx_interface_gen.go (1)
Ctx(17-395)constants.go (1)
MethodGet(5-5)
🪛 markdownlint-cli2 (0.17.2)
docs/whats_new.md
1309-1309: Multiple headings with the same content
(MD024, no-duplicate-heading)
🔇 Additional comments (37)
middleware/session/store_test.go (2)
39-39: LGTM! Correct migration to extractor pattern.The change from
KeyLookup: "header:session_id"toExtractor: FromHeader("session_id")properly implements the new functional extractor approach, providing better type safety and error handling.
55-55: LGTM! Consistent extractor pattern implementation.The change from
KeyLookup: "query:session_id"toExtractor: FromQuery("session_id")maintains consistency with the new extractor approach and provides improved error handling for missing query parameters.middleware/session/middleware.go (1)
306-322: Excellent security enhancement with proper implementation.The new
Regenerate()method correctly implements session ID regeneration for preventing session fixation attacks. The implementation follows established patterns with proper mutex locking, clear documentation, and appropriate delegation to the underlying session.middleware/session/session_test.go (2)
535-535: LGTM! Proper migration to extractor pattern in save test.The change from
KeyLookup: "header:session_id"toExtractor: FromHeader("session_id")correctly updates the test configuration to use the new functional extractor approach while maintaining the same test coverage.
730-730: LGTM! Consistent extractor pattern implementation in destroy test.The change from
KeyLookup: "header:session_id"toExtractor: FromHeader("session_id")maintains consistency with the migration to functional extractors and ensures comprehensive test coverage of the new configuration approach.docs/whats_new.md (1)
1310-1316: Excellent documentation of the Session middleware improvements.The content accurately describes the key architectural changes in the session middleware, particularly the transition from string-based
KeyLookupto the type-safeExtractorfunction pattern. This aligns well with the PR objectives and provides clear value to developers migrating to v3.middleware/session/store.go (1)
187-205: Excellent refactoring to support the new Extractor pattern.The implementation successfully replaces the previous manual extraction logic with a clean, unified approach using the configured extractor function. Key benefits of this change:
- Modularity: Session ID extraction is now centralized and configurable
- Type Safety: Replaces string-based KeyLookup with functional extractors
- Graceful Error Handling: Returning empty string on extraction failure allows seamless fallback to new session generation
- Consistency: Aligns with the broader architectural improvements in the session middleware
The error handling approach is particularly well-designed, as it maintains the existing behavior where extraction failures result in new session creation rather than propagating errors up the stack.
middleware/csrf/csrf_test.go (3)
79-79: LGTM! Correctly updated to use the new extractor pattern.The change from
KeyLookup: "cookie:_session"toExtractor: session.FromCookie("_session")properly adopts the new functional extractor approach while maintaining equivalent functionality.
277-277: LGTM! Consistent with the extractor pattern migration.Same correct update as the previous test function, ensuring consistency across the test suite.
1093-1093: LGTM! Completes the extractor pattern migration.Final update to the new extractor pattern, ensuring all session configurations in the CSRF tests are consistently updated.
middleware/session/config_test.go (4)
17-19: LGTM! Correctly validates the new configuration structure.The test properly validates that the default config includes a non-nil
Extractorfunction and sets theCookieSameSiteto "Lax", which aligns with modern cookie security practices.
26-28: LGTM! Properly demonstrates custom extractor configuration.The test correctly uses
FromHeader("X-Custom-Session")extractor and explicitly sets thesessionName, showing the proper usage pattern for custom session configurations.
33-34: LGTM! Validates custom configuration correctly.The assertions properly verify that both the custom extractor function and session name are correctly applied in the configuration.
49-56: LGTM! Adds important timeout validation coverage.The new test properly validates that
AbsoluteTimeoutcannot be less thanIdleTimeout, which is a sensible security constraint. The test uses appropriatetestifyassertions and checks for the specific panic message.middleware/session/session.go (2)
376-405: LGTM! Unified cookie handling with clear behavioral documentation.The method now consistently sets cookies for all sessions regardless of extraction source. The explicit comment about this behavioral change is helpful. The implementation properly handles all cookie attributes including SameSite modes and uses fasthttp cookie pooling for performance.
Note: This is a breaking change for applications that relied on header-only sessions without cookie creation.
407-437: LGTM! Consistent cookie deletion approach.The method now uniformly handles cookie deletion by removing from both request/response headers and setting an expired cookie for client-side cleanup. The implementation maintains consistency with the
setSession()method's unified approach and properly handles all cookie attributes.middleware/session/middleware_test.go (4)
59-72: Enhanced test coverage for session reset functionality.The test now properly validates that
Reset()clears session data by explicitly setting a value before reset and verifying it's cleared afterward. This is a good improvement over the previous implementation.
74-97: Comprehensive test coverage for new session regeneration functionality.The test properly validates that
Regenerate()changes the session ID while preserving existing session data. The error handling and data preservation checks are well-implemented.
160-160: Integration test coverage for session regeneration endpoint.The test sequence properly validates the regenerate functionality in the HTTP request/response cycle, following the same pattern as other endpoint tests. The token validation logic correctly ensures a new session ID is generated.
Also applies to: 231-247
392-392: Migration to new Extractor pattern configuration.The configuration correctly migrates from the deprecated
KeyLookupstring field to the newExtractorfunction field usingFromCookie("session_id_test"). This aligns with the broader refactoring in the session middleware.middleware/session/config.go (4)
37-40: Well-designed Extractor field replacement for KeyLookup.The new
Extractorfield provides a type-safe, flexible approach to session ID extraction. The function signaturefunc(c fiber.Ctx) (string, error)properly supports custom extraction logic with error handling, which is a significant improvement over string-based configuration.
57-59: Updated documentation reflects new sessionName derivation logic.The comment correctly explains that
sessionNameis now derived from theExtractorconfiguration or defaults to "session_id", which accurately describes the new behavior after the KeyLookup removal.
96-101: Secure and practical default configuration.The updated
ConfigDefaultprovides sensible defaults withFromCookie("session_id")for the extractor and"Lax"forCookieSameSite. These defaults are secure and suitable for most web applications.
151-159: Significantly simplified configuration logic.The
configDefaultfunction is now much cleaner and more maintainable, replacing complex string parsing logic with simple nil checks and default assignments. This reduction in complexity improves code reliability and readability.middleware/session/extractors_test.go (6)
13-20: Clean helper function for HTTP request creation.The
newRequesthelper function is well-implemented with clear purpose and appropriate error handling for test contexts. The use ofcontext.Background()and panic for setup errors is correct for test utilities.
22-49: Comprehensive test coverage for FromCookie extractor.The tests properly validate both success and error scenarios for cookie-based session ID extraction. The resource management with
defer app.ReleaseCtx(ctx)and proper error type validation demonstrate good testing practices.
51-78: Consistent and thorough FromHeader extractor tests.The header-based extraction tests follow the same high-quality patterns as the cookie tests, with proper header manipulation using
ctx.Request().Header.Set()and specific error type validation.
80-109: Effective validation of query parameter extraction.The FromQuery tests properly simulate query parameter scenarios using
SetRequestURI()and validate both successful extraction and missing parameter error cases. The URL construction is realistic and the error handling validation is thorough.
131-150: Complex but necessary route parameter testing.The FromParam test correctly handles the complexity of testing route parameters by setting up actual routes and using
app.Test(). The test structure is appropriate for validating parameter extraction within the routing context where parameters are available.
152-218: Excellent comprehensive testing of Chain function.The Chain function tests cover all important scenarios including extractor priority, fallback behavior, complete failure, and edge cases. The test setup properly simulates different request conditions to validate the chaining logic and error propagation.
middleware/session/extractors.go (6)
9-16: Well-designed error constants for extraction failures.The error constants provide specific, descriptive errors for each extraction source, which will greatly help with debugging session ID retrieval issues. The comprehensive coverage and clear naming follow Go conventions well.
18-27: Clean and correct FromCookie implementation.The implementation properly uses the closure pattern to capture the cookie key and uses the appropriate
c.Cookies(key)method. The error handling for empty cookies withErrMissingSessionIDInCookieis correct and follows the established pattern.
29-38: Consistent FromParam implementation.The route parameter extraction follows the same clean closure pattern and uses the appropriate
c.Params(param)method. The error handling is consistent with other extractors.
51-60: Correct and consistent FromHeader implementation.The header extraction uses the appropriate
c.Get(param)method and follows the same clean patterns as other extractors. The error handling withErrMissingSessionIDInHeaderis consistent.
62-71: Modern FromQuery implementation using generic Query function.The implementation correctly uses
fiber.Query[string](c, param)which is the modern generic approach for query parameter extraction. The explicit type parameter and consistent error handling are well-implemented.
73-104: Sophisticated and well-designed Chain implementation.The Chain function handles complex extractor composition with proper edge case handling, clear priority logic, and appropriate error propagation. The documentation clearly explains the behavior, and the implementation correctly handles scenarios like empty extractor lists and mixed success/failure cases.
docs/middleware/session.md (1)
1-677: Excellent comprehensive documentation for session middleware v3.This documentation update is exemplary, providing:
- Complete coverage of new v3 features (extractors, regeneration, security methods)
- Practical examples including production configurations with Redis and security settings
- Security best practices with clear explanations of session fixation prevention
- Migration guide helping users transition from v2 to v3 patterns
- Comprehensive API reference covering both middleware and store patterns
- Real-world examples like the e-commerce cart preservation scenario
The documentation structure is logical, examples are practical, and the security guidance is particularly valuable. This will significantly help developers understand and properly implement session management.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
middleware/session/config.go (1)
151-159: Consider adding validation for extractor/sessionName consistency.The default value assignment logic is correct and follows established patterns. However, consider adding validation to ensure
sessionNamematches cookie-based extractors when both are user-provided.if cfg.CookieSameSite == "" { cfg.CookieSameSite = ConfigDefault.CookieSameSite } + + // Validate consistency between extractor and sessionName for cookie-based extractors + // This helps prevent common configuration mistakes + validateExtractorConsistency(&cfg)This would help catch configuration mismatches early and provide better developer experience.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
middleware/session/config.go(4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
middleware/session/config.go (17)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".
Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the Test method in app.go.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: mdelapenya
PR: #3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-09-26T03:08:50.917Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
🔇 Additional comments (2)
middleware/session/config.go (2)
37-40: LGTM: Clean extractor pattern implementation.The function-based
Extractorfield provides excellent flexibility for session ID retrieval from various sources while maintaining a clean, testable interface. The signature(string, error)properly handles extraction failures.
95-101: LGTM: Well-designed default configuration.The defaults provide a secure, functional baseline:
FromCookie("session_id")with matchingsessionNameensures consistencyCookieSameSite: "Lax"provides good CSRF protection- Configuration works out-of-the-box for typical web applications
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (2)
middleware/session/session.go (1)
376-376: Remove obsoletesourcelogic and add hooks for writing/deleting session IDsThe
Configstruct no longer has asourcefield—only anExtractor. As a result, theif s.config.source == SourceHeader { … } else { … }branches in bothsetSession()anddelSession()won’t compile and don’t fit the new “Extractor‐only” design. You’ll need to:• Remove all
s.config.sourcechecks in
‑ middleware/session/session.go: (*Session).setSession
‑ middleware/session/session.go: (*Session).delSession• Introduce new config fields for writing/removing session IDs, for example:
type Config struct { // … existing fields … Extractor func(c fiber.Ctx) (string, error) Inserter func(c fiber.Ctx, name, value string) Deleter func(c fiber.Ctx, name string) }• Provide defaults in
ConfigDefault:ConfigDefault = Config{ Extractor: FromCookie("session_id"), Inserter: func(c fiber.Ctx, name, value string) { cookie := fasthttp.AcquireCookie() defer fasthttp.ReleaseCookie(cookie) cookie.SetKey(name) cookie.SetValue(value) c.Response().Header.SetCookie(cookie) }, Deleter: func(c fiber.Ctx, name string) { c.Response().Header.DelCookie(name) }, // … other defaults … }• Update
setSession()to simply call:s.config.Inserter(s.ctx, s.config.sessionName, s.id)• And
delSession()to call:s.config.Deleter(s.ctx, s.config.sessionName)This aligns the write/delete side with the new
Extractorpattern and restores cookie‐only defaults while allowing header‐based or custom storage logic.docs/whats_new.md (1)
1305-1320: Duplicate “Session” heading triggers MD024 and breaks anchorsThere is already a
### Sessionheading at line 1305.
The second one introduced here (1311-1313) violates markdown-lint rule MD024 and will confuse generated anchors (#session), causing broken in-page links.-### Session - -The session middleware has undergone significant improvements in v3, focusing on type safety, flexibility, and better developer experience. +#### Improvements summary + +The session middleware in v3 focuses on type safety, flexibility, and an improved developer experience.Adjust the heading level (or merge the content into the first “Session” subsection) so there is only one third-level “Session” heading in this file.
[static_analysis_hints:MD024]
♻️ Duplicate comments (3)
docs/middleware/session.md (3)
42-44: Type assertion safety concern (partially addressed from previous review).The stale value issue has been fixed, but the unsafe type assertion
visits.(int)remains. If the session contained a non-integer value, this would cause a panic.Consider using a safe type assertion:
- newVisits := 1 - if visits != nil { - newVisits = visits.(int) + 1 - } + newVisits := 1 + if visits != nil { + if v, ok := visits.(int); ok { + newVisits = v + 1 + } + }
433-436: Remove irrelevant JSON tags for gob encoding.Since session data is encoded using Go's
gobpackage (as documented), the JSON tags are irrelevant and could be misleading.type User struct { - ID int `json:"id"` - Name string `json:"name"` - Role string `json:"role"` + ID int + Name string + Role string }
298-299: Clarify cookie behavior for non-cookie extractors.The session middleware will always set a
Set-Cookieheader in the response, regardless of how the session ID was extracted. This might be unexpected for API clients using headers.Consider adding clarification:
-// Header-based (recommended for APIs) -session.FromHeader("X-Session-ID") +// Header-based (recommended for APIs) +// Note: Response will still include Set-Cookie header +session.FromHeader("X-Session-ID")
🧹 Nitpick comments (3)
docs/middleware/session.md (3)
98-102: Fix markdown formatting - add blank lines around lists.The markdown linter requires blank lines before and after lists for proper formatting.
**Benefits:** + - Automatic session saving - Automatic resource cleanup - No manual lifecycle management - Thread-safe operations +
134-138: Fix markdown formatting - add blank lines around lists.**Requirements:** + - Must call `sess.Release()` when done - Must call `sess.Save()` to persist changes - Handle errors manually +
500-516: Fix markdown formatting - add blank lines around fenced code blocks.**v2 Code:** + ```go store := session.New(session.Config{ KeyLookup: "cookie:session_id", }) app.Get("/", func(c fiber.Ctx) error { sess, err := store.Get(c) if err != nil { return err } // Session automatically saved and released sess.Set("key", "value") return nil })
</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 176e65944da68e20e2267943a5685dc98e10095f and 6cf8f4561bbd9f1669d49d5962a0432961c2f1ce. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `docs/middleware/session.md` (1 hunks) * `docs/whats_new.md` (1 hunks) * `middleware/session/extractors_test.go` (1 hunks) * `middleware/session/session.go` (2 hunks) * `middleware/session/session_test.go` (2 hunks) </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * middleware/session/extractors_test.go * middleware/session/session_test.go </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>📓 Path-based instructions (1)</summary> <details> <summary>docs/**</summary> **📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)** > Review and update the contents of the `docs` folder if necessary when modifying code Files: - `docs/middleware/session.md` - `docs/whats_new.md` </details> </details><details> <summary>🧠 Learnings (4)</summary> <details> <summary>📓 Common learnings</summary>Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middlewareConfigstruct, theExtractorfield uses function closures (likeFromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in bothEncryptCookieandDecryptCookiefunctions have been added to ensure robust validation and prevent potential runtime errors.Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in bothEncryptCookieandDecryptCookiefunctions have been added to ensure robust validation and prevent potential runtime errors.Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middlewareConfigstruct,Storeis backed byfiber.Storage; they are different entities serving distinct purposes in session management.Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middlewareConfigstruct,Storeis backed byfiber.Storage; they are different entities serving distinct purposes in session management.Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement inDecryptCookiehave been added to ensure consistency and security in the encryption processes.Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement inDecryptCookiehave been added to ensure consistency and security in the encryption processes.Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in theTestmethod inapp.go.Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.</details> <details> <summary>docs/middleware/session.md (28)</summary> Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:16-26 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:16-26 Timestamp: 2024-09-25T16:17:00.969Z Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:164-165 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the `Test_CSRF_WithSession_Middleware` function, calling `session.NewWithStore()` without arguments is acceptable, as the default configuration is sufficient. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:164-165 Timestamp: 2024-09-25T17:08:07.693Z Learning: In the `Test_CSRF_WithSession_Middleware` function, calling `session.NewWithStore()` without arguments is acceptable, as the default configuration is sufficient. Learnt from: ReneWerner87 PR: gofiber/fiber#3598 File: docs/middleware/csrf.md:364-366 Timestamp: 2025-07-19T18:04:19.891Z Learning: Both `*Session` and `*Middleware` in the session package have `Destroy()` methods with the signature `func Destroy() error` that take no arguments. The method is called directly on the session middleware instance without any parameters. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/session_manager.go:30-43 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware, `session.FromContext(c)` returns `*session.Middleware`, whereas `m.session.Get(c)` returns `*session.Store`, so they are not directly interchangeable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/session_manager.go:30-43 Timestamp: 2024-09-25T16:15:39.392Z Learning: In the session middleware, `session.FromContext(c)` returns `*session.Middleware`, whereas `m.session.Get(c)` returns `*session.Store`, so they are not directly interchangeable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:26-26 Timestamp: 2024-09-25T16:18:46.641Z Learning: In the session middleware, the `newStore`, `New`, and `NewWithStore` functions ensure that a `Store` is present even if it is not initialized in `ConfigDefault`. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:26-26 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware, the `newStore`, `New`, and `NewWithStore` functions ensure that a `Store` is present even if it is not initialized in `ConfigDefault`. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-10-08T19:06:06.583Z Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:188-193 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:188-193 Timestamp: 2024-09-25T15:57:10.221Z Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary. Learnt from: sixcolors PR: gofiber/fiber#3625 File: middleware/session/config.go:57-58 Timestamp: 2025-07-27T17:28:53.382Z Learning: In the session middleware `Config` struct, the `Extractor` field uses function closures (like `FromCookie(key)`), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques. Learnt from: sixcolors PR: gofiber/fiber#3598 File: docs/middleware/csrf.md:37-42 Timestamp: 2025-07-19T14:06:29.884Z Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax". Learnt from: hcancelik PR: gofiber/fiber#3036 File: docs/middleware/cache.md:103-103 Timestamp: 2024-10-08T19:06:06.583Z Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content. Learnt from: hcancelik PR: gofiber/fiber#3036 File: docs/middleware/cache.md:103-103 Timestamp: 2024-06-15T19:26:06.401Z Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:272-293 Timestamp: 2024-10-02T15:16:39.868Z Learning: In the `middleware/session/session.go` file, the `saveSession()` method returns either `nil` or an error, so additional error wrapping in the `Save()` method is unnecessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:272-293 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the `middleware/session/session.go` file, the `saveSession()` method returns either `nil` or an error, so additional error wrapping in the `Save()` method is unnecessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:46-61 Timestamp: 2024-10-02T23:02:12.306Z Learning: In this codebase, the `sessionPool` only contains `Session` instances, so type assertions without additional checks are acceptable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/middleware_test.go:400-407 Timestamp: 2024-09-25T17:09:03.756Z Learning: In the `Test_Session_Next` function in `middleware/session/middleware_test.go`, the variable `doNext` is properly synchronized with the `muNext` mutex for both read and write access. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:46-61 Timestamp: 2024-10-08T19:06:06.583Z Learning: In this codebase, the `sessionPool` only contains `Session` instances, so type assertions without additional checks are acceptable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:122-122 Timestamp: 2024-09-25T16:18:34.719Z Learning: In `DefaultErrorHandler(c *fiber.Ctx, err error)`, since `c` is a pointer to an interface, we need to dereference `*c` when calling interface methods like `SendStatus`. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:122-122 Timestamp: 2024-10-08T19:06:06.583Z Learning: In `DefaultErrorHandler(c *fiber.Ctx, err error)`, since `c` is a pointer to an interface, we need to dereference `*c` when calling interface methods like `SendStatus`. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-06-30T00:38:06.580Z Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-10-08T19:06:06.583Z Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-06-30T00:38:06.580Z Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`. Learnt from: gaby PR: gofiber/fiber#3193 File: middleware/cache/cache_test.go:897-897 Timestamp: 2024-11-08T04:10:42.990Z Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions. Learnt from: mdelapenya PR: gofiber/fiber#3434 File: docs/api/services.md:39-43 Timestamp: 2025-05-07T13:07:33.899Z Learning: When documenting Go interface methods in the Fiber project, avoid showing method signatures with the interface type as the receiver (e.g., `func (d *Service) Method()`) since interfaces cannot be used as receivers in Go. Instead, show just the method signature without a receiver or use a placeholder implementation name. </details> <details> <summary>docs/whats_new.md (13)</summary> Learnt from: ckoch786 PR: gofiber/fiber#3230 File: docs/whats_new.md:944-951 Timestamp: 2024-12-15T19:56:45.935Z Learning: Detailed usage examples and explanations for new methods like `RemoveRoute` and `RemoveRouteByName` are documented in `docs/api/app.md`, so it's unnecessary to duplicate them in `docs/whats_new.md`. Learnt from: hcancelik PR: gofiber/fiber#3036 File: docs/middleware/cache.md:103-103 Timestamp: 2024-06-15T19:26:06.401Z Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content. Learnt from: hcancelik PR: gofiber/fiber#3036 File: docs/middleware/cache.md:103-103 Timestamp: 2024-10-08T19:06:06.583Z Learning: There are no hard tabs in the lines 100 to 105 of the `docs/middleware/cache.md` file. Future comments about formatting should accurately reflect the actual content. Learnt from: sixcolors PR: gofiber/fiber#3625 File: middleware/session/config.go:57-58 Timestamp: 2025-07-27T17:28:53.382Z Learning: In the session middleware `Config` struct, the `Extractor` field uses function closures (like `FromCookie(key)`), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:164-165 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the `Test_CSRF_WithSession_Middleware` function, calling `session.NewWithStore()` without arguments is acceptable, as the default configuration is sufficient. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:164-165 Timestamp: 2024-09-25T17:08:07.693Z Learning: In the `Test_CSRF_WithSession_Middleware` function, calling `session.NewWithStore()` without arguments is acceptable, as the default configuration is sufficient. Learnt from: ReneWerner87 PR: gofiber/fiber#3598 File: docs/middleware/csrf.md:364-366 Timestamp: 2025-07-19T18:04:19.891Z Learning: Both `*Session` and `*Middleware` in the session package have `Destroy()` methods with the signature `func Destroy() error` that take no arguments. The method is called directly on the session middleware instance without any parameters. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:16-26 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:16-26 Timestamp: 2024-09-25T16:17:00.969Z Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/session_manager.go:30-43 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware, `session.FromContext(c)` returns `*session.Middleware`, whereas `m.session.Get(c)` returns `*session.Store`, so they are not directly interchangeable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/session_manager.go:30-43 Timestamp: 2024-09-25T16:15:39.392Z Learning: In the session middleware, `session.FromContext(c)` returns `*session.Middleware`, whereas `m.session.Get(c)` returns `*session.Store`, so they are not directly interchangeable. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:26-26 Timestamp: 2024-09-25T16:18:46.641Z Learning: In the session middleware, the `newStore`, `New`, and `NewWithStore` functions ensure that a `Store` is present even if it is not initialized in `ConfigDefault`. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/config.go:26-26 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the session middleware, the `newStore`, `New`, and `NewWithStore` functions ensure that a `Store` is present even if it is not initialized in `ConfigDefault`. </details> <details> <summary>middleware/session/session.go (10)</summary> Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:272-293 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the `middleware/session/session.go` file, the `saveSession()` method returns either `nil` or an error, so additional error wrapping in the `Save()` method is unnecessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/session/session.go:272-293 Timestamp: 2024-10-02T15:16:39.868Z Learning: In the `middleware/session/session.go` file, the `saveSession()` method returns either `nil` or an error, so additional error wrapping in the `Save()` method is unnecessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:188-193 Timestamp: 2024-10-08T19:06:06.583Z Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/csrf_test.go:188-193 Timestamp: 2024-09-25T15:57:10.221Z Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-10-08T19:06:06.583Z Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-06-30T00:38:06.580Z Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions. Learnt from: ReneWerner87 PR: gofiber/fiber#3598 File: docs/middleware/csrf.md:364-366 Timestamp: 2025-07-19T18:04:19.891Z Learning: Both `*Session` and `*Middleware` in the session package have `Destroy()` methods with the signature `func Destroy() error` that take no arguments. The method is called directly on the session middleware instance without any parameters. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-10-08T19:06:06.583Z Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`. Learnt from: sixcolors PR: gofiber/fiber#3051 File: middleware/session/session.go:215-216 Timestamp: 2024-06-30T00:38:06.580Z Learning: The `session.Save()` method in the `middleware/session` package returns the `Session` back to `sync.Pool`. Learnt from: sixcolors PR: gofiber/fiber#3016 File: middleware/csrf/session_manager.go:30-43 Timestamp: 2024-09-25T16:15:39.392Z Learning: In the session middleware, `session.FromContext(c)` returns `*session.Middleware`, whereas `m.session.Get(c)` returns `*session.Store`, so they are not directly interchangeable. </details> </details><details> <summary>🪛 GitHub Check: markdownlint</summary> <details> <summary>docs/middleware/session.md</summary> [failure] 532-532: Fenced code blocks should be surrounded by blank lines docs/middleware/session.md:532 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md --- [failure] 518-518: Fenced code blocks should be surrounded by blank lines docs/middleware/session.md:518 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md --- [failure] 501-501: Fenced code blocks should be surrounded by blank lines docs/middleware/session.md:501 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md --- [failure] 494-494: Trailing spaces docs/middleware/session.md:494:78 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md009.md --- [failure] 484-484: Lists should be surrounded by blank lines docs/middleware/session.md:484 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Custom types must be registe..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md --- [failure] 284-284: Lists should be surrounded by blank lines docs/middleware/session.md:284 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `IdleTimeout`: Storage autom..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md --- [failure] 234-234: Fenced code blocks should be surrounded by blank lines docs/middleware/session.md:234 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md --- [failure] 223-223: Fenced code blocks should be surrounded by blank lines docs/middleware/session.md:223 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md --- [failure] 135-135: Lists should be surrounded by blank lines docs/middleware/session.md:135 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Must call `sess.Release()` w..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md --- [failure] 98-98: Lists should be surrounded by blank lines docs/middleware/session.md:98 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Automatic session saving"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md </details> </details> <details> <summary>🪛 GitHub Actions: markdownlint</summary> <details> <summary>docs/middleware/session.md</summary> [error] 98-98: markdownlint MD032/blanks-around-lists: Lists should be surrounded by blank lines [Context: "- Automatic session saving"] </details> </details> <details> <summary>🪛 markdownlint-cli2 (0.17.2)</summary> <details> <summary>docs/whats_new.md</summary> 1311-1311: Multiple headings with the same content (MD024, no-duplicate-heading) </details> </details> <details> <summary>🪛 GitHub Check: unit (1.24.x, ubuntu-latest)</summary> <details> <summary>middleware/session/session.go</summary> [failure] 398-398: undefined: fcookie --- [failure] 397-397: undefined: fcookie --- [failure] 427-427: undefined: fcookie --- [failure] 426-426: undefined: fcookie </details> </details> <details> <summary>🪛 GitHub Check: govulncheck-check</summary> <details> <summary>middleware/session/session.go</summary> [failure] 398-398: undefined: fcookie --- [failure] 397-397: undefined: fcookie --- [failure] 427-427: undefined: fcookie --- [failure] 426-426: undefined: fcookie </details> </details> <details> <summary>🪛 GitHub Check: modernize</summary> <details> <summary>middleware/session/session.go</summary> [failure] 398-398: undefined: fcookie --- [failure] 397-397: undefined: fcookie --- [failure] 427-427: undefined: fcookie --- [failure] 426-426: undefined: fcookie </details> </details> <details> <summary>🪛 GitHub Check: lint</summary> <details> <summary>middleware/session/session.go</summary> [failure] 398-398: undefined: fcookie --- [failure] 397-397: undefined: fcookie --- [failure] 427-427: undefined: fcookie) (typecheck) --- [failure] 426-426: undefined: fcookie </details> </details> <details> <summary>🪛 GitHub Actions: Run govulncheck</summary> <details> <summary>middleware/session/session.go</summary> [error] 376-376: govulncheck error: s.config.source undefined (type *Store has no field or method source) </details> </details> <details> <summary>🪛 GitHub Actions: Modernize Lint</summary> <details> <summary>middleware/session/session.go</summary> [error] 376-376: Compilation error: 's.config.source' undefined (type *Store has no field or method source) </details> </details> </details> <details> <summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)</summary> * GitHub Check: Compare * GitHub Check: repeated </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>docs/middleware/session.md (2)</summary> `7-18`: **Excellent documentation restructure and comprehensive coverage.** The documentation has been significantly improved with: - Clear progression from quick start to advanced usage - Comprehensive security guidance including session fixation prevention - Well-structured migration guide with practical examples - Multiple usage patterns (middleware vs store) - Production-ready configuration examples This provides developers with everything needed to implement secure session management. --- `147-245`: **Strong security guidance with proper session lifecycle management.** The authentication flow examples correctly demonstrate: - Session ID regeneration after login to prevent fixation attacks - Proper distinction between Regenerate(), Reset(), and Destroy() methods - Cart preservation during login flow - Secure vs insecure implementation comparisons This provides excellent guidance for secure session management implementation. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3625 +/- ##
==========================================
- Coverage 91.13% 91.11% -0.03%
==========================================
Files 112 113 +1
Lines 11296 11374 +78
==========================================
+ Hits 10295 10363 +68
- Misses 744 752 +8
- Partials 257 259 +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:
|
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
middleware/session/session.go (1)
437-470: Fix defer statement placement inside loop.The
delSessionmethod correctly handles multiple extractors, but there's an issue with the defer statement placement.Move the defer statement outside the loop to avoid potential resource leaks:
func (s *Session) delSession() { if s.ctx == nil { return } // Get all relevant extractors extractors := s.getExtractorInfo() // Delete session ID for each extractor type for _, ext := range extractors { switch ext.Source { case SourceHeader: s.ctx.Request().Header.Del(ext.Key) s.ctx.Response().Header.Del(ext.Key) case SourceCookie: s.ctx.Request().Header.DelCookie(ext.Key) s.ctx.Response().Header.DelCookie(ext.Key) fcookie := fasthttp.AcquireCookie() - defer fasthttp.ReleaseCookie(fcookie) fcookie.SetKey(ext.Key) fcookie.SetPath(s.config.CookiePath) fcookie.SetDomain(s.config.CookieDomain) fcookie.SetMaxAge(-1) fcookie.SetExpire(time.Now().Add(-1 * time.Minute)) s.setCookieAttributes(fcookie) s.ctx.Response().Header.SetCookie(fcookie) + fasthttp.ReleaseCookie(fcookie) case SourceOther: // No action required for SourceOther } } }The current code defers the cookie release inside the loop, which could accumulate deferred calls if multiple cookie extractors exist in the chain.
♻️ Duplicate comments (1)
docs/middleware/session.md (1)
32-48: Stale visit counter & unsafe type assertionThe example still shows the original pitfalls:
visitsis displayed before incrementing, so the first request prints0.visits.(int)will panic if the stored value isn’t anint.This mirrors a previously-raised comment. Consider the safer pattern already suggested earlier.
🧹 Nitpick comments (2)
middleware/session/session.go (1)
371-399: Good implementation with minor style improvement needed.The
getExtractorInfomethod correctly handles extractor chain traversal and filtering. It provides a safe default and properly filters for cookie/header extractors.Apply this style improvement as suggested by static analysis:
- } else { - // Single extractor - only include if it's cookie or header - if extractor.Source == SourceCookie || extractor.Source == SourceHeader { + } else if extractor.Source == SourceCookie || extractor.Source == SourceHeader { + // Single extractor - only include if it's cookie or header relevantExtractors = append(relevantExtractors, extractor) } - }docs/middleware/session.md (1)
528-538: Fix markdownlint violations (blank lines & trailing spaces)CI is failing on MD031/MD032/MD009. Insert blank lines before/after fenced blocks and lists, and remove trailing spaces.
-1. **Function Signature**: `session.New()` now returns middleware handler, not store + +1. **Function Signature**: `session.New()` now returns middleware handler, not storeApply similar changes throughout the file to unblock the pipeline.
Also applies to: 545-562
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
docs/middleware/session.md(1 hunks)middleware/session/config.go(4 hunks)middleware/session/config_test.go(2 hunks)middleware/session/extractors.go(1 hunks)middleware/session/extractors_test.go(1 hunks)middleware/session/middleware_test.go(4 hunks)middleware/session/session.go(2 hunks)middleware/session/session_test.go(33 hunks)middleware/session/store.go(2 hunks)middleware/session/store_test.go(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- middleware/session/middleware_test.go
- middleware/session/store_test.go
- middleware/session/store.go
- middleware/session/extractors_test.go
🧰 Additional context used
📓 Path-based instructions (1)
docs/**
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Review and update the contents of the
docsfolder if necessary when modifying code
Files:
docs/middleware/session.md
🧠 Learnings (7)
📓 Common learnings
Learnt from: sixcolors
PR: gofiber/fiber#3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware `Config` struct, the `Extractor` field uses function closures (like `FromCookie(key)`), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
middleware/session/config_test.go (15)
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: efectn
PR: #3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the require methods from the testify package for assertions instead of manual comparisons and calls to t.Fatal or t.Fatalf.
Learnt from: gaby
PR: #3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in ctx_test.go, it is acceptable to use invalid CIDR notation such as "0.0.0.1/31junk" for testing purposes.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
middleware/session/extractors.go (12)
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
middleware/session/session_test.go (26)
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: efectn
PR: #3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the Test_App_ShutdownWithContext function in app_test.go, the clientDone channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional time.Sleep calls.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
middleware/session/session.go (12)
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
docs/middleware/session.md (28)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-02T23:02:12.306Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
Learnt from: mdelapenya
PR: #3434
File: docs/api/services.md:39-43
Timestamp: 2025-05-07T13:07:33.899Z
Learning: When documenting Go interface methods in the Fiber project, avoid showing method signatures with the interface type as the receiver (e.g., func (d *Service) Method()) since interfaces cannot be used as receivers in Go. Instead, show just the method signature without a receiver or use a placeholder implementation name.
middleware/session/config.go (31)
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.382Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the middleware/adaptor/adaptor.go file of the Fiber framework, when updating context handling, replacing c.Context() with c.RequestCtx() is appropriate to access the fasthttp.RequestCtx.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Fiber currently supports square bracket notation in form data with 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. The implementation for form-urlencoded is in ctx.go (BodyParser method), while multipart form data handling needs enhancement to support this feature.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the Test method in app.go.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: mdelapenya
PR: #3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: #3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sigmundxia
PR: #3151
File: middleware/adaptor/adaptor_test.go:226-230
Timestamp: 2024-09-26T03:08:50.917Z
Learning: In Fiber, the c.Set method does not return an error.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: The session middleware's Destroy() method signature is func (m *Middleware) Destroy() error and takes no arguments. It is called on the session middleware instance, not on a session store, and does not require a fiber.Ctx parameter.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-09-25T17:05:06.991Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session IdleTimeout expiration, it's acceptable to use time.Sleep to simulate the passage of time in tests.
🧬 Code Graph Analysis (3)
middleware/session/config_test.go (2)
middleware/session/extractors.go (2)
Extractor(17-22)FromHeader(79-91)middleware/session/config.go (1)
Config(12-89)
middleware/session/extractors.go (2)
ctx_interface_gen.go (1)
Ctx(17-395)ctx.go (1)
Params(1239-1245)
middleware/session/session.go (1)
middleware/session/extractors.go (6)
Extractor(17-22)Source(9-9)SourceCookie(12-12)Chain(111-152)SourceHeader(13-13)SourceOther(14-14)
🪛 GitHub Check: lint
middleware/session/session.go
[failure] 387-387:
elseif: can replace 'else {if cond {}}' with 'else if cond {}' (gocritic)
[failure] 456-456:
defer: prefer not to defer inside loops (revive)
middleware/session/config.go
[failure] 13-13:
File is not properly formatted (gofumpt)
🪛 LanguageTool
docs/middleware/session.md
[style] ~336-~336: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...nly cookie is set in the response - Only Header extractors: Only header is set...
(ADVERB_REPETITION_PREMIUM)
[style] ~337-~337: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ... Only header is set in the response - Only Query/Form/Param extractors: No respo...
(ADVERB_REPETITION_PREMIUM)
🪛 GitHub Check: markdownlint
docs/middleware/session.md
[failure] 562-562: Fenced code blocks should be surrounded by blank lines
docs/middleware/session.md:562 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
[failure] 545-545: Fenced code blocks should be surrounded by blank lines
docs/middleware/session.md:545 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
[failure] 538-538: Trailing spaces
docs/middleware/session.md:538:78 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md009.md
[failure] 528-528: Lists should be surrounded by blank lines
docs/middleware/session.md:528 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Custom types must be registe..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md
[failure] 335-335: Trailing spaces
docs/middleware/session.md:335:65 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md009.md
[failure] 285-285: Lists should be surrounded by blank lines
docs/middleware/session.md:285 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- IdleTimeout: Storage autom..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md
[failure] 235-235: Fenced code blocks should be surrounded by blank lines
docs/middleware/session.md:235 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
[failure] 224-224: Fenced code blocks should be surrounded by blank lines
docs/middleware/session.md:224 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
[failure] 136-136: Lists should be surrounded by blank lines
docs/middleware/session.md:136 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Must call sess.Release() w..."] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md
[failure] 99-99: Lists should be surrounded by blank lines
docs/middleware/session.md:99 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Automatic session saving"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md032.md
🪛 GitHub Actions: markdownlint
docs/middleware/session.md
[error] 99-99: markdownlint MD032/blanks-around-lists: Lists should be surrounded by blank lines [Context: "- Automatic session saving"]
🪛 GitHub Actions: golangci-lint
middleware/session/config.go
[error] 13-13: gofumpt formatting error: File is not properly formatted.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: unit (1.24.x, macos-13)
- GitHub Check: unit (1.24.x, macos-latest)
- GitHub Check: unit (1.24.x, windows-latest)
- GitHub Check: repeated
- GitHub Check: Analyse
- GitHub Check: Compare
🔇 Additional comments (14)
middleware/session/config_test.go (3)
17-19: LGTM! Test correctly validates the new Extractor configuration.The test properly verifies that the default configuration includes a non-nil Extractor with the expected key "session_id", aligning with the new extractor-based architecture.
26-26: LGTM! Test demonstrates proper custom extractor configuration.The test correctly shows how to configure a custom header-based extractor and validates that it properly overrides the default cookie-based extractor.
Also applies to: 32-33
48-55: LGTM! New test properly validates timeout configuration constraints.The test correctly verifies that configDefault panics when AbsoluteTimeout is set less than IdleTimeout, ensuring the session timeout configuration remains consistent and logical.
middleware/session/session_test.go (3)
42-42: LGTM! Consistent updates from dynamic sessionName to hardcoded "session_id".All cookie and header operations have been consistently updated to use the hardcoded "session_id" string, aligning with the new extractor-based architecture where the session key is defined within the extractor configuration rather than as a separate field.
Also applies to: 110-110, 132-132, 201-201, 311-311, 322-322, 482-482, 491-491, 730-730, 745-745, 794-794, 808-808, 890-890, 1095-1095, 1105-1105, 1150-1150, 1222-1222
536-536: LGTM! Proper migration from KeyLookup to Extractor pattern.The tests correctly use
FromHeader("session_id")to configure header-based session extraction, and the response assertions have been appropriately simplified to focus on the actual response behavior.Also applies to: 553-554, 867-867, 897-897
558-692: Excellent comprehensive test coverage for chained extractors!This test thoroughly validates the new extractor chaining functionality with well-structured sub-tests covering:
- Both cookie and header extractors working together
- Order independence of chained extractors
- Proper handling of SourceOther extractors (no response modification)
- Mixed chains correctly setting only cookie/header responses
The test design effectively verifies that the session middleware correctly handles multiple extraction sources.
middleware/session/session.go (1)
401-435: LGTM! Proper implementation of multi-extractor session setting.The refactored
setSessionmethod correctly iterates over all relevant extractors and sets the session ID appropriately for each type:
- Headers are set directly
- Cookies include all necessary attributes (path, domain, expiration, security settings)
- SourceOther extractors are properly ignored
The implementation maintains backward compatibility while supporting the new chained extractor pattern.
middleware/session/config.go (3)
53-56: LGTM! Well-structured migration to Extractor pattern.The new
Extractorfield is properly documented and the default configuration correctly provides a cookie-based extractor with sensible defaults includingCookieSameSite: "Lax"for security.Also applies to: 93-96
109-112: LGTM! Improved error handling with better logging.The enhanced
DefaultErrorHandlernow provides detailed error logging and handles potential failures when sending the error response, improving debuggability.
145-147: LGTM! Proper validation ensures configuration consistency.The validation logic correctly:
- Ensures
AbsoluteTimeoutis not less thanIdleTimeout(fail-fast with panic)- Provides a default
Extractorwhen none is configuredAlso applies to: 150-152
middleware/session/extractors.go (3)
9-31: LGTM! Well-designed extractor types and error constants.The
Sourceenum andExtractorstruct provide a clean abstraction for session ID extraction. The specific error constants for each source type will help with debugging extraction failures.
33-106: LGTM! Consistent and well-implemented extractors.All five extractors follow a clean, consistent pattern:
- Proper error handling with specific error types
- Correct source categorization (Cookie/Header vs Other)
- Clear and concise implementations
108-152: LGTM! Robust Chain implementation with proper error handling.The
Chainfunction implementation is excellent:
- Gracefully handles empty extractor list
- Short-circuits on first successful extraction
- Properly tracks and returns the last error encountered
- Preserves primary extractor metadata for response handling
- Stores the full chain for potential debugging/inspection
docs/middleware/session.md (1)
332-338: Clarify cookie behaviour – Set-Cookie is always sentThe implementation currently always sends a
Set-Cookieheader, even when only header/query extractors are used. The bullet list implies selective behaviour, which can mislead API consumers. Please adjust the wording or update the code to match.
…and custom parameters
|
/gemini review |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a flexible Extractor pattern for session ID retrieval, replacing the previous string-based KeyLookup configuration. The change enhances the session middleware to support extraction from multiple sources (cookies, headers, queries, forms) using type-safe function patterns, while adding session lifecycle improvements and comprehensive error handling.
Key Changes
- Extractor Pattern: Replaces string-based
KeyLookupwith type-safeExtractorfunctions that support cookies, headers, queries, forms, and chained extraction - Session Lifecycle: Adds
Regenerate()method for secure session ID changes while preserving data, plus improved response handling for different extractor types - Enhanced Testing: Comprehensive test coverage for new extractor patterns, chained extractors, and session lifecycle methods
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
middleware/session/extractors.go |
New extractor implementation with built-in extractors and chaining support |
middleware/session/extractors_test.go |
Comprehensive test suite for all extractor types and chain functionality |
middleware/session/config.go |
Replaces KeyLookup parsing with Extractor configuration and validation |
middleware/session/store.go |
Simplifies session ID retrieval using new extractor pattern |
middleware/session/session.go |
Enhanced session management with improved setSession/delSession for multiple extractors |
middleware/session/middleware.go |
Adds Regenerate method to middleware interface |
middleware/session/session_test.go |
Updates tests to use new extractor pattern and adds chain extractor tests |
middleware/session/store_test.go |
Updates store tests to use new extractor configuration |
middleware/session/config_test.go |
Updates config tests for new extractor-based validation |
middleware/session/middleware_test.go |
Adds tests for new Regenerate functionality |
middleware/csrf/csrf_test.go |
Updates CSRF tests to use new extractor pattern |
docs/middleware/session.md |
Comprehensive documentation update with security guidance and examples |
docs/whats_new.md |
Documents the new extractor pattern changes |
Comments suppressed due to low confidence (3)
middleware/session/extractors.go:79
- [nitpick] The parameter name 'param' is ambiguous for a header name. Consider renaming it to 'headerName' or 'name' for better clarity.
func FromHeader(param string) Extractor {
middleware/session/extractors.go:94
- [nitpick] The parameter name 'param' is ambiguous for a query parameter name. Consider renaming it to 'queryParam' or 'name' for better clarity.
func FromQuery(param string) Extractor {
middleware/session/extractors.go:64
- [nitpick] The parameter name 'param' is ambiguous for a form field name. Consider renaming it to 'fieldName' or 'name' for better clarity.
func FromForm(param string) Extractor {
There was a problem hiding this comment.
Code Review
This is an excellent enhancement to the session middleware, replacing the string-based KeyLookup with a more flexible and type-safe Extractor pattern. The changes are well-implemented, thoroughly documented, and include comprehensive tests. My feedback focuses on making the documentation examples safer and more complete for end-users.
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
docs/whats_new.md (1)
1311-1327: Fix duplicate heading issue while maintaining accurate content.The session documentation accurately describes the key changes in v3, particularly the shift to the Extractor pattern and session lifecycle improvements. However, static analysis indicates a duplicate "Session" heading.
Consider renaming one of the Session headings to be more specific, such as:
-### Session +### Session Middleware ImprovementsThis would resolve the duplicate heading issue while maintaining the informative content about the extractor pattern and other key changes.
♻️ Duplicate comments (5)
middleware/session/extractors.go (1)
52-73: Comprehensive documentation and proper implementation.The function now includes excellent documentation that addresses the previous review feedback. The implementation correctly handles cookie extraction and error cases.
docs/middleware/session.md (4)
36-47: Unsafe type assertion & stale value – reuse earlier fix
visits.(int)will panic if the stored value is not anint, and thevisitscount shown to the user is the old value. The safer, idiomatic snippet you were given in the previous review is still applicable.
65-71:CookieSameSitemust be lowercaselaxThe v3 constants – and the examples elsewhere in the repo – use
"lax","strict"or"none". Keeping the capital"Lax"value will mislead readers.
258-266: Boolean check can panic – reuse earlier safe-cast snippetDirectly comparing
sess.Get("authenticated")totruecan panic if the stored value is not abool. The guarded type-assertion shown in the previous review should be applied here as well.
377-391: Custom extractor example does not match the public API
session.Extractoris now a function type, not a struct withExtract,Source, andKeyfields. This snippet will not compile.-func FromAuthorization() session.Extractor { - return session.Extractor{ - Extract: func(c fiber.Ctx) (string, error) { … }, - Source: session.SourceHeader, - Key: "Authorization", - } -} +func FromAuthorization() session.Extractor { + return func(c fiber.Ctx) (string, error) { + auth := c.Get("Authorization") + if strings.HasPrefix(auth, "Bearer ") { + id := strings.TrimPrefix(auth, "Bearer ") + if id != "" { + return id, nil + } + } + return "", session.ErrMissingSessionIDInHeader + } +}
🧹 Nitpick comments (1)
docs/middleware/session.md (1)
339-343: Minor wording nit – repeated adverb“Only header extractors: Only header is set …” – the second “Only” is redundant. Same issue in the next bullet.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/middleware/session.md(1 hunks)docs/whats_new.md(1 hunks)middleware/session/extractors.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/**
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Review and update the contents of the
docsfolder if necessary when modifying code
Files:
docs/middleware/session.mddocs/whats_new.md
🧠 Learnings (4)
📓 Common learnings
Learnt from: sixcolors
PR: gofiber/fiber#3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.403Z
Learning: In the session middleware `Config` struct, the `Extractor` field uses function closures (like `FromCookie(key)`), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: ReneWerner87
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2024-12-01T10:28:36.011Z
Learning: Feature request #3224 has been created to add support for square bracket notation and comma-separated values in multipart form data in Fiber, while maintaining binary data transfer capabilities. This would bring parity with the existing form-urlencoded functionality.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware `Config` struct, `Store` is backed by `fiber.Storage`; they are different entities serving distinct purposes in session management.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ksw2000
PR: gofiber/fiber#0
File: :0-0
Timestamp: 2025-07-08T13:41:20.627Z
Learning: ksw2000 suggests implementing a pluggable encoder/decoder registry system in Fiber instead of hardcoding all encoders in app.config. This would solve dependency management issues by allowing users to opt-in only to the formats they need, keeping JSON and XML as defaults while making CBOR and MsgPack explicit registrations.
middleware/session/extractors.go (11)
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.403Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The encryptcookie_test.go file contains unit tests that validate key lengths for both EncryptCookie and DecryptCookie functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
docs/middleware/session.md (31)
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.403Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using ctx.Response.Header.Cookie may not be suitable for parsing cookies from the response header, as it requires a *Cookie and fills it rather than returning a string value; thus, manual parsing of the Set-Cookie header may be necessary.
Learnt from: sixcolors
PR: #3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:272-293
Timestamp: 2024-10-02T15:16:39.868Z
Learning: In the middleware/session/session.go file, the saveSession() method returns either nil or an error, so additional error wrapping in the Save() method is unnecessary.
Learnt from: sixcolors
PR: #3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the Test_Session_Next function in middleware/session/middleware_test.go, the variable doNext is properly synchronized with the muNext mutex for both read and write access.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/session.go:46-61
Timestamp: 2024-10-02T23:02:12.306Z
Learning: In this codebase, the sessionPool only contains Session instances, so type assertions without additional checks are acceptable.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:122-122
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In DefaultErrorHandler(c *fiber.Ctx, err error), since c is a pointer to an interface, we need to dereference *c when calling interface methods like SendStatus.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for Session.Save already exist in the middleware/session/session_test.go file, specifically in the Test_Session_Save and Test_Session_Save_Expiration functions.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: sixcolors
PR: #3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: The session.Save() method in the middleware/session package returns the Session back to sync.Pool.
Learnt from: gaby
PR: #3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, Context() is being renamed to RequestCtx(), and UserContext() to Context() to improve clarity and align with Go's context conventions.
Learnt from: mdelapenya
PR: #3434
File: docs/api/services.md:39-43
Timestamp: 2025-05-07T13:07:33.899Z
Learning: When documenting Go interface methods in the Fiber project, avoid showing method signatures with the interface type as the receiver (e.g., func (d *Service) Method()) since interfaces cannot be used as receivers in Go. Instead, show just the method signature without a receiver or use a placeholder implementation name.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: #3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both EncryptCookie and DecryptCookie functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: efectn
PR: #3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the require methods from the testify package for assertions instead of manual comparisons and calls to t.Fatal or t.Fatalf.
docs/whats_new.md (13)
Learnt from: ckoch786
PR: #3230
File: docs/whats_new.md:944-951
Timestamp: 2024-12-15T19:56:45.935Z
Learning: Detailed usage examples and explanations for new methods like RemoveRoute and RemoveRouteByName are documented in docs/api/app.md, so it's unnecessary to duplicate them in docs/whats_new.md.
Learnt from: sixcolors
PR: #3625
File: middleware/session/config.go:57-58
Timestamp: 2025-07-27T17:28:53.403Z
Learning: In the session middleware Config struct, the Extractor field uses function closures (like FromCookie(key)), making it impossible to introspect extractor parameters at runtime for validation purposes without complex reflection techniques.
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-06-15T19:26:06.401Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: hcancelik
PR: #3036
File: docs/middleware/cache.md:103-103
Timestamp: 2024-10-08T19:06:06.583Z
Learning: There are no hard tabs in the lines 100 to 105 of the docs/middleware/cache.md file. Future comments about formatting should accurately reflect the actual content.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the Test_CSRF_WithSession_Middleware function, calling session.NewWithStore() without arguments is acceptable, as the default configuration is sufficient.
Learnt from: ReneWerner87
PR: #3598
File: docs/middleware/csrf.md:364-366
Timestamp: 2025-07-19T18:04:19.891Z
Learning: Both *Session and *Middleware in the session package have Destroy() methods with the signature func Destroy() error that take no arguments. The method is called directly on the session middleware instance without any parameters.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-09-25T16:17:00.969Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:16-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware Config struct, Store is backed by fiber.Storage; they are different entities serving distinct purposes in session management.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/session/config.go:26-26
Timestamp: 2024-09-25T16:18:46.641Z
Learning: In the session middleware, the newStore, New, and NewWithStore functions ensure that a Store is present even if it is not initialized in ConfigDefault.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
Learnt from: sixcolors
PR: #3016
File: middleware/csrf/session_manager.go:30-43
Timestamp: 2024-09-25T16:15:39.392Z
Learning: In the session middleware, session.FromContext(c) returns *session.Middleware, whereas m.session.Get(c) returns *session.Store, so they are not directly interchangeable.
🧬 Code Graph Analysis (1)
middleware/session/extractors.go (1)
ctx_interface_gen.go (1)
Ctx(17-395)
🪛 LanguageTool
docs/middleware/session.md
[style] ~341-~341: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ... Only cookie is set in the response - Only Header extractors: Only header is set...
(ADVERB_REPETITION_PREMIUM)
[style] ~342-~342: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ... Only header is set in the response - Only Query/Form/Param extractors: No respo...
(ADVERB_REPETITION_PREMIUM)
🪛 markdownlint-cli2 (0.17.2)
docs/whats_new.md
1311-1311: Multiple headings with the same content
(MD024, no-duplicate-heading)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Compare
- GitHub Check: lint
- GitHub Check: unit (1.24.x, macos-13)
- GitHub Check: unit (1.24.x, windows-latest)
- GitHub Check: repeated
🔇 Additional comments (6)
middleware/session/extractors.go (5)
1-7: LGTM!Package declaration and imports are clean and appropriate for the extractor functionality.
9-34: Excellent documentation and design for the Source enum.The comprehensive documentation clearly explains the behavioral differences between source types, particularly how they affect response handling. This will help developers make informed choices about which extractor to use.
36-50: Well-designed Extractor struct and comprehensive error definitions.The struct design provides good flexibility through the Extract function field while maintaining necessary metadata (Key, Chain, Source). The specific error types will aid in debugging by clearly indicating the source of extraction failures.
171-224: Excellent implementation of the Chain function.The function demonstrates solid error handling logic:
- Proper handling of edge cases (empty extractors)
- Correct early return on first success
- Appropriate error propagation (returns last actual error or generic error)
- Smart use of primary extractor's metadata for response handling
The logic correctly distinguishes between actual errors and empty results, which is important for the fallback behavior.
147-169: Approve genericfiber.Queryusage for FromQuery.The
FromQueryextractor correctly usesfiber.Query[string](c, param), which aligns with other extractors and middleware (e.g., inmiddleware/keyauth/keyauth.go,middleware/csrf/extractors.go, andmiddleware/logger/tags.go). No changes are needed.docs/middleware/session.md (1)
317-322: Verify response behaviour claimThe documentation states that a header-only extractor results in no
Set-Cookieheader. Earlier discussions indicated the middleware always sets a cookie. Please confirm actual behaviour and update the notes/table accordingly.
Implement a flexible Extractor function pattern for session ID retrieval, replacing the previous string-based KeyLookup. Enhance session middleware to support extraction from cookies, headers, queries, and forms. Add a Regenerate method to maintain session data while changing session IDs and improve session lifecycle management by requiring manual session release. Update tests and introduce error handling for missing session IDs in various contexts.