TrafficFilter 0.1.0-alpha
See the version list below for details.
dotnet add package TrafficFilter --version 0.1.0-alpha
NuGet\Install-Package TrafficFilter -Version 0.1.0-alpha
<PackageReference Include="TrafficFilter" Version="0.1.0-alpha" />
paket add TrafficFilter --version 0.1.0-alpha
#r "nuget: TrafficFilter, 0.1.0-alpha"
// Install TrafficFilter as a Cake Addin #addin nuget:?package=TrafficFilter&version=0.1.0-alpha&prerelease // Install TrafficFilter as a Cake Tool #tool nuget:?package=TrafficFilter&version=0.1.0-alpha&prerelease
TrafficFilter
ASP.NET Core middleware for request filtering and rate limiting
About
TrafficFilter is an ASP.NET Core middleware that enables request filtering and rate-limiting. There are the following request filtering features:
- Url filtering
- Headers filtering
- Rate limiting
Each feature can be enabled and configured in the config file.
TrafficFilter may be useful in scenarios when you want to protect your web app and server resources from various scanning bots that try to access non-existent URLs by blacklisting their IP addresses for a configured amount of time.
Another use case could be protecting the app if it is accessed using a public server IP address.
It can also block traffic if configured path-based rate limit is reached.
Getting Started
First install the TrafficFilter NuGet package using PowerShell:
PM> Install-Package TrafficFilter
or via the dotnet command line:
dotnet add package TrafficFilter
Then add the TrafficFilter middleware to your ASP.NET Core Startup
class:
using TrafficFilter;
namespace SampleWebApp
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// --- TrafficFilter ---
services.AddTrafficFilter(Configuration);
//...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// --- TrafficFilter - topmost important! ---
app.UseTrafficFilter();
//...
}
}
}
Add TrafficFilter configuration section to appsettings.json
, modify it as needed:
"TrafficFilter": {
"IPBlacklistTimeoutSeconds": 5,
"RequestFilterUrl": {
"IsEnabled": true,
"Matches": [
{
"Type": "MatchRegex",
"Match": "https?:\\/\\/[\\d*\\.*]+" //Pattern for IP Address based Url
},
{
"Type": "MatchEndsWith",
"Match": ".xml"
},
{
"Type": "MatchContains",
"Match": "mysql"
},
{
"Type": "MatchStartsWith",
"Match": "ftp"
}
]
},
"RequestFilterHeaders": {
"IsEnabled": true,
"Matches": [
{
"Header": "user-agent",
"Type": "MatchContains",
"Match": "x-bot"
}
]
},
"RateLimiter": {
"IsEnabled": true,
"RateLimiterWindowSeconds": 1,
"RateLimiterRequestLimit": 10,
"SkipUrls": [ // Add matches here if you want to exclude them from rate limiting
{
"Type": "MatchEndsWith",
"Match": ".mp4"
}
]
}
}
Documentation
If any of the enabled filters matches the incoming request, the requester's IP address is added to the blacklist for the duration of IPBlacklistTimeoutSeconds
and HttpStatusCode.TooManyRequests
is returned.
Possible values for Match Type are: MatchStartsWith
, MatchContains
, MatchEndsWith
and MatchRegex
.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.Extensions.Configuration (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.