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-18087] Add cipher permissions to response models #5418

Draft
wants to merge 10 commits into
base: ac/pm-18086/add-authorization-methods
Choose a base branch
from

Conversation

r-tome
Copy link
Contributor

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

🎟️ Tracking

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

📔 Objective

  • Created new CipherPermissionsResponseModel to explicitly communicate cipher permissions
    • Added Delete and Restore boolean properties
    • Uses NormalCipherPermissions to calculate these values
  • Updated CipherResponseModel to include the new permissions property
  • Added OrganizationAbility parameter to relevant response model constructors to support permission calculations

Implementation Details

  • Modified API controllers to:
    • Retrieve OrganizationAbility for organizational ciphers
    • Pass organization abilities to response model constructors

📸 Screenshots

⏰ 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

This change introduces organization ability context to various cipher response models across multiple controllers. The modifications include:

- Updating CipherResponseModel to include permissions based on user and organization ability
- Modifying CiphersController methods to fetch and pass organization abilities
- Updating SyncController to include organization abilities in sync response
- Adding organization ability context to EmergencyAccessController response generation
This change simplifies the EmergencyAccessController by removing unnecessary organization ability fetching and passing. Since emergency access only retrieves personal ciphers, the organization ability context is no longer needed in the response generation.
Remove unnecessary JsonConstructor attribute and simplify constructor initialization for EmergencyAccessViewResponseModel
Copy link
Contributor

github-actions bot commented Feb 19, 2025

Logo
Checkmarx One – Scan Summary & Detailse40256a2-7aa9-4a96-a6d8-f4c745b6c1d1

New Issues (22)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/RecoveryController.cs: 38
detailsMethod ProcessEventsAsync at line 38 of /src/Billing/Controllers/RecoveryController.cs gets user input from element requestBody. This element’s val...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
LOW Log_Forging /src/Billing/Controllers/StripeController.cs: 164
detailsMethod TryParseEventFromRequestBodyAsync at line 164 of /src/Billing/Controllers/StripeController.cs gets user input from element Body. This elemen...
Attack Vector
Fixed Issues (228)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Billing/Controllers/StripeController.cs: 176
MEDIUM CSRF /src/Api/Tools/Controllers/OrganizationExportController.cs: 53
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 989
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 982
MEDIUM CSRF /src/Api/Auth/Controllers/TwoFactorController.cs: 108
MEDIUM CSRF /src/Api/Auth/Controllers/TwoFactorController.cs: 406
MEDIUM CSRF /src/Billing/Controllers/StripeController.cs: 164
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 764
MEDIUM CSRF /src/Billing/Controllers/RecoveryController.cs: 38
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 649
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 497
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 366
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 236
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 391
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 163
MEDIUM CSRF /src/Api/Controllers/SettingsController.cs: 36
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 545
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 513
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 493
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 320
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 261
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 937
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 914
MEDIUM CSRF /src/Api/Billing/Controllers/InvoicesController.cs: 16
MEDIUM CSRF /src/Api/Billing/Controllers/AccountsBillingController.cs: 83
MEDIUM CSRF /src/Api/Controllers/LicensesController.cs: 44
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 659
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1153
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 563
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 106
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1099
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1076
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1050
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationsController.cs: 52
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationsController.cs: 110
MEDIUM CSRF /src/Identity/Controllers/SsoController.cs: 41
MEDIUM CSRF /src/Api/SecretsManager/Controllers/AccessPoliciesController.cs: 266
MEDIUM CSRF /src/Api/Public/Controllers/CollectionsController.cs: 64
MEDIUM CSRF /src/Api/Controllers/SelfHosted/SelfHostedOrganizationLicensesController.cs: 51
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 247
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 128
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 119
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 99
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 61
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/OrganizationController.cs: 42
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 142
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 126
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 114
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProviderUsersController.cs: 75
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72
MEDIUM CSRF /bitwarden_license/src/Sso/Controllers/AccountController.cs: 240
MEDIUM CSRF /bitwarden_license/src/Sso/Controllers/AccountController.cs: 167
MEDIUM CSRF /bitwarden_license/src/Sso/Controllers/AccountController.cs: 100
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 171
MEDIUM CSRF /src/Api/Public/Controllers/CollectionsController.cs: 87
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 143
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 630
MEDIUM CSRF /src/Api/SecretsManager/Controllers/AccessPoliciesController.cs: 266
MEDIUM CSRF /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 609

More results are available on the CxOne platform

Extract methods to simplify organization ability fetching for ciphers, reducing code duplication and improving readability. Added two private helper methods:
- GetOrganizationAbilityAsync: Retrieves organization ability for a single cipher
- GetManyOrganizationAbilitiesAsync: Retrieves organization abilities for multiple ciphers
Modify test methods to:
- Replace GetProperUserId with GetUserByPrincipalAsync
- Use User object instead of separate userId
- Update mocking to return User object
- Ensure user ID is correctly set in test scenarios
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 29.69697% with 116 lines in your changes missing coverage. Please review.

Project coverage is 44.21%. Comparing base (1114c97) to head (8586e97).

Files with missing lines Patch % Lines
src/Api/Vault/Controllers/CiphersController.cs 18.85% 99 Missing ⚠️
...th/Models/Response/EmergencyAccessResponseModel.cs 0.00% 6 Missing ⚠️
...Implementations/InMemoryApplicationCacheService.cs 0.00% 6 Missing ⚠️
...c/Api/Vault/Models/Response/CipherResponseModel.cs 60.00% 2 Missing ⚠️
.../Api/Auth/Controllers/EmergencyAccessController.cs 0.00% 1 Missing ⚠️
.../Models/Response/CipherPermissionsResponseModel.cs 90.90% 1 Missing ⚠️
src/Api/Vault/Models/Response/SyncResponseModel.cs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@                            Coverage Diff                            @@
##           ac/pm-18086/add-authorization-methods    #5418      +/-   ##
=========================================================================
- Coverage                                  44.22%   44.21%   -0.02%     
=========================================================================
  Files                                       1501     1502       +1     
  Lines                                      69379    69478      +99     
  Branches                                    6248     6253       +5     
=========================================================================
+ Hits                                       30685    30720      +35     
- Misses                                     37370    37434      +64     
  Partials                                    1324     1324              

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

Comment on lines 115 to 116
Delete = NormalCipherPermissions.CanDelete(user, cipher, organizationAbility),
Restore = NormalCipherPermissions.CanRestore(user, cipher, organizationAbility)
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: this is probably better encapsulated in the ctor for the CipherPermissionsResponseModel.

Comment on lines +46 to +47
cipher.OrganizationId.HasValue && organizationAbilities.TryGetValue(cipher.OrganizationId.Value, out var organizationAbility) ?
organizationAbility : null,
Copy link
Member

Choose a reason for hiding this comment

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

This pattern is repeated a few times in different forms: "if it's an organizational cipher, find and pass in the orgAbility, otherwise null". It works but the caller has to know a bit too much about what's required and how to get it. Maybe that's just a limitation of passing all this into the static method vs. dependency injection. It did make me wonder whether we should pass in the IApplicationCacheService directly, or the dict of OrganizationAbilities, to push the detail down into the response model. But I'm not sure.

@r-tome r-tome mentioned this pull request Feb 21, 2025
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