-
Notifications
You must be signed in to change notification settings - Fork 902
[PM-27119] Filtering card types if user has an ITEM_RESTRICTED org policy on CXP import #6104
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
[PM-27119] Filtering card types if user has an ITEM_RESTRICTED org policy on CXP import #6104
Conversation
|
Great job! No new security vulnerabilities introduced in this pull request |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6104 +/- ##
==========================================
- Coverage 84.82% 84.82% -0.01%
==========================================
Files 721 721
Lines 52824 52842 +18
Branches 7667 7672 +5
==========================================
+ Hits 44808 44822 +14
Misses 5328 5328
- Partials 2688 2692 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Claude finished @aj-rosado's task —— View job Code Review CompleteSummary of ChangesThis PR implements filtering of card-type items during CXP (Credential Exchange Protocol) import when users have active
Critical Issues1. Incorrect Policy Type CheckSeverity: The implementation checks for Location: val shouldFilterCreditCards = policyManager
.getActivePolicies(type = PolicyTypeJson.RESTRICT_ITEM_TYPES)
.any { it.isEnabled }Question: Is 2. Unsafe Type Casting and Silent FailuresSeverity: The Location: private fun isCardType(item: Any): Boolean {
val jsonObject = item as? JsonObject ?: return false
val credentials = jsonObject.get("credentials") as? JsonArray ?: return false
val firstCredential = credentials.firstOrNull() as? JsonObject ?: return false
val type = firstCredential.get("type")?.jsonPrimitive?.content
return type == "credit-card"
}Issues:
Recommendation: Add logging or explicit error handling for unexpected structures. Consider checking all credentials, not just the first one. 3. Magic String "credit-card"Severity: 📝 Low - Code Quality The credential type Location: return type == "credit-card"Recommendation: Define as a constant or reference existing constants from the CXF model if they exist. Suggested Improvements4. Missing KDoc DocumentationSeverity: 📝 Medium - Style Violation Per the project's Location: Recommendation: Add KDoc to explain:
Example: /**
* Filters out card-type items from accounts when the user has active RESTRICT_ITEM_TYPES policies.
*
* @param accounts The list of accounts to filter
* @return A new list of accounts with card items removed if policy is active, otherwise the original list
*/
private fun filterRestrictedItems(...)5. Incomplete Test CoverageSeverity: 💭 Medium - Test Gap The test
Location: Recommendation: Add edge case tests to ensure robustness. 6. Potential Performance ConsiderationSeverity: 💭 Low - Optimization The filtering logic iterates through all accounts and all items even when policy is inactive. The early return happens after the policy check, which is good, but the Location: val accountsJson = try {
json.encodeToString(
value = filterRestrictedItems(
accounts = exportResponse.accounts,
)
.firstOrNull(),
)Consideration: This is likely negligible for typical account sizes, but worth noting that filtering happens even for 7. Naming InconsistencySeverity: 🎨 Low - Code Style The variable Location: Recommendation: Consider Good Practices Observed✓ Proper DI Integration: PolicyManager correctly injected via Hilt Action Items for Author
Code Coverage DetailsPer Codecov report:
The test coverage could be improved by adding the edge case tests mentioned above. Overall Assessment: The implementation follows the project's architecture patterns and integrates well with existing code. However, there are concerns about the robustness of the type-checking logic and potential security implications of silent failures. The main blocker is confirming the correct policy type being used. |

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-27119
📔 Objective
If the user has active ITEM_RESTRICTION policies. They should not be able to import card types.
This aims to filter the card types out of the import.
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:) or similar for great changes:memo:) or ℹ️ (:information_source:) for notes or general info:question:) for questions:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:) for suggestions / improvements:x:) or:warning:) for more significant problems or concerns needing attention:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt:pick:) for minor or nitpick changes