[backend/core] Limit HttpClient buffer size to 1MiB, except DriveService from this policy (until proper limits are in place there)
This commit is contained in:
parent
f1b39981c6
commit
15d955c478
3 changed files with 17 additions and 1 deletions
|
@ -86,6 +86,7 @@ public static class ServiceExtensions
|
|||
// Singleton = instantiated once across application lifetime
|
||||
services
|
||||
.AddSingleton<HttpClient, CustomHttpClient>()
|
||||
.AddSingleton<UnrestrictedHttpClient>()
|
||||
.AddSingleton<HttpRequestService>()
|
||||
.AddSingleton<CronService>()
|
||||
.AddSingleton<QueueService>()
|
||||
|
|
|
@ -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<FastFallback>();
|
||||
FastFallbackHandler.Security = security;
|
||||
|
@ -362,4 +365,16 @@ public class CustomHttpClient : HttpClient
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UnrestrictedHttpClient : CustomHttpClient
|
||||
{
|
||||
public UnrestrictedHttpClient(
|
||||
IOptions<Config.InstanceSection> options,
|
||||
IOptionsMonitor<Config.SecuritySection> security,
|
||||
ILoggerFactory loggerFactory
|
||||
) : base(options, security, loggerFactory)
|
||||
{
|
||||
MaxResponseContentBufferSize = int.MaxValue;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ public class DriveService(
|
|||
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor")]
|
||||
IOptionsSnapshot<Config.StorageSection> storageConfig,
|
||||
IOptions<Config.InstanceSection> instanceConfig,
|
||||
HttpClient httpClient,
|
||||
UnrestrictedHttpClient httpClient,
|
||||
QueueService queueSvc,
|
||||
ILogger<DriveService> logger,
|
||||
ImageProcessor imageProcessor
|
||||
|
|
Loading…
Add table
Reference in a new issue