Enhance rate limiter with whitelist support #7879
Open
+26
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
RateLimitWhitelist
toCommonConfig
to exempt specific IPs from rate limiting. UpdatedServiceCollectionExtensions
to bypass rate limiting for whitelisted IPs, admin-allowed IPs, and localhost. Improved partition key logic for more granular rate limiting. Maintained backward compatibility with existing configurations.Localhost must be allowed to prevent scheduled tasks from being rate limited, as well as any other internal functions.
I've started using the rate limited because non-standard webscrapers are bogging down my site, but not quite enough traffic to trigger other protections. This seeks to improve upon existing code, making it a bit more extensible and also more robust, but improving how the partition key is created. If it is a guest account that needs rate limiting, it will fall back to
httpContext.Request.Headers.Host
which is unreliable because it is provided by the client and even if it isn't tampered with, it would be the domain, which would essentially ratelimit traffic to whole website for all guests if triggered, so there should be other unique identifiers considered before falling back to host (if it should ever be fallen back on).appsettings.json will also need a field added, but it is not tracked in git.