MandalaConsulting.APIMiddlewares
0.0.14
dotnet add package MandalaConsulting.APIMiddlewares --version 0.0.14
NuGet\Install-Package MandalaConsulting.APIMiddlewares -Version 0.0.14
<PackageReference Include="MandalaConsulting.APIMiddlewares" Version="0.0.14" />
<PackageVersion Include="MandalaConsulting.APIMiddlewares" Version="0.0.14" />
<PackageReference Include="MandalaConsulting.APIMiddlewares" />
paket add MandalaConsulting.APIMiddlewares --version 0.0.14
#r "nuget: MandalaConsulting.APIMiddlewares, 0.0.14"
#:package MandalaConsulting.APIMiddlewares@0.0.14
#addin nuget:?package=MandalaConsulting.APIMiddlewares&version=0.0.14
#tool nuget:?package=MandalaConsulting.APIMiddlewares&version=0.0.14
MandalaConsulting.APIMiddleware
Overview
The MandalaConsulting.APIMiddleware library is a comprehensive middleware solution for ASP.NET Core applications. It provides tools for security, performance optimization, and API monitoring. Features include IP blacklisting, invalid endpoint tracking, memory management, and API key validation, designed to enhance the reliability and security of your APIs.
Features
Security and Monitoring
- IP Blacklisting: Automatically blocks malicious IPs after repeated unauthorized attempts.
- Invalid Endpoint Tracking: Monitors failed attempts to access non-existent endpoints and prevents abuse.
- API Key Validation: Ensures requests are authorized with the correct API key.
- Logging: Captures detailed logs of unauthorized access attempts and API interactions.
Performance Optimization
- Memory Management: Includes garbage collection based on endpoint usage patterns.
- Idle Endpoint Detection: Identifies idle endpoints to optimize resource usage.
Flexible Middleware
- Designed to be easily integrated into any ASP.NET Core application.
Installation
Add the library to your ASP.NET Core project and reference the necessary namespaces:
using MandalaConsulting.APIMiddleware;
using MandalaConsulting.APIMiddleware.Filters;
using MandalaConsulting.APIMiddleware.Utility;
using MandalaConsulting.Logging;
Usage
Middleware Components
InvalidEndpointTrackerMiddleware
Tracks attempts to access invalid endpoints and blocks malicious activity.
Example Integration
public void Configure(IApplicationBuilder app)
{
app.UseMiddleware<InvalidEndpointTrackerMiddleware>();
}
IPBlacklistMiddleware
Blocks requests from IPs flagged for malicious activity.
Example Integration
public void Configure(IApplicationBuilder app)
{
app.UseMiddleware<IPBlacklistMiddleware>();
}
Get Blocked IPs Log
var logs = IPBlacklistMiddleware.GetLogs();
foreach (var log in logs)
{
Console.WriteLine(log.message);
}
EndpointAccessMiddleware
Monitors endpoint activity and performs memory cleanup if endpoints remain idle.
Example Integration
public void Configure(IApplicationBuilder app)
{
app.UseMiddleware<EndpointAccessMiddleware>(TimeSpan.FromMinutes(5), true);
}
Filters
APIKeyAttribute
Validates requests with an API key stored in environment variables.
Example Usage
Apply the attribute to a controller or action:
[APIKey]
[ApiController]
[Route("[controller]")]
public class SecureController : ControllerBase
{
[HttpGet]
public IActionResult GetData()
{
return Ok("Secure Data Accessed");
}
}
Environment Variables Required
API_KEY
: Your API key.API_KEY_NAME
: Header name for the API key.
Security Features
IP Blocking
IP addresses are automatically blocked after exceeding the threshold for unauthorized attempts.
IPBlacklist.AddBannedIP("192.168.1.1", "Repeated unauthorized attempts.");
Logging
All middleware components use the logging system provided by MandalaConsulting.Logging
.
Add Logs
IPBlacklistMiddleware.AddLog(LogMessage.Warning("Suspicious activity detected."));
Retrieve Logs
var logs = IPBlacklistMiddleware.GetLogs();
foreach (var log in logs)
{
Console.WriteLine(log.message);
}
Clear Logs
IPBlacklistMiddleware.ClearLogs();
Requirements
- .NET Core 3.1 or later
- ASP.NET Core
License
This project is copyrighted © 2024 Mandala Consulting, LLC.
All Rights Reserved.
Author
Created by Alexander Fields
For inquiries, please contact Mandala Consulting.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- MandalaConsulting.Logging (>= 0.0.7)
- MandalaConsulting.Memory (>= 0.0.5)
- Microsoft.AspNetCore (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
0.0.14 | 675 | 7/5/2025 | |
0.0.13 | 579 | 6/10/2025 | |
0.0.12 | 319 | 6/10/2025 | |
0.0.11 | 465 | 6/8/2025 | |
0.0.10 | 456 | 6/8/2025 | |
0.0.10-develop.8 | 414 | 6/8/2025 | |
0.0.9 | 455 | 6/8/2025 | |
0.0.9-develop.7 | 407 | 6/8/2025 | |
0.0.8 | 724 | 10/15/2024 | |
0.0.7 | 364 | 10/15/2024 | |
0.0.6 | 355 | 10/15/2024 | |
0.0.5 | 351 | 10/15/2024 | |
0.0.4 | 379 | 10/14/2024 | |
0.0.3 | 375 | 10/14/2024 | |
0.0.2 | 381 | 10/13/2024 | |
0.0.1 | 396 | 10/12/2024 |