Skip to content

Commit e639e8f

Browse files
authored
Merge pull request #43 from dustout/feature/20250524-added-sanity-checks
Added sanity check to width and height
2 parents 0b585e7 + 8c6e194 commit e639e8f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CommonImageActions.AspNetCore/CommonImageActionSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public string PathToWatch
4040

4141
public static string DefaultDiskCacheLocation { get; set; }
4242

43+
public static int MaxUrlWidth { get; set; } = 5000;
44+
45+
public static int MaxUrlHeight { get; set; } = 5000;
46+
4347
public static string[] ValidImageExtensions = {
4448
".bmp",
4549
".gif",

CommonImageActions.AspNetCore/CommonImageActionsMiddleware.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,21 @@ public static ImageActions ConvertQueryStringToImageActions(string queryString,
281281
var widthString = query["width"] ?? query["w"];
282282
if (int.TryParse(widthString, out int width))
283283
{
284-
imageActions.Width = width;
284+
//sanity check to make sure no bad actor requests a number that may eat all the ram in the system
285+
if(width < CommonImageActionSettings.MaxUrlWidth)
286+
{
287+
imageActions.Width = width;
288+
}
285289
}
286290

287291
var heightString = query["height"] ?? query["h"];
288292
if (int.TryParse(heightString, out int height))
289293
{
290-
imageActions.Height = height;
294+
//sanity check to make sure no bad actor requests a number that may eat all the ram in the system
295+
if (width < CommonImageActionSettings.MaxUrlHeight)
296+
{
297+
imageActions.Height = height;
298+
}
291299
}
292300

293301
var pageString = query["Page"] ?? query["p"];

0 commit comments

Comments
 (0)