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 11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222
2323import org .springframework .security .web .util .matcher .RequestMatcher ;
2424import org .springframework .util .StringUtils ;
25+ import org .springframework .util .Assert ;
2526
2627/**
2728 * Matches a request based on IP Address or subnet mask matching against the remote
@@ -55,6 +56,9 @@ public IpAddressMatcher(String ipAddress) {
5556 nMaskBits = -1 ;
5657 }
5758 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 ));
5862 }
5963
6064 public boolean matches (HttpServletRequest request ) {
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -84,4 +84,24 @@ public void zeroMaskMatchesAnything() throws Exception {
8484 assertThat (matcher .matches ("123.4.5.6" )).isTrue ();
8585 assertThat (matcher .matches ("192.168.0.159" )).isTrue ();
8686 }
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+ }
87107}
You can’t perform that action at this time.
0 commit comments