feat: Treat rate limit header value as comma-separated list #2282
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.
What kind of change does this PR introduce?
This PR updates
performRateLimitingto treat the rate limit header value as a comma-separated list and enforce rate limiting based on the first value in that list.What is the current behavior?
Certain HTTP headers, such as
X-Forwarded-Forand other headers that are combined according to RFC 7230, can be represented as a comma-separated list of values. Intermediate proxies may add their own values to these headers, modifying the resulting value. For example, an end user with a single IP address proxied through a fleet of load balancers using the X-Forwarded-For header may be associated with multipleX-Forwarded-Forheader values, e.g.,2.2.2.2,100.100.100.100and2.2.2.2,300.300.300.300. The current implementation ofperformRateLimitingtreats each of these as separate rate limiting keys.What is the new behavior?
This PR splits the rate limit header by commas and takes the first value (with whitespace removed) to use as the rate limiting key.
Note that this logic is superficially similar to the
utilities.GetIPAddressfunction with two key differences. InperformRateLimiting, there is no set format for a given rate limiting key, nor is there a fallback value after the first value in the list that the API should use.