Skip to content

[PM-32187] Add Send Type restriction to Send Controls policy#7504

Open
mcamirault wants to merge 63 commits into
mainfrom
tools/pm-32187/restrict-send-type-policy
Open

[PM-32187] Add Send Type restriction to Send Controls policy#7504
mcamirault wants to merge 63 commits into
mainfrom
tools/pm-32187/restrict-send-type-policy

Conversation

@mcamirault

Copy link
Copy Markdown
Contributor

🎟️ 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

harr1424 and others added 30 commits March 1, 2026 18:13
• `IX_Policy_OrganizationId_Type` is a unique index

Co-authored-by: mkincaid-bw <mkincaid@bitwarden.com>
…rden/server into tools/PM-31885-SendControls-Policy

merge suggested changes to migration
…rden/server into tools/PM-31885-SendControls-Policy

merge main
- fix SQL syntax error
- escape Sqlite format specifier
- update migration IDs to match sorted filename
- fix SQL syntax error
@mcamirault mcamirault changed the base branch from tools/pm-31884/send-access-controls-policy to main May 15, 2026 14:14
@mcamirault mcamirault dismissed sven-bitwarden’s stale review May 15, 2026 14:14

The base branch was changed.

@mcamirault mcamirault marked this pull request as ready for review May 15, 2026 14:18

@mkincaid-bw mkincaid-bw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor changes requested.

Comment thread src/Sql/dbo/Tools/Stored Procedures/Send_ReadIdsByOrganizationId.sql Outdated
Comment thread src/Sql/dbo/Tools/Stored Procedures/Send_ReadIdsByOrganizationId.sql Outdated
Comment thread src/Sql/dbo/Tools/Stored Procedures/Send_ReadIdsByOrganizationId.sql Outdated
Comment thread src/Sql/dbo/Tools/Stored Procedures/Send_ReadIdsByOrganizationId.sql Outdated
Comment thread src/Sql/dbo/Tools/Stored Procedures/Send_UpdateDisabledByIds.sql Outdated
Comment thread util/Migrator/DbScripts/2026-05-15_00_SendAccessControlPolicyProcs.sql Outdated
Comment on lines +107 to +110
if (sendControlsRequirement.AllowedSendTypes != null && !sendControlsRequirement.AllowedSendTypes.Contains(send.Type))
{
throw new BadRequestException($"Due to an Enterprise policy your Sends must be of the following types: {string.Join(", ", sendControlsRequirement.AllowedSendTypes.Select(st => st == SendType.Text ? "Text" : st == SendType.File ? "File" : "Unknown"))}");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ DEBT: New AllowedSendTypes creation-time guard has no unit test.

Details

This branch is the bypass-resistant server-side enforcement (the CLI skips front-end checks), so it is the most important path to cover. The sync handler's equivalent logic got a test in this PR (SendControlsSyncPolicyEventTests), but SendValidationServiceTests.cs has no case asserting that a disallowed send.Type throws and an allowed one passes.

Project convention (CLAUDE.md): "ALWAYS add unit tests (with mocking) for any new feature development." Suggest adding a ValidateUserCanSaveAsync_WhenSendTypeRestrictedByPolicy test mirroring the existing domain/auth cases.

@mcamirault

Copy link
Copy Markdown
Contributor Author

@mkincaid-bw The procedure most of your comments were on was introduced in a different PR (for PM-31884), so I've added an update script to fix the procedure here

@sonarqubecloud

Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not certain if this file should be checked in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants