This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24298-siblings in repository https://gitbox.apache.org/repos/asf/camel.git
commit 72f7b9c8c7edf49a5613f94e244a33ae0a5ab680 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Aug 6 14:00:55 2026 +0200 CAMEL-24298: Address review feedback - Fix copy constructors in RecipientListDefinition and RoutingSlipDefinition to copy the allowedSchemes field (would be lost during AdviceWith / route template instantiation). - Add positive test verifying an allowed scheme passes through. - Make allowedSchemes a hard boundary: move the check before the ignoreInvalidEndpoints catch in RecipientListProcessor and PollEnricher so a disallowed scheme always fails regardless of ignoreInvalidEndpoints. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../java/org/apache/camel/model/RecipientListDefinition.java | 1 + .../java/org/apache/camel/model/RoutingSlipDefinition.java | 1 + .../main/java/org/apache/camel/processor/PollEnricher.java | 11 +++++++++-- .../org/apache/camel/processor/RecipientListProcessor.java | 6 +++--- .../camel/processor/DynamicUriEipAllowedSchemesTest.java | 12 ++++++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RecipientListDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RecipientListDefinition.java index 02b3201f83cc..e1a4e72d94ff 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/RecipientListDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RecipientListDefinition.java @@ -140,6 +140,7 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext this.onPrepare = source.onPrepare; this.cacheSize = source.cacheSize; this.shareUnitOfWork = source.shareUnitOfWork; + this.allowedSchemes = source.allowedSchemes; } public RecipientListDefinition(ExpressionDefinition expression) { diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java index 7f9b41b17031..d0676b567f01 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java @@ -75,6 +75,7 @@ public class RoutingSlipDefinition<Type extends ProcessorDefinition<Type>> exten this.uriDelimiter = source.uriDelimiter; this.ignoreInvalidEndpoints = source.ignoreInvalidEndpoints; this.cacheSize = source.cacheSize; + this.allowedSchemes = source.allowedSchemes; } public RoutingSlipDefinition(String headerName) { diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java index 3b007c702ab6..debcbcfb9742 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java @@ -303,8 +303,15 @@ public class PollEnricher extends BaseProcessorSupport implements IdAware, Route } Object targetRecipient = staticUri != null ? staticUri : recipient; targetRecipient = prepareRecipient(exchange, targetRecipient); - // enforce the optional allowed-schemes allow-list on the resolved dynamic recipient (CAMEL-24298) - ProcessorHelper.checkAllowedSchemes(allowedSchemes, targetRecipient); + // enforce the optional allowed-schemes allow-list; must throw before the ignoreInvalidEndpoint + // catch so that a disallowed scheme is always a hard boundary (CAMEL-24298) + try { + ProcessorHelper.checkAllowedSchemes(allowedSchemes, targetRecipient); + } catch (ResolveEndpointFailedException e) { + exchange.setException(e); + callback.done(true); + return true; + } if (targetRecipient == null) { if (LOG.isDebugEnabled()) { LOG.debug("Poll dynamic evaluated as null so cannot poll from any endpoint"); diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java index 4c4f1b253562..52afcf27ca18 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java @@ -257,10 +257,10 @@ public class RecipientListProcessor extends MulticastProcessor { Endpoint endpoint; Producer producer; ExchangePattern pattern; + recipient = prepareRecipient(exchange, recipient); + // enforce the optional allowed-schemes allow-list before the ignoreInvalidEndpoints catch (CAMEL-24298) + ProcessorHelper.checkAllowedSchemes(allowedSchemes, recipient); try { - recipient = prepareRecipient(exchange, recipient); - // enforce the optional allowed-schemes allow-list on the resolved dynamic recipient (CAMEL-24298) - ProcessorHelper.checkAllowedSchemes(allowedSchemes, recipient); Endpoint existing = getExistingEndpoint(exchange, recipient); if (existing == null) { endpoint = resolveEndpoint(exchange, recipient, prototype); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/DynamicUriEipAllowedSchemesTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/DynamicUriEipAllowedSchemesTest.java index e366377204bd..f9906ad016fa 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/DynamicUriEipAllowedSchemesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/DynamicUriEipAllowedSchemesTest.java @@ -22,6 +22,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Header; import org.apache.camel.ResolveEndpointFailedException; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -33,6 +34,16 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; */ class DynamicUriEipAllowedSchemesTest extends ContextTestSupport { + @Test + void recipientListAllowsMatchingScheme() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Hello"); + + template.sendBodyAndHeader("direct:rl-ok", "Hello", "target", "mock:result"); + + mock.assertIsSatisfied(); + } + @Test void recipientListRejectsDisallowedScheme() { assertRejected("direct:rl"); @@ -78,6 +89,7 @@ class DynamicUriEipAllowedSchemesTest extends ContextTestSupport { return new RouteBuilder() { @Override public void configure() { + from("direct:rl-ok").recipientList(header("target")).allowedSchemes("mock"); from("direct:rl").recipientList(header("target")).allowedSchemes("mock"); from("direct:rs").routingSlip(header("target")).allowedSchemes("mock"); from("direct:dr").dynamicRouter(method(DynamicUriEipAllowedSchemesTest.this, "slip")).allowedSchemes("mock");
