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

validate send model parameters (#1067)

This commit is contained in:
Kyle Spearrin
2020-12-30 16:25:00 -05:00
committed by GitHub
parent 4825998ba5
commit d96da37e2a
2 changed files with 20 additions and 0 deletions

View File

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Bit.Core.Models.Data;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Services;
using Bit.Core.Exceptions;
namespace Bit.Core.Models.Api
{
@ -22,6 +23,7 @@ namespace Bit.Core.Models.Api
[EncryptedString]
[EncryptedStringLength(1000)]
public string Key { get; set; }
[Range(1, int.MaxValue)]
public int? MaxAccessCount { get; set; }
public DateTime? ExpirationDate { get; set; }
[Required]
@ -77,6 +79,22 @@ namespace Bit.Core.Models.Api
return existingSend;
}
public void ValidateCreation()
{
// Add 1 minute for a sane buffer and client clock float
var nowPlus1Minute = DateTime.UtcNow.AddMinutes(1);
if (ExpirationDate.HasValue && ExpirationDate.Value <= nowPlus1Minute)
{
throw new BadRequestException("You cannot create a send that is already expired. " +
"Adjust the expiration date and try again.");
}
if (DeletionDate.HasValue && DeletionDate.Value <= nowPlus1Minute)
{
throw new BadRequestException("You cannot create a send that is already deleted. " +
"Adjust the deletion date and try again.");
}
}
private Send ToSendBase(Send existingSend, ISendService sendService)
{
existingSend.Key = Key;