oscerd commented on code in PR #27944:
URL: https://github.com/apache/camel/pull/27944#discussion_r4306637913


##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerEncodedUriTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 rejectsNarrowingCharacterInQuery() {
+        // U+010A is above 0xFF; the client would narrow it to the single byte 
0x0A (LF). It is refused before that.
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader(Exchange.HTTP_QUERY, "q=Ċ"));
+        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 rejectsCrlfInPreservedHostHeader() {
+        // with preserveHostHeader the caller's Host header is written 
verbatim, so it is validated too
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo?preserveHostHeader=true";,
+                e -> e.getIn().setHeader("Host", "localhost\r\nX-Injected: 
1"));
+        assertRejected(out, "Host header");
+    }
+
+    @Test
+    void sendsAnOrdinaryQuery() {

Review Comment:
   Added `sendsAHeaderWithTabAndLatin1` in 7640e02 — it sends `MyHeader: 
café<TAB>au lait` (a Latin-1/obs-text character, a tab and a space) and asserts 
the exchange is not failed, confirming those are not refused. So the allowed 
set is: everything except control characters, `DEL`, and characters above 
`0xFF`; `SP` and `HTAB` pass. Thanks.
   
   _Claude Code on behalf of oscerd_



-- 
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