Conversation
IpInetAddressMatcher#matches(InetAddress) compared the byte arrays of the two addresses without first checking that they are the same length. When the configured CIDR mask required more full bytes than the shorter of the two addresses had (for example an IPv6 /64 matcher checked against an IPv4 address), and the leading bytes happened to be equal up to the shorter array's length, the comparison loop indexed past the end of the shorter array and threw ArrayIndexOutOfBoundsException instead of returning false, as documented on IpAddressMatcher. Closes spring-projectsgh-19733 Signed-off-by: minwoo-3 <s26002@gsm.hs.kr>
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.
Fixes #19733
IpInetAddressMatcher#matches(InetAddress)(backingIpAddressMatcher/InetAddressMatchers, added in 7.1) compares the byte arrays of theconfigured address and the address being checked without first verifying
they're the same length.
The class-level Javadoc on
IpAddressMatcherdocuments:When the configured CIDR mask requires more full bytes than the shorter of
the two addresses has (e.g. an IPv6
/64matcher checked against an IPv4address), and the leading bytes happen to be equal up to the shorter
array's length, the comparison loop indexes past the end of the shorter
array and throws
ArrayIndexOutOfBoundsExceptioninstead of returningfalseas documented.Repro (see #19733 for the full write-up):
This PR adds a length check that returns
falseimmediately when the twoaddresses are different lengths (different families), matching the
documented contract, plus two regression tests covering both directions
(IPv6-configured matcher checked against IPv4, and vice versa).
Ran
./gradlew formatand:spring-security-core:checklocally; bothpass, along with the full
IpInetAddressMatcherTestssuite.