FIX: BUG: IPv6 CIDR notation in NO_PROXY variable or option #19828
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.
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.