-
Notifications
You must be signed in to change notification settings - Fork 28
Fix the WASA Issue : IDOR Vulnerability #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughVersion bumped to 3.6.1 in pom.xml. JWT-based authorization validation added to multiple controller methods via HttpServletRequest inspection and token parsing with JwtUtil and CookieUtil utilities. Each modified endpoint now verifies userId from JWT cookie matches the request userId before proceeding. New getUserIdFromToken public method exposed in JwtUtil for token claim extraction. Changes
Sequence DiagramsequenceDiagram
actor Client
participant Controller
participant JwtUtil
participant CookieUtil
participant Service
Client->>Controller: POST/GET request with userID
activate Controller
Controller->>CookieUtil: Extract JWT from cookies
activate CookieUtil
CookieUtil-->>Controller: JWT token
deactivate CookieUtil
Controller->>JwtUtil: getUserIdFromToken(token)
activate JwtUtil
JwtUtil->>JwtUtil: extractAllClaims(token)
JwtUtil-->>Controller: tokenUserId
deactivate JwtUtil
alt userId matches
Controller->>Service: Proceed with business logic
activate Service
Service-->>Controller: Response (200)
deactivate Service
else userId mismatch
Controller-->>Client: Unauthorized (5000)
end
deactivate Controller
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touchesβ Failed checks (1 warning)
β Passed checks (2 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
Tip π Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests β including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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. Comment |
|
@coderabbitai review |
β Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
π§Ή Nitpick comments (1)
src/main/java/com/iemr/mmu/controller/location/LocationController.java (1)
146-168: Consider simplifying the authorization check and logging unauthorized attempts
getLocDetailsBasedOnSpIDAndPsmIDNewcorrectly blocks requests when the JWTuserIdis null/missing/mismatched, but the nested structure makes it harder to follow, and unauthorized access is not logged.You can improve readability and observability by:
- Checking JWT vs request
userIdup front.- Logging unauthorized attempts.
- Only then validating
spID/spPSMID.For example:
- JSONObject obj = new JSONObject(comingRequest); - String jwtToken = CookieUtil.getJwtTokenFromCookie(request); - String userId = jwtUtil.getUserIdFromToken(jwtToken); - if(userId != null && obj.has("userId") && userId.equals(String.valueOf( obj.getInt("userId")))) { - if (obj != null && obj.has("spID") && obj.has("spPSMID") && obj.get("spID") != null - && obj.get("spPSMID") != null) { + JSONObject obj = new JSONObject(comingRequest); + String jwtToken = CookieUtil.getJwtTokenFromCookie(request); + String userId = jwtUtil.getUserIdFromToken(jwtToken); + + if (userId == null || !obj.has("userId") + || !userId.equals(String.valueOf(obj.getInt("userId")))) { + logger.warn("Unauthorized access in getLocDetailsBasedOnSpIDAndPsmIDNew for userId {}", userId); + response.setError(5000, "Unauthorized access"); + return response.toString(); + } + + if (obj.has("spID") && obj.has("spPSMID") && obj.get("spID") != null + && obj.get("spPSMID") != null) { @@ - } - } - else { - response.setError(5000, "Unauthorized access"); - }This keeps the IDOR protection semantics but makes the control flow more obvious and traceable.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (6)
pom.xml(1 hunks)src/main/java/com/iemr/mmu/controller/common/main/CommonController.java(5 hunks)src/main/java/com/iemr/mmu/controller/location/LocationController.java(4 hunks)src/main/java/com/iemr/mmu/controller/login/IemrMmuLoginController.java(4 hunks)src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java(3 hunks)src/main/java/com/iemr/mmu/utils/JwtUtil.java(1 hunks)
π Additional comments (7)
pom.xml (1)
8-8: Version bump aligns with target releaseArtifact version updated to 3.6.1; this is consistent with the
release-3.6.1target branch and has no technical issues from this fileβs perspective.src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java (1)
27-55: JwtUtil wiring in TeleConsultationController looks goodThe JwtUtil import and autowired field are straightforward and used only where needed; no issues here.
src/main/java/com/iemr/mmu/controller/location/LocationController.java (1)
28-56: JwtUtil and CookieUtil wiring for location endpoints looks fineThe added imports and autowired
JwtUtilfield are consistent with the new JWT-based authorization flow and donβt introduce functional issues by themselves.src/main/java/com/iemr/mmu/controller/login/IemrMmuLoginController.java (2)
36-43: JwtUtil and CookieUtil wiring in login controller is correctThe new imports and autowired
JwtUtilfield are consistent with the JWT-based validation pattern used elsewhere and look fine.Also applies to: 57-59
155-158: Minor catch-block tweak in getVanMaster is fineThe catch block still logs the exception and returns an error response; the additional blank line has no functional impact.
src/main/java/com/iemr/mmu/controller/common/main/CommonController.java (2)
43-43: LGTM: Imports support JWT-based authorization.The new imports for
JwtUtilandCookieUtilare necessary for implementing the IDOR vulnerability fix.Also applies to: 54-54
73-74: LGTM: JwtUtil properly autowired.The dependency injection follows the existing pattern in this controller.
src/main/java/com/iemr/mmu/controller/common/main/CommonController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/iemr/mmu/controller/common/main/CommonController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/iemr/mmu/controller/login/IemrMmuLoginController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java
Show resolved
Hide resolved
|
* fix: wasa-IDOR Vulnerability * fix: coderabbit comments * fix: remove userid from payload
* fix: wasa-IDOR Vulnerability * fix: coderabbit comments * fix: remove userid from payload
* fix: rebase to resolve the conflicts * fix: coderabbit comments * Fix the WASA Issue : IDOR Vulnerability (#137) * fix: wasa-IDOR Vulnerability * fix: coderabbit comments * fix: remove userid from payload * fix: resolve the conflicts * fix: remove unwanted codes




π Description
JIRA ID:
AMM-1922
Use the UserID from the JWT Token, instead of passing it from payload, to prevent this IDOR Vulnerability.
β Type of Change
Summary by CodeRabbit
Chores
New Features