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 2d0cff86a956 CAMEL-27773: camel-alibaba-eventbridge - reject
CloudEvent extensions that reuse reserved attribute names (#31122)
2d0cff86a956 is described below
commit 2d0cff86a9562eaf9d2e36561c7b7a8765c42371
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Dec 1 13:36:14 2026 +0100
CAMEL-27773: camel-alibaba-eventbridge - reject CloudEvent extensions that
reuse reserved attribute names (#31122)
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
.../eventbridge/MapCloudEventValidator.java | 63 +++++++
.../eventbridge/MapCloudEventValidationTest.java | 198 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc | 19 ++
3 files changed, 280 insertions(+)
diff --git
a/components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidator.java
b/components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidator.java
index 27f340e7ae84..c0b80d385e65 100644
---
a/components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidator.java
+++
b/components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidator.java
@@ -22,7 +22,10 @@ import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import com.aliyun.eventbridge.EventBridgeClient;
@@ -55,6 +58,16 @@ final class MapCloudEventValidator {
private static final Gson GSON = new Gson();
private static final String DEFAULT_SPECVERSION = "1.0";
+ /**
+ * The reserved CloudEvents core attribute names that the Alibaba SDK
serializes from the dedicated
+ * {@link CloudEvent} fields. An {@code extensions} entry using one of
these names would be flattened over the
+ * matching top-level attribute when the request is serialized. {@code
data_base64} is included because the SDK
+ * serializes the data as {@code data_base64} when the content type is not
JSON.
+ */
+ private static final Set<String> RESERVED_ATTRIBUTE_NAMES = Set.of(
+ "id", "source", "specversion", "type", "datacontenttype",
"dataschema", "subject", "time", "data",
+ "data_base64");
+
private final EventSourceCache eventSourceCache;
public MapCloudEventValidator(EventSourceCache eventSourceCache) {
@@ -148,6 +161,8 @@ final class MapCloudEventValidator {
throw new IllegalArgumentException("CloudEvent cannot be null");
}
+ rejectReservedAttributeExtensions(cloudEvent);
+
String eventBusName = extractEventBusName(cloudEvent);
if (ObjectHelper.isEmpty(eventBusName)) {
eventBusName = configuration.eventBusName();
@@ -168,6 +183,54 @@ final class MapCloudEventValidator {
}
validateBusSourceAndType(eventBusName, source, type, configuration,
client);
+
+ applyResolvedAttributes(cloudEvent, eventBusName, source, type);
+ }
+
+ /**
+ * Writes the resolved bus, source and type back onto the {@link
CloudEvent} so the request that the SDK serializes
+ * and sends carries exactly the values that were validated. For a {@code
CloudEvent}-object body the producer sends
+ * this same instance, and only the {@code aliyuneventbusname} extension
carries the bus on the wire, so a bus, type
+ * or source resolved from the endpoint options (or from an alternate
bus-name extension) would otherwise be
+ * validated but not sent. The {@code extensions} map is copied before it
is changed, and the bus is written onto
+ * the single {@code aliyuneventbusname} key the SDK serializes.
+ */
+ private static void applyResolvedAttributes(CloudEvent cloudEvent, String
eventBusName, String source, String type) {
+ cloudEvent.setSource(source);
+ cloudEvent.setType(type);
+
+ Map<String, Object> extensions = new LinkedHashMap<>();
+ Map<String, ?> current = cloudEvent.getExtensions();
+ if (current != null) {
+ extensions.putAll(current);
+ }
+ extensions.remove("aliyunEventBus");
+ extensions.remove("eventBusName");
+ extensions.put("aliyuneventbusname", eventBusName);
+ cloudEvent.setExtensions(extensions);
+ }
+
+ /**
+ * When the body is a {@link CloudEvent} instance, the Alibaba SDK
serializes the request by flattening every entry
+ * of the {@code extensions} map up to a top-level attribute, overriding
any dedicated attribute of the same name.
+ * An extension whose name matches a reserved CloudEvents core attribute
(for example {@code source} or
+ * {@code type}) would therefore replace the value this validator checked,
and the event would be published with a
+ * different source or type than the one that was validated. Reject such
an event so the value that is validated is
+ * the value that is published.
+ */
+ private static void rejectReservedAttributeExtensions(CloudEvent
cloudEvent) {
+ Map<String, ?> extensions = cloudEvent.getExtensions();
+ if (extensions == null || extensions.isEmpty()) {
+ return;
+ }
+ for (String key : extensions.keySet()) {
+ if (key != null &&
RESERVED_ATTRIBUTE_NAMES.contains(key.toLowerCase(Locale.ROOT))) {
+ throw new IllegalArgumentException(
+ "CloudEvent extension '" + key
+ + "' collides with the
reserved CloudEvent attribute of the same name;"
+ + " remove it from the
event extensions");
+ }
+ }
}
private static String extractEventBusName(CloudEvent cloudEvent) {
diff --git
a/components/camel-alibaba/camel-alibaba-eventbridge/src/test/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidationTest.java
b/components/camel-alibaba/camel-alibaba-eventbridge/src/test/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidationTest.java
index 94f1e32224c8..604ea87980ec 100644
---
a/components/camel-alibaba/camel-alibaba-eventbridge/src/test/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidationTest.java
+++
b/components/camel-alibaba/camel-alibaba-eventbridge/src/test/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidationTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.alibaba.eventbridge;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
@@ -30,6 +31,7 @@ import com.aliyun.eventbridge.models.ListEventBusesRequest;
import com.aliyun.eventbridge.models.ListEventBusesResponse;
import com.aliyun.eventbridge.models.ListRulesRequest;
import com.aliyun.eventbridge.models.ListRulesResponse;
+import com.aliyun.eventbridge.util.EventBuilder;
import org.apache.camel.Exchange;
import org.apache.camel.component.alibaba.eventbridge.models.AllowedEventBus;
import
org.apache.camel.component.alibaba.eventbridge.models.AllowedEventSource;
@@ -555,4 +557,200 @@ class MapCloudEventValidationTest extends
CamelTestSupport {
assertThat(urnSource2.source()).isEqualTo("urn:another:source");
assertThat(urnSource2.allowedEventTypes()).isEmpty();
}
+
+ @Test
+ void cloudEventExtensionNamedSourceIsRejected() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withAliyunEventBus("orders-bus")
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-200")
+ .build();
+
+ // the published source would be taken from this extension, not from
the validated dedicated field
+ Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+ extensions.put("source", "app.other");
+ event.setExtensions(extensions);
+
+ assertThatThrownBy(() -> validator.validateCloudEvent(event, config,
eventBridgeClient))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("collides with the reserved CloudEvent
attribute");
+ }
+
+ @Test
+ void cloudEventExtensionNamedTypeIsRejected() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withAliyunEventBus("orders-bus")
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-201")
+ .build();
+
+ // the published type would be taken from this extension, not from the
validated dedicated field
+ Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+ extensions.put("type", "OrderDeleted");
+ event.setExtensions(extensions);
+
+ assertThatThrownBy(() -> validator.validateCloudEvent(event, config,
eventBridgeClient))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("collides with the reserved CloudEvent
attribute");
+ }
+
+ @Test
+ void cloudEventWithNonReservedExtensionIsAccepted() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withAliyunEventBus("orders-bus")
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-202")
+ .build();
+
+ Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+ extensions.put("tenant", "tenant-a");
+ event.setExtensions(extensions);
+
+ validator.validateCloudEvent(event, config, eventBridgeClient);
+ assertThat(event.getExtensions()).containsKey("tenant");
+ }
+
+ @Test
+ void cloudEventWithAliyunEventBusNameExtensionIsAccepted() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ // the configuration carries no event bus name, so it can only be
resolved from the extension below
+ ClientConfigurations config = new ClientConfigurations(
+ null, null, null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-203")
+ .build();
+
+ // aliyuneventbusname is the extension the producer reads to resolve
the target event bus; it must stay a
+ // non-reserved name so the reject check lets it through and the bus
name is extracted from it
+ Map<String, Object> extensions = new HashMap<>();
+ extensions.put("aliyuneventbusname", "orders-bus");
+ event.setExtensions(extensions);
+
+ validator.validateCloudEvent(event, config, eventBridgeClient);
+
+ assertThat(event.getExtensions()).containsKey("aliyuneventbusname");
+ }
+
+ @Test
+ void cloudEventExtensionNamedDataBase64IsRejected() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withAliyunEventBus("orders-bus")
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-302")
+ .build();
+
+ // data_base64 is the attribute the SDK writes from the data field
when the content type is not JSON
+ Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+ extensions.put("data_base64", "x");
+ event.setExtensions(extensions);
+
+ assertThatThrownBy(() -> validator.validateCloudEvent(event, config,
eventBridgeClient))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("collides with the reserved CloudEvent
attribute");
+ }
+
+ @Test
+ void cloudEventExtensionReusingReservedNameInDifferentCaseIsRejected() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withAliyunEventBus("orders-bus")
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-303")
+ .build();
+
+ // reserved names are matched case-insensitively, so a different-case
key is rejected too
+ Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+ extensions.put("Source", "app.other");
+ event.setExtensions(extensions);
+
+ assertThatThrownBy(() -> validator.validateCloudEvent(event, config,
eventBridgeClient))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("collides with the reserved CloudEvent
attribute");
+ }
+
+ @Test
+ void cloudEventBusResolvedFromConfigIsWrittenBackOntoTheEvent() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ // the bus comes only from the endpoint configuration, not from the
event
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, null, null, false, false, true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withSource(URI.create("app.orders"))
+ .withType("OrderCreated")
+ .withId("event-304")
+ .build();
+ event.setExtensions(new HashMap<>());
+
+ validator.validateCloudEvent(event, config, eventBridgeClient);
+
+ // the validated bus is written onto the aliyuneventbusname extension
the SDK serializes on the wire
+
assertThat(event.getExtensions().get("aliyuneventbusname")).isEqualTo("orders-bus");
+ }
+
+ @Test
+ void cloudEventTypeResolvedFromConfigIsWrittenBackOntoTheEvent() {
+ AllowedEventSource allowedSource = new
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+ AllowedEventBus allowedBus = new AllowedEventBus("orders-bus",
Map.of("app.orders", allowedSource));
+ // the type comes only from the endpoint configuration
+ ClientConfigurations config = new ClientConfigurations(
+ null, "orders-bus", null, "OrderCreated", null, false, false,
true,
+ Map.of("orders-bus", allowedBus), 300000L);
+
+ CloudEvent event = EventBuilder.builder()
+ .withSource(URI.create("app.orders"))
+ .withType("placeholder")
+ .withId("event-305")
+ .build();
+ event.setType("");
+ Map<String, Object> extensions = new HashMap<>();
+ extensions.put("aliyuneventbusname", "orders-bus");
+ event.setExtensions(extensions);
+
+ validator.validateCloudEvent(event, config, eventBridgeClient);
+
+ // the validated type is written back so the event that is sent
carries it
+ assertThat(event.getType()).isEqualTo("OrderCreated");
+ }
}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index bf4269a9d427..14780f9d6591 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -78,6 +78,25 @@ Queue service of the `devstoreaccount1` account under
`/devstoreaccount1-queue`.
`http://localhost:4577/devstoreaccount1-queue` instead of
`http://localhost:10001/devstoreaccount1`. The account name and
key do not change. The Blob dev service still runs on Azurite.
+=== camel-alibaba-eventbridge - a CloudEvent body cannot carry extensions that
reuse reserved attribute names
+
+When the body sent to the `alibaba-eventbridge` producer is a `CloudEvent`
instance, its `extensions` map must not
+contain a key that reuses a reserved CloudEvents core attribute name (`id`,
`source`, `specversion`, `type`,
+`datacontenttype`, `dataschema`, `subject`, `time`, `data` or `data_base64`),
compared case-insensitively. The Alibaba
+SDK serializes a request by flattening each extension up to a top-level
attribute, so such an extension would replace
+the dedicated attribute of the same name that the producer set and validated.
The producer now rejects such an event
+with an `IllegalArgumentException`.
+
+The producer also writes the resolved event bus, source and type back onto a
`CloudEvent` body before it is sent, so
+the request carries exactly the values that were validated. The `CloudEvent`
instance given as the body is updated in
+place: the bus is written onto the `aliyuneventbusname` extension, the only
bus key the SDK serializes on the wire, on
+a copy of the extensions map from which the `aliyunEventBus` and
`eventBusName` hint keys are removed, and the source
+and type onto the dedicated fields. A bus, source or type that was resolved
from the endpoint options, or a bus taken
+from one of the two hint keys, is therefore now serialized and sent rather
than validated and silently dropped.
+
+Routes that copy arbitrary key/value pairs into a `CloudEvent` `extensions`
map should drop these reserved names
+before sending. The `Map` and JSON-text body forms build a fresh event and are
not affected.
+
=== camel-alibaba-eventbridge - the client that the endpoint creates sends its
requests over HTTPS
The client that the `alibaba-eventbridge` endpoint creates now sends its
requests to EventBridge over HTTPS. Before,