4.1.0 hardening: exact proxy matching, deterministic header folding, config validation - #30
Merged
Merged
Conversation
…r folding, config validation - proxy_list: complete IPs match exactly (v3 prefix-matched, so 1.2.3.4 trusted 1.2.3.45); prefixes match on octet/group boundaries; IPv6 entries case/zero-insensitive; mapped/NAT64 CIDRs match unwrapped IPv4 hops. - Folded header keys: dash spelling wins regardless of dict order, so a client underscore header cannot shadow the proxy's; conflicts -> absent. - Constructor rejects bare-string proxy_list/precedence, non-IP entries, bool/non-int proxy_count; copies caller lists. Non-mapping meta -> TypeError. - RFC 7239 Forwarded parsing is quote-aware (no smuggled hops). - Tiers: 0.0.0.0/8 rejected; fec0::/10 and 64:ff9b:1::/48 private. - Remove dead is_valid_ip. - Tests: new tests_modern_config.py, wider matrix configs (IPv6, two-hop, count/list mismatch); 100% line+branch coverage of modern engine.
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.
These are the fixes from a deep review of the modern engine. PR #29 was merged before they were pushed, so this is a fresh branch off
main.Security
proxy_list=["1.2.3.4"]also trusted1.2.3.45, and that host could forge the client IP. Prefixes now match only on whole octets or groups:"10.1"matches10.1.x.xbut not10.100.x.x. IPv6 entries ignore case and leading zeros. An entry ending in:still works as a prefix, as it did in 4.0.0.x_forwarded_forcan no longer shadow the proxy'sx-forwarded-for. Previously the result depended on dict order, even with a trusted proxy configured. If two dash spellings disagree, the header is treated as absent.Forwardedparsing. A,or;inside a quoted value no longer splits a hop, soext="x,8.8.8.8"can't add a fake address or a fake proxy hop.Correctness
ValueErrorwhen the object is created:proxy_listorprecedencepassed as a bare string. Previously each character became an entry.proxy_listentry that isn't an IP, such as"foo".proxy_countthat is a bool, float or string.precedenceandproxy_listare copied, so later changes to those lists have no effect.metathat isn't a mapping raisesTypeError. Non-string keys are skipped.0.0.0.0/8is never returned.fec0::/10(site-local) ranks as private; Python reports it as global.64:ff9b:1::/48(local-use NAT64) ranks as private; Python reports it as reserved.is_valid_iphelper is removed. It was never exported.proxy_countandproxy_listcan still be set together and can differ, as in v3: the list sets the client position, and the count is a hop requirement. This is now documented and tested.Tests
tests/tests_modern_config.pycovers config validation, every matcher form, count/list interplay, meta handling, Forwarded quoting and the new address classes.is_global, and quote-blind splitting.Verified locally
ruff check .is clean.No tag has been pushed, so nothing is published.
🚀 Generated with Dojo ⛩️