CVE-2022-41915 (published 2022-12-13T07:15Z)

Netty project is an event-driven asynchronous network application framework. Starting in version 4.1.83.Final and prior to 4.1.86.Final, when calling `DefaultHttpHeadesr.set` with an _iterator_ of values, header value validation was not performed, allowing malicious header values in the iterator to perform HTTP Response Splitting. This issue has been patched in version 4.1.86.Final. Integrators can work around the issue by changing the `DefaultHttpHeaders.set(CharSequence, Iterator<?>)` call, into a `remove()` call, and call `add()` in a loop over the iterator of values.

CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-113
cwe_name: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Request/Response Splitting')
description: The product receives data from an HTTP agent/component (e.g., web server, proxy, browser, etc.), but it does not neutralize or incorrectly neutralizes CR and LF characters before the data is included in outgoing HTTP headers.
extended_description: 
	   
	     HTTP agents or components may include a web server, load balancer, reverse proxy, web caching proxy, application firewall, web browser, etc. Regardless of the role, they are expected to maintain coherent, consistent HTTP communication state across all components. However, including unexpected data in an HTTP header allows an attacker to specify the entirety of the HTTP message that is rendered by the client HTTP agent (e.g., web browser) or back-end HTTP agent (e.g., web server), whether the message is part of a request or a response.
	   
            When an HTTP request contains unexpected CR and LF characters, the server may respond with an output stream that is interpreted as "splitting" the stream into two different HTTP messages instead of one. CR is carriage return, also given by %0d or \r, and LF is line feed, also given by %0a or \n.
	    In addition to CR and LF characters, other valid/RFC compliant special characters and unique character encodings can be utilized, such as HT (horizontal tab, also given by %09 or \t) and SP (space, also given as + sign or %20).
	    These types of unvalidated and unexpected data in HTTP message headers allow an attacker to control the second "split" message to mount attacks such as server-side request forgery, cross-site scripting, and cache poisoning attacks.
            HTTP response splitting weaknesses may be present when:
               
                  Data enters a web application through an untrusted source, most frequently an HTTP request.
                  The data is included in an HTTP response header sent to a web user without neutralizing malicious characters that can be interpreted as separator characters for headers.
               
         
         
cwe_id: CWE-436
cwe_name: Interpretation Conflict
description: Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
extended_description: This is generally found in proxies, firewalls, anti-virus software, and other intermediary devices that monitor, allow, deny, or modify traffic based on how the client or server is expected to behave.
         

Fix information:
repo_url: https://github.com/netty/netty
commit_details: repo_url: https://github.com/netty/netty
author: Chris Vest
author_date: 2022-12-12 05:04:58-08:00
msg: Merge pull request from GHSA-hh82-3pmq-7frp

Motivation:
The setObject methods that took arrays and iterators as arguments provided a way to bypass value validation.

Modification:
Add the missing value validation checks.

Result:
It is no longer possibel to bypass value validation in DefaultHeaders based implementations, including DefaultHttpHeaders.
repository: repo_url: https://github.com/netty/netty
repo_name: netty/netty
description: Netty project - an event-driven asynchronous network application framework
repo_language: Java
owner: netty
file_changes: filename: DefaultHttpHeadersTest.java
change_type: ModificationType.MODIFY
diff: @@ -22,7 +22,7 @@ import io.netty.util.internal.StringUtil;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.function.Executable;
 
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -41,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class DefaultHttpHeadersTest {
     private static final CharSequence HEADER_NAME = "testHeader";
+    private static final CharSequence ILLEGAL_VALUE = "testHeader\r\nContent-Length:45\r\n\r\n";
 
     @Test
     public void nullHeaderNameNotAllowed() {
@@ -234,6 +235,28 @@ public class DefaultHttpHeadersTest {
         assertDefaultValues(headers, HeaderValue.THREE);
     }
 
+    @Test
+    public void setCharSequenceValidatesValue() {
+        final DefaultHttpHeaders headers = newDefaultDefaultHttpHeaders();
+        assertThrows(IllegalArgumentException.class, new Executable() {
+            @Override
+            public void execute() throws Throwable {
+                headers.set(HEADER_NAME, ILLEGAL_VALUE);
+            }
+        });
+    }
+
+    @Test
+    public void setIterableValidatesValue() {
+        final DefaultHttpHeaders headers = newDefaultDefaultHttpHeaders();
+        assertThrows(IllegalArgumentException.class, new Executable() {
+            @Override
+            public void execute() throws Throwable {
+                headers.set(HEADER_NAME, Collections.singleton(ILLEGAL_VALUE));
+            }
+        });
+    }
+
     @Test
     public void toStringOnEmptyHeaders() {
         assertEquals("DefaultHttpHeaders[]", newDefaultDefaultHttpHeaders().toString());

programming_language: Java
filename: DefaultHeaders.java
change_type: ModificationType.MODIFY
diff: @@ -532,7 +532,9 @@ public class DefaultHeaders<K, V, T extends Headers<K, V, T>> implements Headers
             if (v == null) {
                 break;
             }
-            add0(h, i, name, fromObject(name, v));
+            V converted = fromObject(name, v);
+            validateValue(valueValidator, name, converted);
+            add0(h, i, name, converted);
         }
 
         return thisT();
@@ -550,7 +552,9 @@ public class DefaultHeaders<K, V, T extends Headers<K, V, T>> implements Headers
             if (v == null) {
                 break;
             }
-            add0(h, i, name, fromObject(name, v));
+            V converted = fromObject(name, v);
+            validateValue(valueValidator, name, converted);
+            add0(h, i, name, converted);
         }
 
         return thisT();

programming_language: Java