diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj
index 6a1d0baa0..b8f5ff82a 100644
--- a/BTCPayServer/BTCPayServer.csproj
+++ b/BTCPayServer/BTCPayServer.csproj
@@ -49,6 +49,7 @@
+
diff --git a/BTCPayServer/Controllers/AccountController.cs b/BTCPayServer/Controllers/AccountController.cs
index 51e9c2156..2127e9eb3 100644
--- a/BTCPayServer/Controllers/AccountController.cs
+++ b/BTCPayServer/Controllers/AccountController.cs
@@ -18,6 +18,7 @@ using BTCPayServer.Services.Stores;
using BTCPayServer.Logging;
using BTCPayServer.Security;
using System.Globalization;
+using NicolasDorier.RateLimits;
namespace BTCPayServer.Controllers
{
@@ -70,6 +71,7 @@ namespace BTCPayServer.Controllers
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
+ [RateLimitsFilter(ZoneLimits.Login, Scope = RateLimitsScope.RemoteAddress)]
public async Task Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs
index ca03047c6..748cc0476 100644
--- a/BTCPayServer/Hosting/BTCPayServerServices.cs
+++ b/BTCPayServer/Hosting/BTCPayServerServices.cs
@@ -41,6 +41,7 @@ using System.Security.Claims;
using BTCPayServer.Security;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using NBXplorer.DerivationStrategy;
+using NicolasDorier.RateLimits;
namespace BTCPayServer.Hosting
{
@@ -165,6 +166,10 @@ namespace BTCPayServer.Hosting
{
options.AddPolicy(CorsPolicies.All, p=>p.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
});
+
+ var rateLimits = new RateLimitService();
+ rateLimits.SetZone($"zone={ZoneLimits.Login} rate=5r/min burst=3 nodelay");
+ services.AddSingleton(rateLimits);
return services;
}
diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs
index 52574eeff..f7f0b58c8 100644
--- a/BTCPayServer/Hosting/Startup.cs
+++ b/BTCPayServer/Hosting/Startup.cs
@@ -166,6 +166,7 @@ namespace BTCPayServer.Hosting
Authorization = new[] { new NeedRole(Roles.ServerAdmin) }
});
app.UseWebSockets();
+ app.UseStatusCodePages();
app.UseMvc(routes =>
{
routes.MapRoute(
diff --git a/BTCPayServer/ZoneLimits.cs b/BTCPayServer/ZoneLimits.cs
new file mode 100644
index 000000000..8214330a5
--- /dev/null
+++ b/BTCPayServer/ZoneLimits.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace BTCPayServer
+{
+ public class ZoneLimits
+ {
+ public const string Login = "btcpaylogin";
+ }
+}