gnodet-bot commented on code in PR #27944:
URL: https://github.com/apache/camel/pull/27944#discussion_r4294033516


##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerEncodedUriTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.undertow;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The undertow producer must not write a request path, query or header value 
that it cannot put on the wire as it is: a
+ * percent-encoded CR/LF in {@code CamelHttpPath} or {@code CamelHttpQuery}, 
or a CR/LF in a header value, is refused
+ * rather than written into the request line or a header line. An ordinary 
query is still sent.
+ */
+class UndertowProducerEncodedUriTest extends BaseUndertowTest {
+
+    @Test
+    void rejectsEncodedCrlfInQuery() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader(Exchange.HTTP_QUERY, 
"q=x%0D%0AX-Injected:%201"));
+        assertRejected(out, "request target");
+    }
+
+    @Test
+    void rejectsEncodedCrlfInPath() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader(Exchange.HTTP_PATH, "a%0D%0Ab"));
+        assertRejected(out, "request target");
+    }
+
+    @Test
+    void rejectsHeaderValueWithCrlf() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader("MyHeader", "value\r\nX-Injected: 
1"));
+        assertRejected(out, "HTTP header");
+    }
+
+    @Test
+    void sendsAnOrdinaryQuery() {
+        String out = 
template.requestBodyAndHeader("undertow:http://localhost:{{port}}/echo";,
+                null, Exchange.HTTP_QUERY, "q=hello", String.class);
+        assertEquals("q=hello", out);
+    }

Review Comment:
   ⚠️ **Missing coverage for `ch > 0xFF` narrowing attack vector**
   
   The `ch > 0xFF` branch in `checkWriteable` (the guard for `U+010A → LF` 
narrowing highlighted in the PR description) has no test. Consider adding a 
test before `sendsAnOrdinaryQuery`:
   
   ```suggestion
       @Test
       void rejectsNarrowingCharacterInQuery() {
           // U+010A narrows to LF (0x0A) when written as a byte — must be 
refused
           Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
                   e -> e.getIn().setHeader(Exchange.HTTP_QUERY, "q=\u010A"));
           assertRejected(out, "request target");
       }
   
       @Test
       void sendsAnOrdinaryQuery() {
           String out = 
template.requestBodyAndHeader("undertow:http://localhost:{{port}}/echo";,
                   null, Exchange.HTTP_QUERY, "q=hello", String.class);
           assertEquals("q=hello", out);
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to