Skip to content
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-18085] Add Manage property to UserCipherDetails #5390

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented Feb 11, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-18085

📔 Objective

CipherDetails should include a Manage property, indicating whether or not the user has Can Manage permissions over at least 1 collection the cipher is in. This should be correctly set from the Dapper and EF repository methods.

Changes Made

  1. Added Manage property to UserCipherDetails SQL function and EF query
  2. Added comprehensive integration tests to verify Manage property behavior across:
    • Organization ciphers in collections the user has access to
    • Organization ciphers in collections accessed through group membership
    • Personal ciphers (which always have Manage=true)
  3. Fixed EF query to correctly evaluate user permissions

Technical Details
The EF query required restructuring because it wasn't correctly evaluating permissions for ciphers that users had access to through both groups and collections. The original logic didn't match the SQL function's behavior for permission evaluation.

The solution was to:

  1. Align the EF LINQ query's permission logic with the SQL function
  2. Properly handle the COALESCE-like behavior for checking permissions through both CollectionUser and CollectionGroup
  3. Ensure consistent evaluation of the Manage permission across all access paths

Testing
Added integration tests that verify the Manage property is correctly set:

  • true for user-owned ciphers
  • true for organization ciphers in collections where the user has Manage permission
  • false for organization ciphers in collections where the user does not have Manage permission
  • true for organization ciphers in collections where the user's group has Manage permission
  • false for organization ciphers in collections where the user's group does not have Manage permission

Tests cover the CipherRepository query methods:

  • GetCipherPermissionsForOrganizationAsync
  • GetManyByUserIdAsync
  • GetByIdAsync

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 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

…bility

- Split large test method into smaller, focused methods
- Added helper methods for creating test data and performing assertions
- Improved test coverage for cipher permissions in different scenarios
- Maintained existing test logic while enhancing code structure
- Removed redundant helper methods for permission assertions
- Simplified test methods for GetCipherPermissionsForOrganizationAsync, GetManyByUserIdAsync, and GetByIdAsync
- Maintained existing test coverage for cipher manage permissions
- Improved code readability and reduced code duplication
…missions

- Added new test method GetCipherPermissionsForOrganizationAsync_ManageProperty_RespectsCollectionGroupRules
- Implemented helper method CreateCipherInOrganizationCollectionWithGroup to support group-based collection permission testing
- Verified manage permissions are correctly applied based on group collection access settings
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 47.39%. Comparing base (f6365fa) to head (1c37749).

Files with missing lines Patch % Lines
src/Core/Vault/Models/Data/CipherDetails.cs 50.00% 1 Missing ⚠️
...tyFramework/Vault/Repositories/CipherRepository.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5390      +/-   ##
==========================================
+ Coverage   44.47%   47.39%   +2.92%     
==========================================
  Files        1511     1511              
  Lines       70253    70295      +42     
  Branches     6338     6338              
==========================================
+ Hits        31242    33317    +2075     
+ Misses      37669    35587    -2082     
- Partials     1342     1391      +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Updated CipherDetails_Create, CipherDetails_CreateWithCollections, and CipherDetails_Update stored procedures
- Added @manage parameter with comment "-- not used"
- Included new stored procedure implementations in migration script
- Consistent with previous work on adding Manage property to cipher details
Copy link
Contributor

github-actions bot commented Feb 11, 2025

Logo
Checkmarx One – Scan Summary & Details0c89283e-8bf3-4cdf-b2fc-01e01c7cf66f

