mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 21:12:18 +00:00
Fix NPE in IpAddressMatcher
Closes gh-15527
This commit is contained in:
parent
6e495b8ba9
commit
52de894c3c
@ -71,6 +71,11 @@ public final class IpAddressMatcher implements RequestMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(String address) {
|
public boolean matches(String address) {
|
||||||
|
// Do not match null or blank address
|
||||||
|
if (!StringUtils.hasText(address)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
assertNotHostName(address);
|
assertNotHostName(address);
|
||||||
InetAddress remoteAddress = parseAddress(address);
|
InetAddress remoteAddress = parseAddress(address);
|
||||||
if (!this.requiredAddress.getClass().equals(remoteAddress.getClass())) {
|
if (!this.requiredAddress.getClass().equals(remoteAddress.getClass())) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -126,4 +126,17 @@ public class IpAddressMatcherTests {
|
|||||||
.withMessage("ipAddress 123.156.7.18.org doesn't look like an IP Address. Is it a host name?");
|
.withMessage("ipAddress 123.156.7.18.org doesn't look like an IP Address. Is it a host name?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-15527
|
||||||
|
@Test
|
||||||
|
public void matchesWhenIpAddressIsLoopbackAndAddressIsNullThenFalse() {
|
||||||
|
IpAddressMatcher ipAddressMatcher = new IpAddressMatcher("127.0.0.1");
|
||||||
|
assertThat(ipAddressMatcher.matches((String) null)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// gh-15527
|
||||||
|
@Test
|
||||||
|
public void matchesWhenAddressIsNullThenFalse() {
|
||||||
|
assertThat(this.v4matcher.matches((String) null)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user