Skip to content

Commit 4d039e5

Browse files
committed
Merge branch '6.2.x'
2 parents 093b557 + 9c48546 commit 4d039e5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

web/src/main/java/org/springframework/security/web/firewall/StrictHttpFirewall.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -130,9 +130,13 @@ public class StrictHttpFirewall implements HttpFirewall {
130130
private static final Predicate<String> ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE = (
131131
s) -> ASSIGNED_AND_NOT_ISO_CONTROL_PATTERN.matcher(s).matches();
132132

133+
private static final Pattern HEADER_VALUE_PATTERN = Pattern.compile("[\\p{IsAssigned}&&[[^\\p{IsControl}]||\\t]]*");
134+
135+
private static final Predicate<String> HEADER_VALUE_PREDICATE = (s) -> HEADER_VALUE_PATTERN.matcher(s).matches();
136+
133137
private Predicate<String> allowedHeaderNames = ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE;
134138

135-
private Predicate<String> allowedHeaderValues = ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE;
139+
private Predicate<String> allowedHeaderValues = HEADER_VALUE_PREDICATE;
136140

137141
private Predicate<String> allowedParameterNames = ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE;
138142

web/src/test/java/org/springframework/security/web/firewall/StrictHttpFirewallTests.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -781,6 +781,13 @@ public void getFirewalledRequestGetHeaderWhenControlCharacterInHeaderValueThenEx
781781
assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getHeader("Something"));
782782
}
783783

784+
@Test
785+
public void getFirewalledRequestGetHeaderWhenHorizontalTabInHeaderValueThenNoException() {
786+
this.request.addHeader("Something", "tab\tvalue");
787+
HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
788+
assertThat(request.getHeader("Something")).isEqualTo("tab\tvalue");
789+
}
790+
784791
@Test
785792
public void getFirewalledRequestGetHeaderWhenUndefinedCharacterInHeaderValueThenException() {
786793
this.request.addHeader("Something", "bad\uFFFEvalue");

0 commit comments

Comments
 (0)