I am using ImageSharp.Web to resize images on my ASP.NET Core 5.0 website.
To prevent DDoS (Distributed Denial of Service attacks), I would like to restrict the sizes that ImageSharp.Web can resize too.
For example I have an image with an original size of 800x400 (100kb) that I am resizing using the following:
<img src="image.jpg?width=300&height=300" alt="..." /> // image will be 40 kb, bandwidth saved yay!
The problem is if an evil user decides to request the image with:
<img src="image.jpg?width=8000&height=4000" alt="..." /> // 8,000 x 4,000 => image is now 2mb
If that user request this image with 'high-numbered' pixel sizes (7000,7001,7002...8000} say 10,000 times the server will become non-responsive due to memory exhausting and bandwidth usage.
- How can I restrict ImageSharp.Web to not resize images above their original size?
- How can I restrict ImageSharp.Web to only resize images to e.g. 300x300, and 300x600?
I don't see any configurable options for that in ImageSharp.Web (https://docs.sixlabors.com/articles/imagesharp.web/gettingstarted.html).
My startup.cs:
public void ConfigureServices(IServiceCollection services)
{
// ....
services.AddImageSharp();
}