Repository navigation
Reject host names in SubnetUtils6 instead of resolving them via DNS - #417
Open
Sahana2524 wants to merge 1 commit into
Open
Sahana2524 wants to merge 1 commit into
Sahana2524 wants to merge 1 commit into
Conversation
SubnetUtils6 parsed its input with InetAddress.getByName(), which resolves anything that is not an IP literal through DNS. A host name with an AAAA record inside the subnet made SubnetInfo.isInRange(String) return true, and each call could trigger a lookup of a caller-supplied name. Only accept strings shaped like an IPv6 literal, as SubnetUtils does for IPv4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SubnetUtils6turns its string input into bytes withInetAddress.getByName(), which falls back to a DNS lookup for anything that is not an IP literal.SubnetInfo.isInRange(String)and theSubnetUtils6(String)constructors are documented to take an IPv6 address, but today they also accept host names:new SubnetUtils6("2001:db8::/32").getInfo().isInRange("attacker.example")returnstruewhen that name has an AAAA record in2001:db8::/32. If an application checks a client-supplied value against an allowlist (for example a forwarded-for header), sending a name the client controls passes the check.""is mapped to the loopback address.The IPv4
SubnetUtilsalready parses with a regex and never resolves names, so this bringsSubnetUtils6in line with it. The new check only lets through strings shaped like an IPv6 literal (hex digits and a colon first, optional brackets and%scope). For those,getByName()always parses the literal and never does a lookup. Bracketed and scoped literals keep working.Repro (JDK 18+ resolver SPI mapping
attacker.exampleto2001:db8::5), before and after:About the test:
testHostNameIsNotResolvedalways passes with the fix because no lookup happens. Without the fix it fails only where one of the names resolves to IPv6. That happens withip6-localhoston typical Linux hosts, or with-DargLine=-Djava.net.preferIPv6Addresses=true, which is how I confirmed it locally. This touches the sametoBytes()helper as #412 (IPv4-mapped literals). The two changes are independent, and mapped literals like::ffff:192.0.2.1still match the new pattern.Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
Claude Code (Anthropic) found this issue and drafted the fix, the test and this description. I reviewed all of it before submitting.
mvn; that'smvnon the command line by itself.