mirror of
https://github.com/bitwarden/server
synced 2025-12-22 11:13:27 +00:00
Use RequestSizeLimit for all file upload endpoints (#1507)
* Enforce upload size limits via RequestSizeLimit instead of if statements * 101mb limit for legacy uploads, 501mb limit for all other * Only allow v2 local storage for self-hosted instances
This commit is contained in:
@@ -167,6 +167,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("file")]
|
||||
[Obsolete("Deprecated File Send API", false)]
|
||||
[RequestSizeLimit(Constants.FileSize101mb)]
|
||||
[DisableFormValueModelBinding]
|
||||
public async Task<SendResponseModel> PostFile()
|
||||
@@ -176,11 +177,6 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("Invalid content.");
|
||||
}
|
||||
|
||||
if (Request.ContentLength > Constants.FileSize101mb)
|
||||
{
|
||||
throw new BadRequestException("Max file size is 100 MB.");
|
||||
}
|
||||
|
||||
Send send = null;
|
||||
await Request.GetSendFileAsync(async (stream, fileName, model) =>
|
||||
{
|
||||
@@ -250,6 +246,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("{id}/file/{fileId}")]
|
||||
[SelfHosted(SelfHostedOnly = true)]
|
||||
[RequestSizeLimit(Constants.FileSize501mb)]
|
||||
[DisableFormValueModelBinding]
|
||||
public async Task PostFileForExistingSend(string id, string fileId)
|
||||
@@ -259,11 +256,6 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("Invalid content.");
|
||||
}
|
||||
|
||||
if (Request.ContentLength > Constants.FileSize101mb && !_globalSettings.SelfHosted)
|
||||
{
|
||||
throw new BadRequestException("Max file size for direct upload is 100 MB.");
|
||||
}
|
||||
|
||||
var send = await _sendRepository.GetByIdAsync(new Guid(id));
|
||||
await Request.GetFileAsync(async (stream) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user