FIX: BUG: IPv6 CIDR notation in NO_PROXY variable or option - #19828
FIX: BUG: IPv6 CIDR notation in NO_PROXY variable or option#19828GenuaGSchulz wants to merge 3 commits into
Conversation
|
Nice catch! How about extending the unit test 1614 as well with some |
|
Hm, in fact. Maybe we should just drop supporting the bracketed version completely as that's not how the name is ever passed in to the function outside of the unit tests? Then we could just drop the brackets from the host names in the unit test too. |
|
I was thinking the same, but don't know the code as well to be sure that there is no case in which |
|
It is only called from a single spot in the source code so we know the brackets won't be there. |
|
Done. |
|
Thanks! |
|
No, thank you for maintaining this important piece of open-source software! |
The Bug
We noticed that using IPv6 CIDR-Notation in a NO_PROXY env var doesn't have the desired effect, contrary to what the documentation at https://everything.curl.dev/usingcurl/proxies/env.html explains.
How to reproduce:
curl -vv http://[::1]and observe that curl correctly tries to go through the proxy and fails to reach::1.::1by enteringNO_PROXY="::1/64" curl -vv http://[::1]. We now expect to not access the proxy and reach::1. We can observe that curl is still trying to go through the proxy, failing to reach::1.Debugging
I looked into the curl code and debugged a bit. An interesting find was that when using the above commands, the parameter
nameinCurl_check_noproxy()in lib/noproxy.c does not contain an address within brackets. Even if our target address ishttp://[::1], the value atnameis "::1". This is unexpected, sinceCurl_check_noproxy()specificly checksnamefor brackets and only then interprets it as IPv6 address. The unit tests for that function have brackets around their IPv6 address strings, so they work.The Fix
I didn't want to look further for how the brackets get removed in curl, because maybe there already is some other code now that relies on those brackets being removed. So my decision was to simply make
Curl_check_noproxy()robust against that case and accept IPv6 with or without brackets. The fix is rather simple, as you can see.By The Way
Non-CIDR IPv6 address strings (without /suffix) in the NO_PROXY env var just worked by accident, because for IPv6 addresses TYPE_HOST fell through in
Curl_check_noproxy(), resulting in a simple string comparison between two addresses.