A middleware that allows whitelist or blacklist incomming requests based on IP address. It can be configured using single IP address or ranges. It supports single IP, IP range IPv4 and IPv6.
Thanks for your contribution, I have a configuration where the web api receives a request only from a reverse proxy, but in the console it shows me the IP of the final client and I want to validate the IP of the proxy in this case, is it possible?
Any objections to me submitting a pull request that adds IP filtering as a MVC filter? This would bring in a new dependencies of Microsoft.AspNetCore.Mvc.Abstractions.
My thoughts here would be an attribute that could be applied either at the class or method level. Something like [IPFilter(Policy = "MyPolicy")] This would allow for either white listing, black listing at a more granular level than at the middle ware level.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at AspNetCoreRateLimit.Bits.GetBitMask(Int32 sizeOfBuff, Int32 bitLen)
at AspNetCoreRateLimit.IpAddressRange..ctor(String ipRangeString)
at AspNetCoreRateLimit.IpAddressUtil.ContainsIp(List`1 ipRules, String clientIp)
at AspNetCoreRateLimit.IpParser.ContainsIp(List`1 ipRules, String clientIp)
at AspNetCoreRateLimit.IpRateLimitProcessor.IsWhitelisted(ClientRequestIdentity requestIdentity)
at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context)
at ZNetCS.AspNetCore.IPFiltering.IPFilteringMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
However, the config will very rarely change between requests, so it'd be more efficient to only parse these once and reuse the same objects across requests.