diff --git a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs index 5d3cbfcb..7e18a8be 100644 --- a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs @@ -86,6 +86,7 @@ public static class ServiceExtensions // Singleton = instantiated once across application lifetime services .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/Iceshrimp.Backend/Core/Services/CustomHttpClient.cs b/Iceshrimp.Backend/Core/Services/CustomHttpClient.cs index d2d0a5ac..12cb31bd 100644 --- a/Iceshrimp.Backend/Core/Services/CustomHttpClient.cs +++ b/Iceshrimp.Backend/Core/Services/CustomHttpClient.cs @@ -31,6 +31,9 @@ public class CustomHttpClient : HttpClient DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", options.Value.UserAgent); Timeout = TimeSpan.FromSeconds(30); + // Protect against DoS attacks + MaxResponseContentBufferSize = 1024 * 1024; // 1MiB + // Configure FastFallback FastFallbackHandler.Logger = loggerFactory.CreateLogger(); FastFallbackHandler.Security = security; @@ -362,4 +365,16 @@ public class CustomHttpClient : HttpClient } } } +} + +public class UnrestrictedHttpClient : CustomHttpClient +{ + public UnrestrictedHttpClient( + IOptions options, + IOptionsMonitor security, + ILoggerFactory loggerFactory + ) : base(options, security, loggerFactory) + { + MaxResponseContentBufferSize = int.MaxValue; + } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index ea79bdac..119f71b8 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -17,7 +17,7 @@ public class DriveService( [SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor")] IOptionsSnapshot storageConfig, IOptions instanceConfig, - HttpClient httpClient, + UnrestrictedHttpClient httpClient, QueueService queueSvc, ILogger logger, ImageProcessor imageProcessor