|
@@ -1,3 +1,18 @@
|
|
|
|
+/*
|
|
|
|
+ * Copyright 2002-2016 the original author or authors.
|
|
|
|
+ *
|
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
|
+ * You may obtain a copy of the License at
|
|
|
|
+ *
|
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
+ *
|
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
|
+ * limitations under the License.
|
|
|
|
+ */
|
|
package org.springframework.security.web.firewall;
|
|
package org.springframework.security.web.firewall;
|
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
import static org.junit.Assert.fail;
|
|
@@ -41,4 +56,59 @@ public class DefaultHttpFirewallTests {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * On WebSphere 8.5 a URL like /context-root/a/b;%2f1/c can bypass a rule on
|
|
|
|
+ * /a/b/c because the pathInfo is /a/b;/1/c which ends up being /a/b/1/c
|
|
|
|
+ * while Spring MVC will strip the ; content from requestURI before the path
|
|
|
|
+ * is URL decoded.
|
|
|
|
+ */
|
|
|
|
+ @Test(expected = RequestRejectedException.class)
|
|
|
|
+ public void getFirewalledRequestWhenLowercaseEncodedPathThenException() {
|
|
|
|
+ DefaultHttpFirewall fw = new DefaultHttpFirewall();
|
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
+ request.setRequestURI("/context-root/a/b;%2f1/c");
|
|
|
|
+ request.setContextPath("/context-root");
|
|
|
|
+ request.setServletPath("");
|
|
|
|
+ request.setPathInfo("/a/b;/1/c"); // URL decoded requestURI
|
|
|
|
+ fw.getFirewalledRequest(request);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test(expected = RequestRejectedException.class)
|
|
|
|
+ public void getFirewalledRequestWhenUppercaseEncodedPathThenException() {
|
|
|
|
+ DefaultHttpFirewall fw = new DefaultHttpFirewall();
|
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
+ request.setRequestURI("/context-root/a/b;%2F1/c");
|
|
|
|
+ request.setContextPath("/context-root");
|
|
|
|
+ request.setServletPath("");
|
|
|
|
+ request.setPathInfo("/a/b;/1/c"); // URL decoded requestURI
|
|
|
|
+
|
|
|
|
+ fw.getFirewalledRequest(request);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void getFirewalledRequestWhenAllowUrlEncodedSlashAndLowercaseEncodedPathThenNoException() {
|
|
|
|
+ DefaultHttpFirewall fw = new DefaultHttpFirewall();
|
|
|
|
+ fw.setAllowUrlEncodedSlash(true);
|
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
+ request.setRequestURI("/context-root/a/b;%2f1/c");
|
|
|
|
+ request.setContextPath("/context-root");
|
|
|
|
+ request.setServletPath("");
|
|
|
|
+ request.setPathInfo("/a/b;/1/c"); // URL decoded requestURI
|
|
|
|
+
|
|
|
|
+ fw.getFirewalledRequest(request);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void getFirewalledRequestWhenAllowUrlEncodedSlashAndUppercaseEncodedPathThenNoException() {
|
|
|
|
+ DefaultHttpFirewall fw = new DefaultHttpFirewall();
|
|
|
|
+ fw.setAllowUrlEncodedSlash(true);
|
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
+ request.setRequestURI("/context-root/a/b;%2F1/c");
|
|
|
|
+ request.setContextPath("/context-root");
|
|
|
|
+ request.setServletPath("");
|
|
|
|
+ request.setPathInfo("/a/b;/1/c"); // URL decoded requestURI
|
|
|
|
+
|
|
|
|
+ fw.getFirewalledRequest(request);
|
|
|
|
+ }
|
|
}
|
|
}
|