Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Jul 30, 2025

closes #11199

Summary by CodeRabbit

  • New Features

    • The application now sets the access token as a secure HTTP-only cookie during authentication and token refresh.
    • The access token cookie is explicitly removed upon user sign-out.
  • Bug Fixes

    • Improved handling of access token cookies to enhance security and reliability during authentication flows.

@ysmoradi ysmoradi requested a review from msynk July 30, 2025 12:37
@coderabbitai
Copy link

coderabbitai bot commented Jul 30, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes refactor how the access_token cookie is managed in the Bit Boilerplate project template. The logic for setting and removing the cookie on the client side is removed, and new logic is introduced on the server side to set the access_token as an HTTP-only cookie during authentication and to remove it during sign-out. A new property is added to facilitate setting the cookie from within the JWT data format class.

Changes

Cohort / File(s) Change Summary
Client Cookie Logic Removal
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AuthManager.cs
Removed all logic for setting and removing the access_token cookie on the client side. Only storage service and authentication state updates remain.
Server-Side Cookie Setting
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/Identity/AppJwtSecureDataFormat.cs
Added a public property to receive HttpContext, and updated the Protect method to set a secure, HTTP-only access_token cookie on the HTTP response if context is provided.
Controller Cookie Management
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/IdentityController.cs,
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/UserController.cs
In IdentityController, set the HttpContext on the JWT protector before issuing tokens. In UserController, explicitly delete the access_token cookie on sign-out.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant IdentityController
    participant AppJwtSecureDataFormat
    participant HttpResponse

    Client->>IdentityController: SignIn/Refresh
    IdentityController->>AppJwtSecureDataFormat: Protect(token, context)
    AppJwtSecureDataFormat->>HttpResponse: Set 'access_token' as HttpOnly cookie
    IdentityController-->>Client: Return response (cookie set)
Loading
sequenceDiagram
    participant Client
    participant UserController
    participant HttpResponse

    Client->>UserController: SignOut
    UserController->>HttpResponse: Delete 'access_token' cookie
    UserController-->>Client: Return sign-out response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure access_token cookie is set as HttpOnly cookie on the server side (#11199)
Remove client-side logic for setting/removing access_token cookie (#11199)
Properly remove access_token cookie on sign-out (#11199)

Poem

A token once lived on the client,
Now HttpOnly, secure, and compliant!
The server now guards with a cookie so neat,
No more peeking from JavaScript’s seat.
Sign-in and out, the flow is just right—
Rabbits hop safe, by day and by night!
🐇🍪✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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

@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

🧹 Nitpick comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/Identity/AppJwtSecureDataFormat.cs (1)

83-98: Excellent secure cookie implementation with comprehensive security attributes.

The implementation properly addresses the PR objectives by setting an HttpOnly cookie with all necessary security attributes:

  • HttpOnly=true prevents XSS attacks by blocking client-side access
  • Secure=true (except in development) ensures HTTPS-only transmission
  • SameSite=Strict provides CSRF protection
  • Proper expiration using the configured bearer token lifetime

The conditional check for HttpContextToSetAccessTokenCookie ensures the class remains functional when HttpContext isn't available.

Consider making the cookie name configurable through app settings for better maintainability:

-                "access_token",
+                appSettings.Identity.AccessTokenCookieName ?? "access_token",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0545bb8 and 5a6079f.

📒 Files selected for processing (4)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AuthManager.cs (0 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/IdentityController.cs (2 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/UserController.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/Identity/AppJwtSecureDataFormat.cs (2 hunks)
💤 Files with no reviewable changes (1)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AuthManager.cs
⏰ 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). (1)
  • GitHub Check: build and test
🔇 Additional comments (4)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/UserController.cs (1)

69-70: Excellent security enhancement for proper cookie cleanup.

The explicit deletion of the "access_token" cookie during sign-out ensures proper cleanup and prevents potential security vulnerabilities where the cookie might remain accessible after logout. This aligns perfectly with the PR objective to enhance security through server-side HttpOnly cookie management.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/IdentityController.cs (2)

102-104: Clean implementation enabling secure cookie functionality.

The approach to cast the BearerTokenProtector and set the HttpContext is well-documented and necessary to enable server-side HttpOnly cookie management. The comment clearly explains the design constraint that prevented constructor injection.


240-242: Consistent implementation across authentication operations.

The same pattern used in the SignIn method ensures consistent server-side cookie management for both initial authentication and token refresh operations. This maintains the security benefits throughout the authentication lifecycle.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/Identity/AppJwtSecureDataFormat.cs (1)

13-13: Well-designed property for HttpContext injection.

The nullable HttpContext property enables flexible cookie management - the class can function with or without cookie-setting behavior based on whether this property is set. This design maintains backward compatibility while adding the new secure cookie functionality.

@ysmoradi ysmoradi changed the title Use http only cookie in bit Boilerplate for access_token (#11199) Enable dependency injection in Boilerplate's AppJwtSecureDataFormat (#11199) Jul 30, 2025
@ysmoradi ysmoradi merged commit 0c8c9c4 into bitfoundation:develop Jul 30, 2025
3 checks passed
@ysmoradi ysmoradi deleted the 11199 branch July 30, 2025 18:25
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.

bit Boilerplate project template's AppJwtSecureDataFormat is not DI enabled

1 participant