1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

Hide email address in Sends (#1234)

* Add send HideEmail to tables and models

* Respect HideEmail setting for Sends

* Recreate SendView to include new HideEmail column

* Enforce new Send policy

* Insert default value for new HideEmail column

* Delete c95d7598-71cc-4eab-8b08-aced0045198b.json

* Remove unrelated files

* Revert disableSendPolicy, add sendOptionsPolicy

* Minor style fixes

* Update SQL project with Send.HideEmail column

* unit test SendOptionsPolicy.DisableHideEmail

* Add SendOptionsPolicy to Portal

* Make HideEmail nullable, fix migrator script

* Remove NOT NULL constraint from HideEmail

* Fix style

* Make HideEmail nullable

* minor fixes to model and error message

* Move SendOptionsExemption banner

Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
This commit is contained in:
Thomas Rittson
2021-03-29 07:56:56 +10:00
committed by GitHub
parent 94249747b4
commit 688cc00d48
17 changed files with 334 additions and 17 deletions

View File

@ -70,7 +70,7 @@ namespace Bit.Api.Controllers
}
var sendResponse = new SendAccessResponseModel(send, _globalSettings);
if (send.UserId.HasValue)
if (send.UserId.HasValue && !send.HideEmail.GetValueOrDefault())
{
var creator = await _userService.GetUserByIdAsync(send.UserId.Value);
sendResponse.CreatorIdentifier = creator.Email;

View File

@ -9,5 +9,6 @@
RequireSso = 4,
PersonalOwnership = 5,
DisableSend = 6,
SendOptions = 7,
}
}

View File

@ -35,6 +35,7 @@ namespace Bit.Core.Models.Api
public string Password { get; set; }
[Required]
public bool? Disabled { get; set; }
public bool? HideEmail { get; set; }
public Send ToSend(Guid userId, ISendService sendService)
{
@ -125,6 +126,7 @@ namespace Bit.Core.Models.Api
existingSend.Password = sendService.HashPassword(Password);
}
existingSend.Disabled = Disabled.GetValueOrDefault();
existingSend.HideEmail = HideEmail.GetValueOrDefault();
return existingSend;
}
}

View File

@ -29,6 +29,7 @@ namespace Bit.Core.Models.Api
DeletionDate = send.DeletionDate;
Password = send.Password;
Disabled = send.Disabled;
HideEmail = send.HideEmail.GetValueOrDefault();
SendData sendData;
switch (send.Type)
@ -66,5 +67,6 @@ namespace Bit.Core.Models.Api
public DateTime RevisionDate { get; set; }
public DateTime? ExpirationDate { get; set; }
public DateTime DeletionDate { get; set; }
public bool HideEmail { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Data
{
public class SendOptionsPolicyData
{
[Display(Name = "DisableHideEmail")]
public bool DisableHideEmail { get; set; }
}
}

View File

@ -20,6 +20,7 @@ namespace Bit.Core.Models.Table
public DateTime? ExpirationDate { get; set; }
public DateTime DeletionDate { get; set; }
public bool Disabled { get; set; }
public bool? HideEmail { get; set; }
public void SetNewId()
{

View File

@ -598,6 +598,24 @@
<data name="DisableSendExemption" xml:space="preserve">
<value>Organization Owners and Administrators are exempt from this policy's enforcement.</value>
</data>
<data name="SendOptions" xml:space="preserve">
<value>Send Options</value>
<comment>'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated.</comment>
</data>
<data name="Options" xml:space="preserve">
<value>Options</value>
</data>
<data name="DisableHideEmail" xml:space="preserve">
<value>Do not allow users to hide their email address when creating or editing a Send.</value>
<comment>'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated.</comment>
</data>
<data name="SendOptionsDescription" xml:space="preserve">
<value>Set options for creating and editing Sends.</value>
<comment>'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated.</comment>
</data>
<data name="SendOptionsExemption" xml:space="preserve">
<value>Organization Owners and Administrators are exempt from this policy's enforcement.</value>
</data>
<data name="DisableRequireSsoError" xml:space="preserve">
<value>You must manually disable the Single Sign-On Authentication policy before this policy can be disabled.</value>
</data>

View File

@ -59,7 +59,7 @@ namespace Bit.Core.Services
public async Task SaveSendAsync(Send send)
{
// Make sure user can save Sends
await ValidateUserCanSaveAsync(send.UserId);
await ValidateUserCanSaveAsync(send.UserId, send);
if (send.Id == default(Guid))
{
@ -265,7 +265,7 @@ namespace Bit.Core.Services
return _passwordHasher.HashPassword(new User(), password);
}
private async Task ValidateUserCanSaveAsync(Guid? userId)
private async Task ValidateUserCanSaveAsync(Guid? userId, Send send)
{
if (!userId.HasValue || (!_currentContext.Organizations?.Any() ?? true))
{
@ -286,6 +286,23 @@ namespace Bit.Core.Services
throw new BadRequestException("Due to an Enterprise Policy, you are only able to delete an existing Send.");
}
}
if (send.HideEmail.GetValueOrDefault())
{
foreach (var policy in policies.Where(p => p.Enabled && p.Type == PolicyType.SendOptions && !_currentContext.ManagePolicies(p.OrganizationId)))
{
SendOptionsPolicyData data = null;
if (policy.Data != null)
{
data = JsonConvert.DeserializeObject<SendOptionsPolicyData>(policy.Data);
}
if (data?.DisableHideEmail ?? false)
{
throw new BadRequestException("Due to an Enterprise Policy, you are not allowed to hide your email address from recipients when creating or editing a Send.");
}
}
}
}
private async Task<long> StorageRemainingForSendAsync(Send send)

View File

@ -12,7 +12,8 @@
@RevisionDate DATETIME2(7),
@ExpirationDate DATETIME2(7),
@DeletionDate DATETIME2(7),
@Disabled BIT
@Disabled BIT,
@HideEmail BIT
AS
BEGIN
SET NOCOUNT ON
@ -32,7 +33,8 @@ BEGIN
[RevisionDate],
[ExpirationDate],
[DeletionDate],
[Disabled]
[Disabled],
[HideEmail]
)
VALUES
(
@ -49,7 +51,8 @@ BEGIN
@RevisionDate,
@ExpirationDate,
@DeletionDate,
@Disabled
@Disabled,
@HideEmail
)
IF @UserId IS NOT NULL
@ -61,4 +64,4 @@ BEGIN
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
END
-- TODO: OrganizationId bump?
END
END

View File

@ -12,7 +12,8 @@
@RevisionDate DATETIME2(7),
@ExpirationDate DATETIME2(7),
@DeletionDate DATETIME2(7),
@Disabled BIT
@Disabled BIT,
@HideEmail BIT
AS
BEGIN
SET NOCOUNT ON
@ -32,7 +33,8 @@ BEGIN
[RevisionDate] = @RevisionDate,
[ExpirationDate] = @ExpirationDate,
[DeletionDate] = @DeletionDate,
[Disabled] = @Disabled
[Disabled] = @Disabled,
[HideEmail] = @HideEmail
WHERE
[Id] = @Id
@ -41,4 +43,4 @@ BEGIN
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
END
-- TODO: OrganizationId bump?
END
END

View File

@ -13,6 +13,7 @@
[ExpirationDate] DATETIME2 (7) NULL,
[DeletionDate] DATETIME2 (7) NOT NULL,
[Disabled] BIT NOT NULL,
[HideEmail] BIT NULL,
CONSTRAINT [PK_Send] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Send_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
CONSTRAINT [FK_Send_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])