Repository navigation
Conversation
With trusted_proxy_hops set, the selected X-Forwarded-For entry became router.session.client_ip verbatim, so values with a port or that were not addresses at all were passed through. Normalize the entry with ipaddress.ip_address after dropping a port and IPv6 brackets, and fall back to the peer address (logging at debug level) when it is not a valid address. Fixes reflex-dev#7854
[Medium impact] This PR appears safe to merge; no actionable issues remain in the reviewed changes. SummaryThis PR makes
The earlier malformed-entry finding is fixed. No new actionable issues were found. Reviews (3) · Last reviewed commit: "fix: reject IPv6 zone indexes in X-Forwa..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Merging this PR will degrade performance by 5.9%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
That's a websocket client connecting straight to the backend. A zone only means something on the proxy's own host, so rejecting it should be safe: |
An unclosed bracket, text after the closing bracket or a non-numeric port now falls back to the peer address instead of being trimmed away. The log test only looks at the reflex.app debug records.
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
ipaddress keeps the text after % without validating it, so a client could still choose its own client_ip through it. A zone only means something on the proxy's own host, so such entries now fall back to the peer address.
|
Good catch, thanks. Fixed in 1b0af00: an entry with a |
Closes #7854
With
trusted_proxy_hopsset, the selectedX-Forwarded-Forentry becamerouter.session.client_ipas is, so203.0.113.7:51234,[2001:db8::1]:443or text that isn't an address at all ended up there._forwarded_client_ip()drops a numeric:portsuffix or IPv6 brackets and returnsstr(ipaddress.ip_address(...)), orNoneif the entry isn't an address. Malformed forms (an unclosed bracket, text after], a non-numeric or empty port) and IPv6 zone indexes (fe80::1%eth0, whichipaddresskeeps without validating) are rejected rather than trimmed. It's only used at theclient_ipsite;_trusted_forwarded_value()and theX-Forwarded-Host/X-Forwarded-Protohandling are unchanged._clip), since the value is client-controlled when a deployment is misconfigured.2001:DB8:0:0:0:0:0:1becomes2001:db8::1), and leading-zero IPv4 such as010.0.0.1falls back to the peer address, whichipaddressrejects.trusted_proxy_hopsdocs mention the normalisation, and the bugfix news fragment notes the change so otherclient_ipconsumers can follow.Tests: new cases in
test_static_router_data_resolves_client_ip_from_trusted_proxy_hops(port, bracketed IPv6 with and without port, expanded IPv6, a non-address entry, malformed brackets and ports, zone indexes) andtest_static_router_data_logs_ignored_forwarded_client_ip; 13 of them fail onmain.pytest tests/units/test_app.py tests/units/test_config.py: 500 passed; ruff check/format clean.All Submissions:
Type of change