1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 13:08:17 -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 // Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration); var globalSettings = services.AddGlobalSettingsServices(Configuration);
if(!globalSettings.SelfHosted)
{
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions")); services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies")); services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
}
// Data Protection // Data Protection
services.AddCustomDataProtectionServices(Environment, globalSettings); services.AddCustomDataProtectionServices(Environment, globalSettings);
@ -62,9 +65,12 @@ namespace Bit.Api
// Caching // Caching
services.AddMemoryCache(); services.AddMemoryCache();
if(!globalSettings.SelfHosted)
{
// Rate limiting // Rate limiting
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
}
// Identity // Identity
services.AddCustomIdentityServices(globalSettings); services.AddCustomIdentityServices(globalSettings);
@ -158,8 +164,11 @@ namespace Bit.Api
app.UseForwardedHeadersForAzure(); app.UseForwardedHeadersForAzure();
} }
if(!globalSettings.SelfHosted)
{
// Rate limiting // Rate limiting
app.UseMiddleware<CustomIpRateLimitMiddleware>(); app.UseMiddleware<CustomIpRateLimitMiddleware>();
}
// Add static files to the request pipeline. // Add static files to the request pipeline.
app.UseStaticFiles(); app.UseStaticFiles();