feat: generate a unique id for the cookie names based on the domain#161
feat: generate a unique id for the cookie names based on the domain#161steveiliop56 merged 2 commits intomainfrom
Conversation
WalkthroughThe changes introduce domain-specific cookie naming by generating unique cookie names for session, CSRF, and redirect cookies using a domain-derived identifier. Config structs are updated to support these dynamic names, and all cookie operations now reference the configurable names. A utility function for generating identifiers and a new dependency on Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Handlers
participant Auth
participant Utils
Note over Handlers,Auth: On initialization
Handlers->>Utils: GenerateIdentifier(domain)
Utils-->>Handlers: identifier
Handlers->>Handlers: Set CsrfCookieName, RedirectCookieName with identifier
Auth->>Utils: GenerateIdentifier(domain)
Utils-->>Auth: identifier
Auth->>Auth: Set SessionCookieName with identifier
Note over User,Handlers: During request handling
User->>Handlers: Request (sets/reads cookies)
Handlers->>Handlers: Use CsrfCookieName, RedirectCookieName from config
Handlers->>Auth: Authenticate (uses SessionCookieName from config)
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
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.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
internal/api/api_test.go (2)
179-182:⚠️ Potential issueUpdate cookie name in TestAppContext
The cookie name is still set to
"tinyauth"in this test, but according to the changes elsewhere in the file and the constants ininternal/constants/constants.go, it should be updated to"tinyauth-session"for consistency.// Set the cookie req.AddCookie(&http.Cookie{ - Name: "tinyauth", + Name: "tinyauth-session", Value: cookie, })
304-308:⚠️ Potential issueUpdate cookie name in TestLogout
The cookie name is still set to
"tinyauth"in this test, while it should be"tinyauth-session"to match the updated cookie name configuration.// Set the cookie req.AddCookie(&http.Cookie{ - Name: "tinyauth", + Name: "tinyauth-session", Value: cookie, })
🧹 Nitpick comments (1)
internal/api/api_test.go (1)
152-153: Verify the cookie name in TestLoginThis test sets the
cookievariable from the first cookie in the response but doesn't verify that the correct cookie name is being used. Consider adding an assertion to check that the cookie name matches the expected"tinyauth-session".// Get the cookie cookie = recorder.Result().Cookies()[0].Value + +// Check if the cookie name is correct +if recorder.Result().Cookies()[0].Name != "tinyauth-session" { + t.Fatalf("Expected cookie name 'tinyauth-session', got '%s'", recorder.Result().Cookies()[0].Name) +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/api/api_test.go(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/api/api_test.go (2)
internal/constants/constants.go (3)
CsrfCookieName(27-27)RedirectCookieName(28-28)SessionCookieName(26-26)internal/types/config.go (1)
AuthConfig(77-87)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (5)
internal/api/api_test.go (5)
37-39: Cookie names configuration looks goodThe addition of configurable cookie names aligns with the PR objective to support domain-specific cookie naming.
39-41: Verify UI settings relevance to this PRThe addition of
BackgroundImageandOAuthAutoRedirectfields seems unrelated to the cookie naming feature. Consider whether these should be part of a separate PR for better change tracking and review.
52-53: Domain configuration looks goodAdding the
SessionCookieNameandDomainfields to the auth configuration supports the PR objective of domain-specific cookie naming.
248-249: Cookie name update in TestUserContext looks goodThe cookie name has been properly updated from
"tinyauth"to"tinyauth-session"in this test.
217-220: AppContext test updatesThe test has been properly updated to include the new UI settings and domain in the expected results. Make sure these are intentional additions for this PR.
Summary by CodeRabbit
New Features
Chores