Repository navigation
Conversation
c484f32 to
5494944
Compare
| for index in range(len(forwarded_ips) - 1, -1, -1): | ||
| ip = normalize_ip(forwarded_ips[index].strip()) | ||
| if not is_ip(ip): | ||
| continue | ||
| normalized_ip = preparse(ip) | ||
| if is_private_ip(normalized_ip): | ||
| continue | ||
| if isinstance(config, CIDRTrustProxy) and config.matcher.has(normalized_ip): | ||
| continue | ||
| return ip | ||
| return None |
There was a problem hiding this comment.
🟡 Medium - CIDR proxy mode skips a private client and accepts the spoofed XFF prefix
When a request comes through a configured CIDR-trusted proxy and the actual client address is private, the selector skips both the trusted proxy and the private client, then continues into the client-controlled left side of X-Forwarded-For. A client can therefore vary that prefix to control the IP used for per-IP rate limits and IP firewall decisions instead of being bound to the private client address.
Show fix
| for index in range(len(forwarded_ips) - 1, -1, -1): | |
| ip = normalize_ip(forwarded_ips[index].strip()) | |
| if not is_ip(ip): | |
| continue | |
| normalized_ip = preparse(ip) | |
| if is_private_ip(normalized_ip): | |
| continue | |
| if isinstance(config, CIDRTrustProxy) and config.matcher.has(normalized_ip): | |
| continue | |
| return ip | |
| return None | |
| for index in range(len(forwarded_ips) - 1, -1, -1): | |
| ip = normalize_ip(forwarded_ips[index].strip()) | |
| if not is_ip(ip): | |
| if isinstance(config, CIDRTrustProxy): | |
| return None | |
| continue | |
| normalized_ip = preparse(ip) | |
| if isinstance(config, CIDRTrustProxy): | |
| if config.matcher.has(normalized_ip): | |
| continue | |
| return ip | |
| if is_private_ip(normalized_ip): | |
| continue | |
| return ip | |
| return None |
More info - Reply on this comment to give feedback or ignore the issue.
There was a problem hiding this comment.
Keeping this as is because private addresses count as part of the proxy chain, so unlisted internal hops are skipped. For clients on a private network, the hop-count mode applies.
There was a problem hiding this comment.
Partially fixed in commit 8d6eed5.
This issue remains because aikido_zen/helpers/get_ip_from_request.py:50-58 still skips every private address before applying the CIDR matcher, so an XFF sequence containing a trusted proxy, private client, and attacker-controlled public prefix still returns that prefix; the WSGI ProxyFix bypass only removes this path for that specific integration.
There was a problem hiding this comment.
Partially fixed in commit b519e4c.
This issue remains because get_client_ip_from_header at aikido_zen/helpers/get_ip_from_request.py:52 unconditionally continues past private addresses before the CIDR boundary check, so a private client is skipped and a public spoofed XFF entry to its left can still be selected.
5494944 to
9bbfbc8
Compare
As without ProxyFix, and as the spec's fallback rule says, use the connection address when the address ProxyFix chose is not an IP. Narrow the docs sentence to the X-Forwarded-For case.
The UTF-8 reading of a non-ASCII line is still scanned, but it no longer shifts the hop count. The selector only returns valid IPs, so the caller does not check them again.
Zen reads the client IP before a ProxyFix inside app.wsgi_app runs, so AIKIDO_TRUST_PROXY must equal x_for for both to select the same client.
With proxy trust on, Zen applies its setting to the connection address that ProxyFix keeps. With it off, Zen uses the address the app sees, as .NET does. This replaces the special cases for the address ProxyFix chose.
No description provided.