Repository navigation
Resolve client identity only from trusted proxies - #114
Merged
Merged
Conversation
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.
Pull Request Template
Description
Resolve the client identity used by the rate limiter and auth log attribution from the
connection peer instead of trusting
X-Forwarded-Forunconditionally. Previously any APIcaller could rotate the header to mint fresh rate-limit buckets (bypassing the limit
entirely) or forge a victim's address to consume its quota.
The header is now honoured only when the connection peer is declared in the new
api.trusted_proxiessetting (default[], i.e. the header is always ignored): the chainis walked right-to-left with
ipaddressvalidation, malformed hops fail closed, IPv4-mappedforms are normalized and an unparseable peer collapses to the shared
unknownbucket.Both launch paths start Uvicorn with
proxy_headers=False, so forwarded headers can neverrewrite the peer before the policy runs and
FORWARDED_ALLOW_IPSis irrelevant to clientidentification. The rate-limit middleware and auth log attribution share one resolver.
Configuration entries are validated when the config is built: catch-all networks
(
0.0.0.0/0,::/0, IPv4-mapped/96), IPv6 zone identifiers and invalid values arerejected; host bits are masked with a warning.
Validation:
tests/unit1731 passed / 3 skipped,tests/integration/api57 passed,ruff check .,ruff formatandpyrightclean. A mutation check confirmed that all 9security regression tests fail against the previous implementation while functional tests
still pass.
Related Issue
No linked issue (no public issue tracker entry for this change).
Type of Change
Checklist
Screenshots (if applicable)
Not applicable — backend/security behaviour only; no UI changes.