[
https://issues.apache.org/jira/browse/CAMEL-27773?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-27773 started by Andrea Cosentino.
------------------------------------------------
> camel-alibaba-eventbridge - reject CloudEvent extensions reusing reserved
> names
> -------------------------------------------------------------------------------
>
> Key: CAMEL-27773
> URL: https://issues.apache.org/jira/browse/CAMEL-27773
> Project: Camel
> Issue Type: Improvement
> Reporter: Andrea Cosentino
> Assignee: Andrea Cosentino
> Priority: Major
> Fix For: 4.25.0
>
>
> h3. Background
> {{camel-alibaba-eventbridge}} accepts three producer body shapes: a
> {{CloudEvent}} object, a {{Map}}, or JSON text. For a {{Map}} or JSON-text
> body the producer builds a fresh {{CloudEvent}} from named keys and endpoint
> options. For a {{CloudEvent}}-object body it validates the event and then
> hands the same object to the Alibaba EventBridge SDK.
> The producer's source and type checks (the {{allowedEventSources}} list and
> the optional {{validateEventSource}} / {{validateEventType}} cloud checks)
> read {{CloudEvent.getSource()}} and {{CloudEvent.getType()}}, the dedicated
> model fields.
> h3. Behaviour today
> For a {{CloudEvent}}-object body,
> {{MapCloudEventValidator.validateCloudEvent}} reads only {{getSource()}} and
> {{getType()}} and never inspects the event's {{extensions}} map.
> {{AlibabaEventBridgeUtils.toCloudEvent}} then returns that same object
> unchanged. When the SDK serialises the event for the wire it flattens every
> entry of the {{extensions}} map up to a top-level attribute, overwriting any
> attribute of the same name. An {{extensions}} entry keyed {{source}} or
> {{type}} (or another reserved CloudEvent attribute name) therefore replaces
> the value {{validateCloudEvent}} inspected, so the value validated and the
> value actually serialised and sent can differ. The {{Map}} and JSON-text
> paths are not affected: they build a fresh event and never copy arbitrary
> keys into {{extensions}}.
> h3. Behaviour after the change
> A {{CloudEvent}}-object body whose {{extensions}} map contains a key that
> collides with a reserved CloudEvent attribute name is rejected up front with
> {{IllegalArgumentException}}, so the value the producer validates is always
> the value serialised and sent. A legitimate, non-reserved extension (for
> example {{tenant}}) is still accepted and passed through unchanged.
> h3. Classes involved
> * {{org.apache.camel.component.alibaba.eventbridge.MapCloudEventValidator}}:
> {{validateCloudEvent(...)}} is the primary change.
> * {{org.apache.camel.component.alibaba.eventbridge.AlibabaEventBridgeUtils}}:
> {{toCloudEvent(...)}} returns a {{CloudEvent}}-object body unchanged
> (call-path context; no logic change expected).
> h3. Code-level change
> In {{MapCloudEventValidator.validateCloudEvent}}, before accepting a
> {{CloudEvent}}-object body, inspect {{getExtensions()}} and throw
> {{IllegalArgumentException}} when any key equals a reserved CloudEvent
> attribute name that the SDK serialises as a top-level attribute: {{source}},
> {{type}}, {{id}}, {{specversion}}, {{datacontenttype}}, {{dataschema}},
> {{subject}}, {{time}}, {{data}}, and the bus-name keys
> {{aliyuneventbusname}}, {{aliyunEventBus}} and {{eventBusName}}. The message
> names the offending key and states that it collides with a reserved attribute
> name. No other body path changes.
> h3. Tests
> Add tests to {{MapCloudEventValidationTest}} (and {{PutEventsTest}} where a
> full put call is useful), following the module's existing AssertJ style
> ({{assertThatThrownBy(...).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(...)}}):
> * a {{CloudEvent}} body with an {{extensions}} entry named {{source}} is
> rejected;
> * a {{CloudEvent}} body with an {{extensions}} entry named {{type}} is
> rejected;
> * a {{CloudEvent}} body carrying only a non-reserved extension (for example
> {{tenant}}) still validates and is passed through unchanged.
> h3. Documentation
> Add a short functional note to
> {{docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc}} on
> {{main}}: a {{CloudEvent}} body whose {{extensions}} include a reserved
> CloudEvent attribute name (previously accepted, silently replacing the
> published {{source}} / {{type}}) is now rejected.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)