[HttpClient] Fix checking for private IPs before connecting #59013
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 patch for CVE-2024-50342 isn't enough.
As reported by @cs278:
In addition:
As a first reminder, NoPrivateNetworkHttpClient DOES prevent requests to unwanted servers, but it doesn't prevent connecting to them, allowing to use timings to scan private network topologies.
As a second reminder, according to our security policy, we shouldn't have considered this as a security issue in the first place, but as a security hardening that could be handled without a CVE. Yet we did so we're going to update the already published CVE/advisory/blog post after this PR.
This patch rewrites
NoPrivateNetworkHttpClient
to make it responsible for resolving DNS and following redirections. I tried usingCURLOPT_RESOLVE
instead, but this setting is ignored during a curl transaction apparently so we have no other choices.In addition, the decorator will refuse to connect to IPv6/IPv4 hosts if the configured
$subnets
doesn't block any IPs for the corresponding version of the protocol.Because the DNS check is made earlier, the decorator now also rejects relative URLs when the base URI is unknown to it.