Skip to content

feat: generate a unique id for the cookie names based on the domain#161

Merged
steveiliop56 merged 2 commits intomainfrom
feat/cookie-uuid
May 25, 2025
Merged

feat: generate a unique id for the cookie names based on the domain#161
steveiliop56 merged 2 commits intomainfrom
feat/cookie-uuid

Conversation

@steveiliop56
Copy link
Copy Markdown
Member

@steveiliop56 steveiliop56 commented May 22, 2025

Summary by CodeRabbit

  • New Features

    • Cookie names for session, CSRF, and redirect actions are now unique per domain, reducing the risk of conflicts when using multiple domains.
    • Improved configuration options allow for dynamic naming of these cookies.
  • Chores

    • Added a new dependency for UUID generation to enhance cookie name uniqueness.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2025

Walkthrough

The 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 github.com/google/uuid are added.

Changes

File(s) Change Summary
cmd/root.go Implements logic to generate unique cookie names by appending a domain-derived identifier and assigns these names to config structs.
go.mod Adds github.com/google/uuid v1.6.0 as a new dependency.
internal/auth/auth.go Replaces hardcoded session cookie name with a configurable value from AuthConfig.SessionCookieName.
internal/constants/constants.go Adds constants for base cookie names: SessionCookieName, CsrfCookieName, and RedirectCookieName.
internal/handlers/handlers.go Replaces hardcoded CSRF and redirect cookie names with configurable values from HandlersConfig.
internal/types/config.go Adds CsrfCookieName and RedirectCookieName fields to HandlersConfig, and SessionCookieName to AuthConfig.
internal/utils/utils.go Adds GenerateIdentifier utility function to create a static identifier from a string using SHA-1 UUID.
internal/api/api_test.go Updates test configs and expectations to include new domain and cookie name fields, and adjusts session cookie name in tests.

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)
Loading

Poem

Hopping through code with cookies anew,
Each domain now gets a name just for you!
UUIDs swirl in a clever dance,
No more collisions—no random chance.
With configs set and rabbits proud,
Our cookies stand out in the crowd!
🐇🍪

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit 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.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit 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 Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
internal/api/api_test.go (2)

179-182: ⚠️ Potential issue

Update 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 in internal/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 issue

Update 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 TestLogin

This test sets the cookie variable 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7151832 and 07933ad.

📒 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 good

The addition of configurable cookie names aligns with the PR objective to support domain-specific cookie naming.


39-41: Verify UI settings relevance to this PR

The addition of BackgroundImage and OAuthAutoRedirect fields 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 good

Adding the SessionCookieName and Domain fields to the auth configuration supports the PR objective of domain-specific cookie naming.


248-249: Cookie name update in TestUserContext looks good

The cookie name has been properly updated from "tinyauth" to "tinyauth-session" in this test.


217-220: AppContext test updates

The 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.

@steveiliop56 steveiliop56 merged commit 3a7b71a into main May 25, 2025
6 checks passed
@Rycochet Rycochet deleted the feat/cookie-uuid branch April 1, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant