File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
main/java/org/springframework/security/web/util/matcher
test/java/org/springframework/security/web/util/matcher Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
22
22
23
23
import org .springframework .security .web .util .matcher .RequestMatcher ;
24
24
import org .springframework .util .StringUtils ;
25
+ import org .springframework .util .Assert ;
25
26
26
27
/**
27
28
* Matches a request based on IP Address or subnet mask matching against the remote
@@ -55,6 +56,9 @@ public IpAddressMatcher(String ipAddress) {
55
56
nMaskBits = -1 ;
56
57
}
57
58
requiredAddress = parseAddress (ipAddress );
59
+ Assert .isTrue (requiredAddress .getAddress ().length * 8 >= nMaskBits ,
60
+ String .format ("IP address %s is too short for bitmask of length %d" ,
61
+ ipAddress , nMaskBits ));
58
62
}
59
63
60
64
public boolean matches (HttpServletRequest request ) {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -84,4 +84,24 @@ public void zeroMaskMatchesAnything() throws Exception {
84
84
assertThat (matcher .matches ("123.4.5.6" )).isTrue ();
85
85
assertThat (matcher .matches ("192.168.0.159" )).isTrue ();
86
86
}
87
+
88
+ // SEC-2576
89
+ @ Test
90
+ public void ipv4RequiredAddressMaskTooLongThenIllegalArgumentException () {
91
+ String ipv4AddressWithTooLongMask = "192.168.1.104/33" ;
92
+ assertThatCode (() -> new IpAddressMatcher (ipv4AddressWithTooLongMask ))
93
+ .isInstanceOf (IllegalArgumentException .class )
94
+ .hasMessage (String .format ("IP address %s is too short for bitmask of " +
95
+ "length %d" , "192.168.1.104" , 33 ));
96
+ }
97
+
98
+ // SEC-2576
99
+ @ Test
100
+ public void ipv6RequiredAddressMaskTooLongThenIllegalArgumentException () {
101
+ String ipv6AddressWithTooLongMask = "fe80::21f:5bff:fe33:bd68/129" ;
102
+ assertThatCode (() -> new IpAddressMatcher (ipv6AddressWithTooLongMask ))
103
+ .isInstanceOf (IllegalArgumentException .class )
104
+ .hasMessage (String .format ("IP address %s is too short for bitmask of " +
105
+ "length %d" , "fe80::21f:5bff:fe33:bd68" , 129 ));
106
+ }
87
107
}
You can’t perform that action at this time.
0 commit comments