Enhance rate limiter with whitelist support#7879
Open
danFbach wants to merge 2 commits intonopSolutions:developfrom
Open
Enhance rate limiter with whitelist support#7879danFbach wants to merge 2 commits intonopSolutions:developfrom
danFbach wants to merge 2 commits intonopSolutions:developfrom
Conversation
Added `RateLimitWhitelist` to `CommonConfig` to exempt specific IPs from rate limiting. Updated `ServiceCollectionExtensions` 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.
… area allow ips. use ip for GetNoLimiter partitionKey.
Contributor
Author
|
I'll just add - with the dramatic increase in AI related bot traffic - these changes to the rate limiter have really helped my site stay fast and proactively reject abusive traffic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
RateLimitWhitelisttoCommonConfigto exempt specific IPs from rate limiting. UpdatedServiceCollectionExtensionsto 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.Hostwhich 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.