New Issues (135)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Api/Tools/Controllers/OrganizationExportController.cs: 53
detailsMethod Export at line 53 of /src/Api/Tools/Controllers/OrganizationExportController.cs gets a parameter from a user request from Export. This param...
Attack Vector
MEDIUM CSRF /src/Billing/Controllers/PayPalController.cs: 70
detailsMethod PostIpn at line 70 of /src/Billing/Controllers/PayPalController.cs gets a parameter from a user request from Body. This parameter value flow...
Attack Vector
MEDIUM CSRF /src/Api/Billing/Controllers/InvoicesController.cs: 16
detailsMethod PreviewInvoiceAsync at line 16 of /src/Api/Billing/Controllers/InvoicesController.cs gets a parameter from a user request from PreviewInvoic...
Attack Vector
MEDIUM CSRF /src/Api/Billing/Controllers/AccountsBillingController.cs: 83
detailsMethod PreviewInvoiceAsync at line 83 of /src/Api/Billing/Controllers/AccountsBillingController.cs gets a parameter from a user request from Previe...
Attack Vector
MEDIUM CSRF /src/Api/Controllers/LicensesController.cs: 44
detailsMethod GetUser at line 44 of /src/Api/Controllers/LicensesController.cs gets a parameter from a user request from GetUser. This parameter value flo...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
detailsMethod PutCollectionsAdmin at line 659 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parame...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
detailsMethod PutCollectionsAdmin at line 659 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This par...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
detailsMethod PutCollectionsAdmin at line 659 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This par...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
detailsMethod PutCollectionsAdmin at line 659 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parame...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
detailsMethod DeleteAttachment at line 1153 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This paramete...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
detailsMethod DeleteAttachment at line 1153 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from DeleteAttachment....
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
detailsMethod DeleteAttachment at line 1153 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This paramete...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 563
detailsMethod DeleteAccount at line 563 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from Dele...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 106
detailsMethod Get at line 106 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from Get. This para...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1076
detailsMethod PostAttachment at line 1076 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter ...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1050
detailsMethod PostFileForExistingAttachment at line 1050 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. ...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1099
detailsMethod PostAttachmentAdmin at line 1099 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This param...
Attack Vector
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationsController.cs: 52
detailsMethod GetSubscription at line 52 of /src/Api/Billing/Controllers/OrganizationsController.cs gets a parameter from a user request from GetSubscript...
Attack Vector
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationsController.cs: 110
detailsMethod PostPayment at line 110 of /src/Api/Billing/Controllers/OrganizationsController.cs gets a parameter from a user request from PostPayment. Th...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
detailsMethod PutCollections at line 609 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter v...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
detailsMethod PutCollections_vNext at line 630 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This pa...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
detailsMethod PutCollections at line 609 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This paramete...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
detailsMethod PutCollections_vNext at line 630 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This param...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 133
detailsMethod Put at line 133 of /src/Api/AdminConsole/Public/Controllers/GroupsController.cs gets a parameter from a user request from model. This parame...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/GroupsController.cs: 110
detailsMethod Post at line 110 of /src/Api/AdminConsole/Public/Controllers/GroupsController.cs gets a parameter from a user request from model. This param...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
detailsMethod PutCollections_vNext at line 630 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This param...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
detailsMethod PutCollections_vNext at line 630 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This pa...
Attack Vector
MEDIUM CSRF /src/Api/SecretsManager/Controllers/AccessPoliciesController.cs: 266
detailsMethod GetSecretAccessPoliciesAsync at line 266 of /src/Api/SecretsManager/Controllers/AccessPoliciesController.cs gets a parameter from a user req...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72
detailsMethod Setup at line 72 of /src/Api/AdminConsole/Controllers/ProvidersController.cs gets a parameter from a user request from Setup. This parameter...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
detailsMethod PutCollections at line 609 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter v...
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
detailsMethod PutCollections at line 609 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from model. This paramete...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 238
detailsMethod Invite at line 238 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from Invite. Thi...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 392
detailsMethod Put at line 392 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from model. This pa...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 392
detailsMethod Put at line 392 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from model. This pa...
Attack Vector
MEDIUM CSRF /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs: 51
detailsMethod PostLicenseAsync at line 51 of /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs gets a parameter from a user requ...
Attack Vector
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
detailsMethod Import at line 42 of /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs gets a parameter from a user request from Import. Th...
Attack Vector

More results are available on the CxOne platform

Fixed Issues (24)
Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 135
MEDIUM Privacy_Violation /src/Core/Auth/Services/Implementations/AuthRequestService.cs: 221
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164

@r-tome r-tome marked this pull request as ready for review February 12, 2025 15:27
@r-tome r-tome requested review from a team as code owners February 12, 2025 15:27
@r-tome r-tome requested review from nick-livefront, a team and JimmyVo16 February 12, 2025 15:27
Assert.True(personalDetails.Manage, "Personal ciphers should always have Manage permission");
}

private async Task<(User user, Organization org, OrganizationUser orgUser)> CreateTestUserAndOrganization(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work on making these helper methods to make the tests easier to read.

JimmyVo16
JimmyVo16 previously approved these changes Feb 13, 2025
@eliykat
Copy link
Member

eliykat commented Feb 17, 2025

@shane-melton do you mind taking a look at this, just given that we discussed it and it's probably one of the more complex changes we're making. Thanks.

shane-melton
shane-melton previously approved these changes Feb 19, 2025
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, thanks! Just saw one tiny, non-blocking nit in the updated sproc.

@r-tome r-tome dismissed stale reviews from shane-melton and JimmyVo16 via bfe9d6b February 19, 2025 11:29
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Personal ciphers always have Manage=true

  • For organizational ciphers, Manage permission is inherited from collection/group permissions

  • The Manage property is properly propagated through all query methods

LGTM

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.

5 participants