This is an automated email from the ASF dual-hosted git repository. Croway pushed a commit to branch camel-4.18.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 37188f807e034c736c3788e766b722063748bdb9 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Aug 31 10:23:27 2026 +0200 CAMEL-24455: camel-platform-http - select proxy mode by the exact path, not by prefix (#25833) isHttpProxy() tested path.startsWith(PROXY_PATH), so any endpoint whose path merely began with "proxy" - proxyStats, proxy-health, proxying - was treated as the documented platform-http:proxy endpoint. That is not only a naming curiosity: getPath() returns "/" for such an endpoint, making it a catch-all, and VertxPlatformHttpConsumer.handleProxy() sets Exchange.HTTP_HOST from the request's own Host header so a bridging producer forwards there. A route author naming an endpoint proxyStats got a catch-all whose forward target came from the caller. Compare for equality. The check is deliberately strict rather than tolerating a leading slash: platform-http:/proxy did not select proxy mode before and still does not, so tightening this can never turn an endpoint into a proxy that was not already one. The test asserts that, so the check is not loosened later by mistake. Every platform-http:proxy usage in the tree - the component docs, PlatformHttpProxyTest, VertxPlatformHttpProxyTest, VertxPlatformHttpsProxyTest - already uses the exact path. Signed-off-by: Andrea Cosentino <[email protected]> (cherry picked from commit 7abf13b2b314f40b8e76af3ba655266b57ff5e20) Co-authored-by: Claude Opus 5 (1M context) <[email protected]> --- .../platform/http/PlatformHttpEndpoint.java | 10 +++- .../http/PlatformHttpEndpointProxyPathTest.java | 65 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java index c2b729e1eaab..9421f582a1a7 100644 --- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java +++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java @@ -301,8 +301,16 @@ public class PlatformHttpEndpoint extends DefaultEndpoint : getComponent().getOrCreateEngine(); } + /** + * Whether this endpoint is the documented {@code platform-http:proxy} endpoint. + * <p> + * Compared for equality rather than as a prefix. Proxy mode makes {@link #getPath()} return {@code "/"}, turning + * the endpoint into a catch-all, and the consumer then takes the forward target from the request's own {@code Host} + * header - so a path that merely begins with "proxy", such as {@code proxyStats}, would become a forwarding proxy + * its author never asked for. + */ public boolean isHttpProxy() { - return this.path.startsWith(PROXY_PATH); + return PROXY_PATH.equals(this.path); } public boolean isReturnHttpRequestHeaders() { diff --git a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpEndpointProxyPathTest.java b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpEndpointProxyPathTest.java new file mode 100644 index 000000000000..5d2e4b39d526 --- /dev/null +++ b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpEndpointProxyPathTest.java @@ -0,0 +1,65 @@ +/* + * 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.platform.http; + +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Proxy mode makes the endpoint a catch-all whose forward target comes from the request's own Host header. Selecting it + * by prefix meant any path merely beginning with "proxy" became a forwarding proxy its author never asked for. + */ +class PlatformHttpEndpointProxyPathTest { + + @Test + void onlyTheProxyPathSelectsProxyMode() throws Exception { + assertTrue(isProxy("platform-http:proxy")); + + // a leading slash did not select proxy mode before the check was tightened, and still does not: + // narrowing the check must never turn an endpoint into a proxy that was not already one + assertFalse(isProxy("platform-http:/proxy")); + + assertFalse(isProxy("platform-http:proxyStats")); + assertFalse(isProxy("platform-http:proxy-health")); + assertFalse(isProxy("platform-http:proxying")); + assertFalse(isProxy("platform-http:/orders")); + } + + @Test + void aNonProxyPathIsNotTurnedIntoACatchAll() throws Exception { + try (DefaultCamelContext context = new DefaultCamelContext()) { + context.start(); + PlatformHttpComponent component = new PlatformHttpComponent(context); + PlatformHttpEndpoint endpoint + = (PlatformHttpEndpoint) component.createEndpoint("platform-http:proxyStats"); + + assertEquals("proxyStats", endpoint.getPath()); + } + } + + private static boolean isProxy(String uri) throws Exception { + try (DefaultCamelContext context = new DefaultCamelContext()) { + context.start(); + PlatformHttpComponent component = new PlatformHttpComponent(context); + return ((PlatformHttpEndpoint) component.createEndpoint(uri)).isHttpProxy(); + } + } +}
