Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.security.util.matcher;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -70,25 +69,14 @@ final class IpInetAddressMatcher implements InetAddressMatcher {
.format("IP address %s is too short for bitmask of length %d", requiredAddress, this.nMaskBits));
}

private static InetAddress parse(String address) {

@winfriedgerlach winfriedgerlach Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was unused residue from the earlier refactoring

try {
InetAddress result = InetAddress.getByName(address);
if (address.matches(".*[a-zA-Z\\-].*$") && !address.contains(":")) {
logger.warn("Hostname '" + address + "' resolved to " + result.toString()
+ " will be used on IP address matching");
}
return result;
}
catch (UnknownHostException ex) {
throw new IllegalArgumentException(String.format("Failed to parse address '%s'", address), ex);
}
}

@Override
public boolean matches(@Nullable InetAddress toCheck) {
if (toCheck == null) {
return false;
}
if (!this.requiredAddress.getClass().equals(toCheck.getClass())) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check was present before 7.1.0, I am just re-introducing it

return false;
}
if (this.nMaskBits < 0) {
return toCheck.equals(this.requiredAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ void matchesWhenIpv4AndIpv6AddressThenReturnsFalse() throws Exception {
assertThat(matcher.matches(InetAddress.getByName("fe80::21f:5bff:fe33:bd68"))).isFalse();
}

// regression test for #19329 "ArrayIndexOutOfBoundsException using IpAddressMatcher"
// this test failed with ArrayIndexOutOfBoundsException in Spring Security 7.1.0
@Test
void matchesWhenIpv4AndIpv6AddressThenFailFast() throws Exception {
IpInetAddressMatcher matcher = new IpInetAddressMatcher("::1/128");
assertThat(matcher.matches(InetAddress.getByName("0.0.0.0"))).isFalse();
}

@Test
void matchesWhenIpv6AndIpv4AddressThenReturnsFalse() throws Exception {
IpInetAddressMatcher matcher = new IpInetAddressMatcher("fe80::21f:5bff:fe33:bd68");
Expand Down