This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new cf1f1897f1c7 chore: camel-http - a & or + in an option of a rest
producer is not sent as a query parameter (#31087)
cf1f1897f1c7 is described below
commit cf1f1897f1c7daf0613ea55a1d35c945f878d9a9
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 30 13:49:20 2026 +0100
chore: camel-http - a & or + in an option of a rest producer is not sent as
a query parameter (#31087)
Since CAMEL-27234 the rest producer factory of camel-http writes the options
of the producer (such as the login options of a rest-openapi endpoint) into
the http endpoint uri. They were percent-encoded, and normalizing the uri
decodes them, so a password such as p&ss+word was split into the option
authPassword and an unknown option ss+word, which the producer sent as a
query parameter. The values are now written as RAW(...) values, or RAW{...}
when the value has a )&. The endpoint still gets them from the parameters,
so only the uri changes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/component/http/HttpComponent.java | 25 +++++++++++++-
.../http/HttpRestProducerParametersTest.java | 39 +++++++++++++++++++++-
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index c2d02f6d3f77..87e090228b2d 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -812,7 +812,7 @@ public class HttpComponent extends HttpCommonComponent
implements RestProducerFa
// instead of all of them using the endpoint (and the login) of the
first producer created for the same url
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
if (isUriValue(entry.getValue())) {
- map.put(entry.getKey(), entry.getValue());
+ map.put(entry.getKey(), asUriValue(entry.getValue()));
}
}
@@ -849,6 +849,29 @@ public class HttpComponent extends HttpCommonComponent
implements RestProducerFa
|| value instanceof Character || value instanceof Enum<?>;
}
+ /**
+ * The value as written in the endpoint uri. Text is written as a RAW
value, as a percent-encoded value is decoded
+ * when the uri is normalized: an & or + in a password would then split
the option into another option, which the
+ * producer sends as a query parameter. The endpoint still gets the value
as given, as the parameters take
+ * precedence over the uri.
+ */
+ private static Object asUriValue(Object value) {
+ if (!(value instanceof CharSequence) && !(value instanceof Character))
{
+ return value;
+ }
+ String text = value.toString();
+ for (char start : URISupport.RAW_TOKEN_START) {
+ if (text.startsWith(URISupport.RAW_TOKEN_PREFIX + start)) {
+ return text;
+ }
+ }
+ // a RAW value ends at the first closing bracket followed by &, so use
RAW{...} when the value has a )&.
+ // A value with both a )& and a }& cannot be written as RAW: its uri
is split, and the producer sends the
+ // rest of the value as a query parameter (the endpoint still gets the
value from the parameters)
+ int kind = text.contains(URISupport.RAW_TOKEN_END[0] + "&") ? 1 : 0;
+ return URISupport.RAW_TOKEN_PREFIX + URISupport.RAW_TOKEN_START[kind]
+ text + URISupport.RAW_TOKEN_END[kind];
+ }
+
public HttpClientConfigurer getHttpClientConfigurer() {
return httpClientConfigurer;
}
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpRestProducerParametersTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpRestProducerParametersTest.java
index 765aadba35af..ac45e70c9900 100644
---
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpRestProducerParametersTest.java
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpRestProducerParametersTest.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.http;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@@ -37,11 +39,13 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* The producers that rest components (such as rest-openapi) create for the
same url, each with its own options, do not
- * share one endpoint: each producer uses its own login (CAMEL-27234).
+ * share one endpoint: each producer uses its own login (CAMEL-27234), and no
part of an option value (such as a & in a
+ * password) is sent as a query parameter.
*/
public class HttpRestProducerParametersTest {
private final AtomicReference<String> authorization = new
AtomicReference<>();
+ private final AtomicReference<String> query = new AtomicReference<>();
private HttpServer server;
private DefaultCamelContext context;
@@ -75,6 +79,37 @@ public class HttpRestProducerParametersTest {
assertThat(send(bearer)).isEqualTo("Bearer TOKEN");
}
+ @Test
+ public void shouldNotSendPartOfThePasswordAsQueryParameter() throws
Exception {
+ Producer basic = createProducer(Map.of("authMethod", "Basic",
"authUsername", "ann", "authPassword", "p&ss+word",
+ "authenticationPreemptive", "true"));
+
+ assertThat(send(basic)).isEqualTo(basic("ann", "p&ss+word"));
+ assertThat(query.get()).isNull();
+ }
+
+ @Test
+ public void shouldNotSendPartOfThePasswordWithBracketsAsQueryParameter()
throws Exception {
+ Producer basic = createProducer(Map.of("authMethod", "Basic",
"authUsername", "ann", "authPassword", "p)&s{s}+(w%26rd",
+ "authenticationPreemptive", "true"));
+
+ assertThat(send(basic)).isEqualTo(basic("ann", "p)&s{s}+(w%26rd"));
+ assertThat(query.get()).isNull();
+ }
+
+ @Test
+ public void
shouldNotSendPartOfThePasswordWithClosingBracketsAsQueryParameter() throws
Exception {
+ Producer basic = createProducer(Map.of("authMethod", "Basic",
"authUsername", "ann", "authPassword", "p}&ss)w+rd)",
+ "authenticationPreemptive", "true"));
+
+ assertThat(send(basic)).isEqualTo(basic("ann", "p}&ss)w+rd)"));
+ assertThat(query.get()).isNull();
+ }
+
+ private static String basic(String user, String password) {
+ return "Basic " + Base64.getEncoder().encodeToString((user + ":" +
password).getBytes(StandardCharsets.UTF_8));
+ }
+
private Producer createProducer(Map<String, Object> parameters) throws
Exception {
HttpComponent http = context.getComponent("http", HttpComponent.class);
Producer producer = http.createProducer(context, "http://localhost:" +
server.getAddress().getPort(), "GET", "api",
@@ -85,6 +120,7 @@ public class HttpRestProducerParametersTest {
private String send(Producer producer) throws Exception {
authorization.set(null);
+ query.set(null);
Exchange exchange = new DefaultExchange(context);
producer.process(exchange);
assertThat(exchange.getException()).isNull();
@@ -94,6 +130,7 @@ public class HttpRestProducerParametersTest {
private void handle(HttpExchange exchange) throws IOException {
authorization.set(exchange.getRequestHeaders().getFirst("Authorization"));
+ query.set(exchange.getRequestURI().getRawQuery());
exchange.sendResponseHeaders(200, -1);
exchange.close();
}