[PM-32187] Add Send Type restriction to Send Controls policy#7504
[PM-32187] Add Send Type restriction to Send Controls policy#7504mcamirault wants to merge 2 commits intotools/pm-31884/send-access-controls-policyfrom
Conversation
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR adds a Code Review DetailsNo new findings. The previously flagged CRITICAL issue in |
| (sendControlsPolicyData.WhoCanAccess == SendWhoCanAccessType.SpecificPeople && !SendValidationService.SendAllEmailsHaveAllowedDomains(send.Emails, sendControlsPolicyData.AllowedDomains))) || | ||
| (sendControlsPolicyData.RestrictSendType != null && send.Type != sendControlsPolicyData.RestrictSendType)) |
There was a problem hiding this comment.
❌ CRITICAL: RestrictSendType check is outside the postUpsertedPolicyState.Enabled guard, breaking the re-enable behavior when the policy is disabled.
Details and fix
Counting parentheses, the current condition parses as:
(postUpsertedPolicyState.Enabled && (DisableSend || ... || AllowedDomains check))
||
(RestrictSendType != null && send.Type != RestrictSendType)
The new disjunct on line 101 is outside the Enabled guard. This regresses the intent documented on line 94 ("If the policy is disabled then we want to re-enable any Sends that were previously disabled").
Repro scenario:
- Admin enables SendControls with
RestrictSendType = Text→FileSends get disabled (correct). - Admin later disables the SendControls policy. Policy data still contains
RestrictSendType = Text. - Handler runs:
postUpsertedPolicyState.Enabled == false, butRestrictSendType != nullandsend.Type != RestrictSendTypefor File Sends, so those File Sends are added todisabled(line 103) andUpdateManyDisabledAsync(..., true)is called, leaving them disabled instead of re-enabling them.
Fix — move the new clause inside the Enabled guard (same group as the other checks):
| (sendControlsPolicyData.WhoCanAccess == SendWhoCanAccessType.SpecificPeople && !SendValidationService.SendAllEmailsHaveAllowedDomains(send.Emails, sendControlsPolicyData.AllowedDomains))) || | |
| (sendControlsPolicyData.RestrictSendType != null && send.Type != sendControlsPolicyData.RestrictSendType)) | |
| (sendControlsPolicyData.WhoCanAccess == SendWhoCanAccessType.SpecificPeople && !SendValidationService.SendAllEmailsHaveAllowedDomains(send.Emails, sendControlsPolicyData.AllowedDomains)) || | |
| (sendControlsPolicyData.RestrictSendType != null && send.Type != sendControlsPolicyData.RestrictSendType))) |
Also consider adding a test that sets RestrictSendType with postUpsertedPolicy.Enabled == false and asserts non-matching Sends are re-enabled (not disabled) — the current new test only exercises the enabled path.
|
New Issues (1)Checkmarx found the following issues in this Pull Request
|
95a40df to
72a8b71
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## tools/pm-31884/send-access-controls-policy #7504 +/- ##
==============================================================================
- Coverage 63.58% 59.08% -4.50%
==============================================================================
Files 2077 2078 +1
Lines 91970 91823 -147
Branches 8192 8168 -24
==============================================================================
- Hits 58482 54257 -4225
- Misses 31465 35629 +4164
+ Partials 2023 1937 -86 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|





🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-32187
📔 Objective
This PR adds a field to the Send Controls policy that can be used to restrict which types of Sends can be created
📸 Screenshots
N/A