From 37a57cb774d36fef2bb1ace17216986d2901eb1b Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Tue, 15 Apr 2025 15:20:58 +0200 Subject: [PATCH] Added request size limit option --- .../Configuration/AppConfiguration.cs | 6 +++++ MoonlightServers.Daemon/Startup.cs | 24 +++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/MoonlightServers.Daemon/Configuration/AppConfiguration.cs b/MoonlightServers.Daemon/Configuration/AppConfiguration.cs index 7166a46..658849f 100644 --- a/MoonlightServers.Daemon/Configuration/AppConfiguration.cs +++ b/MoonlightServers.Daemon/Configuration/AppConfiguration.cs @@ -10,6 +10,12 @@ public class AppConfiguration public RemoteData Remote { get; set; } = new(); public FilesData Files { get; set; } = new(); public ServerData Server { get; set; } = new(); + public KestrelData Kestrel { get; set; } = new(); + + public class KestrelData + { + public int RequestBodySizeLimit { get; set; } = 25; + } public class RemoteData { diff --git a/MoonlightServers.Daemon/Startup.cs b/MoonlightServers.Daemon/Startup.cs index 000a3d4..a6efe95 100644 --- a/MoonlightServers.Daemon/Startup.cs +++ b/MoonlightServers.Daemon/Startup.cs @@ -89,7 +89,8 @@ public class Startup { WebApplicationBuilder.WebHost.ConfigureKestrel(options => { - options.Limits.MaxRequestBodySize = ByteConverter.FromMegaBytes(Configuration.Files.UploadChunkSize).Bytes; + options.Limits.MaxRequestBodySize = + ByteConverter.FromMegaBytes(Configuration.Kestrel.RequestBodySizeLimit).Bytes; }); return Task.CompletedTask; @@ -375,21 +376,12 @@ public class Startup // We are defining the access token policies here. Because the same jwt secret is used by the panel // to generate jwt access tokens for all sorts of daemon related stuff we need to separate // the type of access token using the type parameter provided in the claims. - - options.AddPolicy("serverWebsocket", builder => - { - builder.RequireClaim("type", "websocket"); - }); - - options.AddPolicy("serverUpload", builder => - { - builder.RequireClaim("type", "upload"); - }); - - options.AddPolicy("serverDownload", builder => - { - builder.RequireClaim("type", "download"); - }); + + options.AddPolicy("serverWebsocket", builder => { builder.RequireClaim("type", "websocket"); }); + + options.AddPolicy("serverUpload", builder => { builder.RequireClaim("type", "upload"); }); + + options.AddPolicy("serverDownload", builder => { builder.RequireClaim("type", "download"); }); }); return Task.CompletedTask;