Skip to content

Conversation

srishtigrp78
Copy link
Contributor

@srishtigrp78 srishtigrp78 commented May 25, 2025

📋 Description

JIRA ID:
AMM-1507 | Force logout not restricting access in Supervisor module
Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the logout process to ensure that authentication cookies are properly invalidated, enhancing session security.

Copy link
Contributor

coderabbitai bot commented May 25, 2025

Walkthrough

The forceLogout endpoint in IEMRAdminController was updated to accept HTTP request and response objects. After performing the logout logic, it now invalidates any "Jwttoken" cookies by setting their value to null and expiring them, ensuring the JWT token is removed from the client.

Changes

File(s) Change Summary
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java Modified forceLogout method to accept HTTP request/response, added JWT cookie invalidation logic

Poem

A logout now with extra care,
The token cookie’s vanished air.
With headers passed and cookies gone,
The rabbit’s code hops safely on.
"Jwttoken" swept from every trace—
Security’s in place!
🥕✨

✨ 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
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cc609d and 3e8abbd.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1 hunks)
🧰 Additional context used
🪛 ast-grep (0.38.1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

[warning] 927-927: The application does not appear to verify inbound requests which can lead to a Cross-site request forgery (CSRF) vulnerability. If the application uses cookie-based authentication, an attacker can trick users into sending authenticated HTTP requests without their knowledge from any arbitrary domain they visit. To prevent this vulnerability start by identifying if the framework or library leveraged has built-in features or offers plugins for CSRF protection. CSRF tokens should be unique and securely random. The Synchronizer Token or Double Submit Cookie patterns with defense-in-depth mechanisms such as the sameSite cookie flag can help prevent CSRF. For more information, see: [Cross-site request forgery prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Req\ uest_Forgery_Prevention_Cheat_Sheet.html).
Context: response.addCookie(cookie);
Note: [CWE-352] Cross-Site Request Forgery (CSRF). [REFERENCES]
- https://stackoverflow.com/questions/42717210/samesite-cookie-in-java-application

(cookie-missing-samesite-java)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: style-check / checkstyle
  • GitHub Check: Build
  • GitHub Check: Package-test
  • GitHub Check: Analyze (java)
🔇 Additional comments (2)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (2)

896-910: LGTM! Well-structured logout implementation.

The method correctly:

  • Calls the service layer to perform logout logic first
  • Invalidates JWT cookies after successful logout
  • Handles exceptions properly with appropriate error responses
  • Maintains consistent response format

895-895:

✅ Verification successful

Verify API breaking change impact across the codebase.

The method signature change adds new parameters (HttpServletRequest httpRequest, HttpServletResponse response), which is a breaking change for any direct method invocations. However, since this is a REST endpoint, Spring will automatically inject these parameters, so HTTP clients should not be affected.

Please verify that no internal code directly calls this method:


🏁 Script executed:

#!/bin/bash
# Description: Search for direct method calls to forceLogout to ensure no breaking changes
# Expected: Only REST endpoint usage, no direct method calls

# Search for direct method invocations of forceLogout
ast-grep --pattern 'forceLogout($$$)'

# Search for any references to forceLogout method
rg -A 3 '\.forceLogout\(' --type java

Length of output: 558


Breaking change validated: controller method signature change is safe

A search for direct invocations of IEMRAdminController.forceLogout found only the service call (iemrAdminUserServiceImpl.forceLogout(request)) in the same class—no calls to the controller method itself. Since Spring injects HttpServletRequest and HttpServletResponse automatically, this signature change won’t break internal code or external HTTP clients.

Copy link
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

🧹 Nitpick comments (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)

912-936: Consider SameSite consistency with project CORS requirements.

The invalidateJwtCookie implementation is well-structured and addresses previous security concerns. However, there's a potential inconsistency with the project's CORS configuration.

Based on retrieved learnings, this project uses SameSite=None for cross-origin requests. Setting SameSite=Strict for invalidation might prevent proper logout in cross-origin scenarios.

Consider using SameSite=None to maintain consistency with the project's CORS requirements:

-                cookie.setAttribute("SameSite", "Strict");
+                cookie.setAttribute("SameSite", "None");

Alternatively, if Strict is intentionally used for enhanced security during logout, consider adding a comment explaining this design decision.

🧰 Tools
🪛 ast-grep (0.38.1)

[warning] 927-927: The application does not appear to verify inbound requests which can lead to a Cross-site request forgery (CSRF) vulnerability. If the application uses cookie-based authentication, an attacker can trick users into sending authenticated HTTP requests without their knowledge from any arbitrary domain they visit. To prevent this vulnerability start by identifying if the framework or library leveraged has built-in features or offers plugins for CSRF protection. CSRF tokens should be unique and securely random. The Synchronizer Token or Double Submit Cookie patterns with defense-in-depth mechanisms such as the sameSite cookie flag can help prevent CSRF. For more information, see: [Cross-site request forgery prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Req\ uest_Forgery_Prevention_Cheat_Sheet.html).
Context: response.addCookie(cookie);
Note: [CWE-352] Cross-Site Request Forgery (CSRF). [REFERENCES]
- https://stackoverflow.com/questions/42717210/samesite-cookie-in-java-application

(cookie-missing-samesite-java)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e8abbd and f67d796.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)
Learnt from: sandipkarmakar3
PR: PSMRI/Common-API#162
File: src/main/java/com/iemr/common/utils/CookieUtil.java:40-47
Timestamp: 2025-02-21T07:42:36.497Z
Learning: In the Common-API project's CookieUtil class, JWT cookies are configured with SameSite=None to support cross-origin requests, which is required for the project's CORS functionality.
🪛 ast-grep (0.38.1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

[warning] 927-927: The application does not appear to verify inbound requests which can lead to a Cross-site request forgery (CSRF) vulnerability. If the application uses cookie-based authentication, an attacker can trick users into sending authenticated HTTP requests without their knowledge from any arbitrary domain they visit. To prevent this vulnerability start by identifying if the framework or library leveraged has built-in features or offers plugins for CSRF protection. CSRF tokens should be unique and securely random. The Synchronizer Token or Double Submit Cookie patterns with defense-in-depth mechanisms such as the sameSite cookie flag can help prevent CSRF. For more information, see: [Cross-site request forgery prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Req\ uest_Forgery_Prevention_Cheat_Sheet.html).
Context: response.addCookie(cookie);
Note: [CWE-352] Cross-Site Request Forgery (CSRF). [REFERENCES]
- https://stackoverflow.com/questions/42717210/samesite-cookie-in-java-application

(cookie-missing-samesite-java)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
  • GitHub Check: Build
🔇 Additional comments (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)

895-910: LGTM! Method signature properly updated for cookie invalidation.

The forceLogout method has been correctly updated to accept HttpServletRequest and HttpServletResponse parameters, enabling proper JWT cookie invalidation. The implementation follows a clear sequence: perform logout logic, invalidate cookies, and return success response with appropriate error handling.

Copy link

@srishtigrp78 srishtigrp78 merged commit 13a7492 into PSMRI:develop May 25, 2025
7 checks passed
srishtigrp78 added a commit to srishtigrp78/Common-API that referenced this pull request May 26, 2025
Merge pull request PSMRI#205 from srishtigrp78/feature/version/upgrade
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.

2 participants