1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 20:50:21 -05:00

only use rate limiting on non-self host

This commit is contained in:
Kyle Spearrin 2017-08-15 16:33:38 -04:00
parent a2dc1602f8
commit 1ef76b562f

View File

@ -44,8 +44,11 @@ namespace Bit.Api
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
if(!globalSettings.SelfHosted)
{
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
}
// Data Protection
services.AddCustomDataProtectionServices(Environment, globalSettings);
@ -62,9 +65,12 @@ namespace Bit.Api
// Caching
services.AddMemoryCache();
// Rate limiting
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
if(!globalSettings.SelfHosted)
{
// Rate limiting
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
}
// Identity
services.AddCustomIdentityServices(globalSettings);
@ -158,8 +164,11 @@ namespace Bit.Api
app.UseForwardedHeadersForAzure();
}
// Rate limiting
app.UseMiddleware<CustomIpRateLimitMiddleware>();
if(!globalSettings.SelfHosted)
{
// Rate limiting
app.UseMiddleware<CustomIpRateLimitMiddleware>();
}
// Add static files to the request pipeline.
app.UseStaticFiles();