mirror of
https://github.com/bitwarden/server
synced 2026-01-10 12:33:49 +00:00
Queue ip addresses for block whenever they exceed the rate limit too much
This commit is contained in:
@@ -8,14 +8,19 @@
|
||||
public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings();
|
||||
public virtual MailSettings Mail { get; set; } = new MailSettings();
|
||||
public virtual LoggrSettings Loggr { get; set; } = new LoggrSettings();
|
||||
public virtual CacheSettings Cache { get; set; } = new CacheSettings();
|
||||
public virtual PushSettings Push { get; set; } = new PushSettings();
|
||||
public virtual StorageSettings Storage { get; set; } = new StorageSettings();
|
||||
|
||||
public class SqlServerSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
}
|
||||
|
||||
public class StorageSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
}
|
||||
|
||||
public class MailSettings
|
||||
{
|
||||
public string ApiKey { get; set; }
|
||||
@@ -28,12 +33,6 @@
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
|
||||
public class CacheSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public int Database { get; set; }
|
||||
}
|
||||
|
||||
public class PushSettings
|
||||
{
|
||||
public string ApnsCertificateThumbprint { get; set; }
|
||||
|
||||
37
src/Core/Services/AzureBlockIpService.cs
Normal file
37
src/Core/Services/AzureBlockIpService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Queue;
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class AzureBlockIpService : IBlockIpService
|
||||
{
|
||||
private CloudQueue _blockIpQueue;
|
||||
private CloudQueue _unblockIpQueue;
|
||||
|
||||
public AzureBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
|
||||
_blockIpQueue = queueClient.GetQueueReference("blockip");
|
||||
_blockIpQueue.CreateIfNotExists();
|
||||
|
||||
_unblockIpQueue = queueClient.GetQueueReference("unblockip");
|
||||
_unblockIpQueue.CreateIfNotExists();
|
||||
}
|
||||
|
||||
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
|
||||
{
|
||||
var message = new CloudQueueMessage(ipAddress);
|
||||
await _blockIpQueue.AddMessageAsync(message);
|
||||
|
||||
if(!permanentBlock)
|
||||
{
|
||||
await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(12, 0, 0), null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Core/Services/IBlockIpService.cs
Normal file
10
src/Core/Services/IBlockIpService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public interface IBlockIpService
|
||||
{
|
||||
Task BlockIpAsync(string ipAddress, bool permanentBlock);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
"DataTableProxy": "1.2.0",
|
||||
"Sendgrid": "6.3.4",
|
||||
"StackExchange.Redis": "1.0.488",
|
||||
"PushSharp": "4.0.10"
|
||||
"PushSharp": "4.0.10",
|
||||
"WindowsAzure.Storage": "7.2.1"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
|
||||
Reference in New Issue
Block a user