-
Notifications
You must be signed in to change notification settings - Fork 43
[OB4] Removing session data key consent from the cache #915
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -256,6 +256,13 @@ public Response persist(@Context HttpServletRequest request, @Context HttpServle | |||||||
| throws ConsentException, ConsentManagementException, URISyntaxException { | ||||||||
|
|
||||||||
| ConsentData consentData = ConsentCache.getConsentDataFromCache(sessionDataKey); | ||||||||
|
|
||||||||
| /* | ||||||||
| Remove consent data from the cache to prevent multiple calls to the persist endpoint. | ||||||||
| This ensures the flow is completed and avoids further updates after a single persistence. | ||||||||
| */ | ||||||||
| ConsentCache.removeFromCache(sessionDataKey); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 2
Suggested change
Comment on lines
258
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if the base cache class has an atomic getAndRemove operation that could be used
ast-grep --pattern $'class FinancialServicesBaseCache {
$$$
}'
# Also check for any existing atomic cache operations in the codebase
rg -n "getAndRemove|removeAndGet|atomicRemove" --type javaRepository: wso2/financial-services-accelerator Length of output: 61 🏁 Script executed: # Find the ConsentCache class
fd -type f -name "*ConsentCache*" --type fRepository: wso2/financial-services-accelerator Length of output: 249 🏁 Script executed: # Search for ConsentCache class definition and methods
rg -n "class ConsentCache|public.*get.*Cache|public.*remove.*Cache" --type java -A 3Repository: wso2/financial-services-accelerator Length of output: 26398 🏁 Script executed: # Look at the complete flow in ConsentAuthorizeEndpoint to understand the race window
rg -n "getConsentDataFromCache|removeFromCache|persistConsent" --type java -B 2 -A 2Repository: wso2/financial-services-accelerator Length of output: 14580 🏁 Script executed: # Get the full implementation of FinancialServicesBaseCache to understand synchronization
cat financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/caching/FinancialServicesBaseCache.java | head -200Repository: wso2/financial-services-accelerator Length of output: 6279 🏁 Script executed: # Check if there's any synchronization in the ConsentCache specifically
rg -n "synchronized" financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.consent.mgt.endpoint/src/main/java/org/wso2/financial/services/accelerator/consent/mgt/endpoint/utils/ConsentCache.javaRepository: wso2/financial-services-accelerator Length of output: 129 🏁 Script executed: # Look at the complete ConsentAuthorizeEndpoint flow around the cache removal to understand persistence logic
sed -n '250,380p' financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.consent.mgt.endpoint/src/main/java/org/wso2/financial/services/accelerator/consent/mgt/endpoint/api/ConsentAuthorizeEndpoint.javaRepository: wso2/financial-services-accelerator Length of output: 7306 🏁 Script executed: # Check the git history to see if lines 273, 284, 289 were modified in this PR
git log -p --follow -S "consentData.getRedirectURI()" financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.consent.mgt.endpoint/src/main/java/org/wso2/financial/services/accelerator/consent/mgt/endpoint/api/ConsentAuthorizeEndpoint.java | head -100Repository: wso2/financial-services-accelerator Length of output: 61 🏁 Script executed: # Show the exact context around line 273 and 284 to understand the NPE issue
sed -n '268,295p' financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.consent.mgt.endpoint/src/main/java/org/wso2/financial/services/accelerator/consent/mgt/endpoint/api/ConsentAuthorizeEndpoint.javaRepository: wso2/financial-services-accelerator Length of output: 1655 Race condition window remains between retrieval and removal. The cache removal improves security but two concurrent requests can both retrieve valid If atomic operations aren't feasible, this fix still meaningfully narrows the attack window and is acceptable for merge. The database cleanup in the finally block (lines 367-380) provides an additional layer of protection. 🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| URI location; | ||||||||
| try { | ||||||||
| if (consentData == null) { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -223,4 +223,13 @@ public int setModifiedExpiryMinutes() { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| return FinancialServicesConfigParser.getInstance().getCommonCacheModifiedExpiryTime(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Remove from the consent cache | ||||||||||||||||||||||
| * @param cacheKey Cache key | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public static void removeFromCache(String cacheKey) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ConsentCache.getInstance().removeFromCache(ConsentCacheKey.of(cacheKey)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+230
to
+234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 3
Suggested change
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
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.
Log Improvement Suggestion No: 1