diff --git a/web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java b/web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java index c26b27daf6c..8375846aeb7 100644 --- a/web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java +++ b/web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -64,6 +64,9 @@ * Rejects URLs that contain a backslash. See {@link #setAllowBackSlash(boolean)} * *
+ * Determines if a null "\0" or a URL encoded nul "%00" should be allowed in + * the path or not. The default is not to allow this behavior because it is a frequent + * source of security exploits. + *
+ * + * @param allowNull a null "\0" or a URL encoded null "%00" be allowed + * in the path or not. Default is false + * @since 5.4 + */ + public void setAllowNull(boolean allowNull) { + if (allowNull) { + urlBlocklistsRemoveAll(FORBIDDEN_NULL); + } else { + urlBlocklistsAddAll(FORBIDDEN_NULL); + } + } + /** ** Determines if a percent "%" that is URL encoded "%25" should be allowed in the path diff --git a/web/src/test/java/org/springframework/security/web/firewall/StrictHttpFirewallTests.java b/web/src/test/java/org/springframework/security/web/firewall/StrictHttpFirewallTests.java index 3de4acc59ea..89971b8355b 100644 --- a/web/src/test/java/org/springframework/security/web/firewall/StrictHttpFirewallTests.java +++ b/web/src/test/java/org/springframework/security/web/firewall/StrictHttpFirewallTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -377,6 +377,18 @@ public void getFirewalledRequestWhenExceedsUpperboundAsciiThenException() { this.firewall.getFirewalledRequest(this.request); } + @Test(expected = RequestRejectedException.class) + public void getFirewalledRequestWhenContainsNullThenException() { + this.request.setRequestURI("/\0"); + this.firewall.getFirewalledRequest(this.request); + } + + @Test(expected = RequestRejectedException.class) + public void getFirewalledRequestWhenContainsEncodedNullThenException() { + this.request.setRequestURI("/something%00/"); + this.firewall.getFirewalledRequest(this.request); + } + // --- from DefaultHttpFirewallTests --- /**