Exclude null and wildcard from external matching - #19494
Open
ryandiginomad wants to merge 1 commit into
Open
Conversation
ExternalInetAddressMatcher negates InternalInetAddressMatcher, which returns false for a null address and for the wildcard addresses 0.0.0.0 and ::. Negating that classified all three as external, even though none of them identifies a host that a request could originate from. Return false for those cases before delegating to the internal matcher, and document the behavior on matchExternal. Closes spring-projectsgh-19072 Signed-off-by: Ryan Tang <24728770+ryandiginomad@users.noreply.github.com>
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.
ExternalInetAddressMatcheris defined as!InternalInetAddressMatcher, and the internal matcher returnsfalsefor anulladdress and for the wildcard addresses0.0.0.0and::— they are neither loopback, link-local, site-local, nor ULA, so they fall through to the finalreturn false. Negating that classified all three as external, which is what gh-19072 reports.This returns
falsefor those cases before delegating, so they now match neithermatchExternal()normatchInternal(). That asymmetry looks deliberate to me: none of the three identifies a host a request could originate from, so neither classification is meaningful — but if you would rather the wildcard addresses count as internal, that is a one-line change instead.InetAddress.isAnyLocalAddress()covers both wildcard forms. I checked the IPv4-mapped spelling too, since it is the easy one to miss:The JDK folds
::ffff:0.0.0.0into anInet4Address, so it is covered by the same check, and loopback/public addresses are untouched.Closes gh-19072
Testing
Three tests added to
ExternalInetAddressMatcherTests, following the surrounding naming convention and@ValueSourcestyle: one formatches((InetAddress) null)and a parameterized one for0.0.0.0and::. I confirmed all three fail onmainbefore the change and pass after it../gradlew :spring-security-core:checkis green — 1507 tests across 185 classes, 0 failures, checkstyle clean. I ran it with-PtestToolchain=21because I do not have JDK 25 locally;options.releaseis 17 regardless.matchExternalandExternalInetAddressMatcherhave no other callers in the repository, so the change is contained to this API.🤖 AI assistance
Developed with Claude Code. I reviewed every line of this diff, and the verification above reflects test runs I actually performed and observed.