I am trying to understand whether .NET Middleware will protect against Denial Of Service attacks on a sensitive area of a system. I can't find the answer in docs such as this.
The attack I've envisaged is this.
- An attacker gains rights to a NON Super-Admin user
- They then use these credentials to spam the Upload controller.
Here is the controller:
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace Test.controllers
{
[Authorize(Policy = "SuperAdmin")]
[ApiController]
public class UploadController : Controller
{
public UploadController()
{
}
[HttpPost, Route("upload")]
public async Task<ActionResult<string>> Upload()
{
try
{
// Exta checks
var file = Request.Form.Files[0];
// Do something with the file
}
catch (Exception ex)
{
// ...
}
return "OK";
}
}
}
So the Authorize attribute is ASP.NET Middleware that will bounce the request if the user isnt a 'SuperAdmin'.
What I'm unsure of though is - will the whole request reach the server, or is this done at the header level.
E.g. I want to upload a 500MB file.
Option 1
- Upload controller called (e.g. from a browser UI)
- API recieves headers
- middleware reads the headers (rejects if insufficient permissions - has only taken a few bytes to get to this decision)
- Middleware accepts - controller now accepts the 500MB file.
- This would mean only a few bytes of data transfer if not permitted.
Option 2
- Upload controller called (e.g. from a browser UI)
- Whole 500MB+ request to API controller
- The controller recieves the whole payload
- In among the payload, retrieves header.
- Accepts or rejects (but 500MB has been transferred before the decision has been made).
Obviously, option 2 would be much more susceptible to DOS attacks, so I'm hoping it's Option 1, but I can't find the answer.
How does this actually flow please?