gnodet-bot commented on code in PR #30340:
URL: https://github.com/apache/camel/pull/30340#discussion_r4614158075
##########
core/camel-support/src/main/java/org/apache/camel/support/NormalizedUri.java:
##########
@@ -33,9 +33,17 @@ public final class NormalizedUri extends ValueHolder<String>
implements Normaliz
// NormalizedEndpointUri (e.g. from SendDynamicProcessor / toD).
private final String rawUri;
- private NormalizedUri(String normalizedValue, String rawUri) {
+ // Whether the endpoint uri was computed from the current message at
runtime (for example the per-message
+ // recipient of toD, enrich, wireTap, pollEnrich, recipientList,
routingSlip or dynamicRouter). When true the
+ // query option values are bound as literal text, i.e. without
property-placeholder resolution and without
+ // bean/class reference (#class:, #bean:, #type:, ...) resolution, because
those segments come from the message
+ // and not from the route. Not part of equals/hashCode: the endpoint
registry key stays the uri alone.
Review Comment:
Nit: consider extending the comment to clarify the security implication:
values computed from the message at runtime should not be resolved as property
placeholders or bean references to prevent message-data injection into the
routing configuration.
##########
core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java:
##########
@@ -535,48 +541,60 @@ private static boolean doSetPropertyValue(
}
}
- // prepare the value before it is bound
- try {
- Object str = resolveValue(camelContext, target, key, text,
ignoreCase, fluentBuilder,
- allowPrivateSetter, reflection, configurer);
- // resolve property placeholders
- if (str instanceof String strValue) {
+ // prepare the value before it is bound. In literal mode the value was
computed from message content at
+ // runtime, so it is kept verbatim: neither property placeholders nor
bean/class references (#class:, #bean:,
+ // #type:, ...) are resolved, because that resolution is reserved for
values authored in the route.
+ if (literal) {
+ value = text;
+ } else {
+ try {
+ Object str = resolveValue(camelContext, target, key, text,
ignoreCase, fluentBuilder,
+ allowPrivateSetter, reflection, configurer);
// resolve property placeholders
- str = camelContext.resolvePropertyPlaceholders(strValue);
- }
- if (str == null && reference && mandatory && !optional) {
- // we could not resolve the reference and this is mandatory
- throw new PropertyBindingException(target, key, value);
+ if (str instanceof String strValue) {
+ // resolve property placeholders
+ str = camelContext.resolvePropertyPlaceholders(strValue);
+ }
+ if (str == null && reference && mandatory && !optional) {
+ // we could not resolve the reference and this is mandatory
+ throw new PropertyBindingException(target, key, value);
+ }
+ value = str;
+ } catch (Exception e) {
+ // report the exception using the long key and parent target
+ throw new PropertyBindingException(target, key, text, e);
}
- value = str;
- } catch (Exception e) {
- // report the exception using the long key and parent target
- throw new PropertyBindingException(target, key, text, e);
}
+ // in literal mode reference resolution must be disabled on every
binding path, and a value that still looks
+ // like a reference (#...) must not be handed to the configurer either
(the configurer resolves references for
+ // non-String options on its own), so it is bound via reflection as
plain text instead
+ boolean effReference = reference && !literal;
+ boolean skipConfigurer = literal && value instanceof String refStr &&
isReferenceParameter(refStr);
+
// okay we are ready to set the value, but the property key
// can still be complex such as a map/list/array so we need to handle
them specially than a regular key
boolean bound = false;
try {
if (isCollectionKey(name)) {
// collection key (list,map,array)
- if (configurer != null) {
+ if (configurer != null && !skipConfigurer) {
bound = setPropertyCollectionViaConfigurer(camelContext,
target, key, value, ignoreCase, configurer);
}
if (!bound && reflection) {
// fallback to reflection based
- bound = setPropertyCollectionViaReflection(camelContext,
target, key, value, ignoreCase, reference,
+ bound = setPropertyCollectionViaReflection(camelContext,
target, key, value, ignoreCase, effReference,
optional);
}
} else {
// regular key
- if (configurer != null) {
+ if (configurer != null && !skipConfigurer) {
bound = setSimplePropertyViaConfigurer(camelContext,
target, key, value, ignoreCase, configurer);
}
if (!bound && reflection) {
// fallback to reflection based
bound = setSimplePropertyViaReflection(camelContext,
target, key, value, fluentBuilder, allowPrivateSetter,
- reflection, ignoreCase);
+ !literal && reflection, ignoreCase);
Review Comment:
Nit: `effReference` is already defined on line 572 (`boolean effReference =
reference && !literal`) and used consistently in the collection-key path at
line 586. For symmetry, the regular-key path (here and the equivalent
`setPropertyCollectionViaReflection` call) could use the same variable:
```suggestion
effReference, ignoreCase);
```
##########
core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java:
##########
@@ -535,48 +541,60 @@ private static boolean doSetPropertyValue(
}
}
- // prepare the value before it is bound
- try {
- Object str = resolveValue(camelContext, target, key, text,
ignoreCase, fluentBuilder,
- allowPrivateSetter, reflection, configurer);
- // resolve property placeholders
- if (str instanceof String strValue) {
+ // prepare the value before it is bound. In literal mode the value was
computed from message content at
+ // runtime, so it is kept verbatim: neither property placeholders nor
bean/class references (#class:, #bean:,
+ // #type:, ...) are resolved, because that resolution is reserved for
values authored in the route.
+ if (literal) {
+ value = text;
+ } else {
+ try {
+ Object str = resolveValue(camelContext, target, key, text,
ignoreCase, fluentBuilder,
+ allowPrivateSetter, reflection, configurer);
// resolve property placeholders
- str = camelContext.resolvePropertyPlaceholders(strValue);
- }
- if (str == null && reference && mandatory && !optional) {
- // we could not resolve the reference and this is mandatory
- throw new PropertyBindingException(target, key, value);
+ if (str instanceof String strValue) {
+ // resolve property placeholders
+ str = camelContext.resolvePropertyPlaceholders(strValue);
+ }
+ if (str == null && reference && mandatory && !optional) {
+ // we could not resolve the reference and this is mandatory
+ throw new PropertyBindingException(target, key, value);
+ }
+ value = str;
+ } catch (Exception e) {
+ // report the exception using the long key and parent target
+ throw new PropertyBindingException(target, key, text, e);
}
- value = str;
- } catch (Exception e) {
- // report the exception using the long key and parent target
- throw new PropertyBindingException(target, key, text, e);
}
+ // in literal mode reference resolution must be disabled on every
binding path, and a value that still looks
+ // like a reference (#...) must not be handed to the configurer either
(the configurer resolves references for
+ // non-String options on its own), so it is bound via reflection as
plain text instead
+ boolean effReference = reference && !literal;
+ boolean skipConfigurer = literal && value instanceof String refStr &&
isReferenceParameter(refStr);
+
// okay we are ready to set the value, but the property key
// can still be complex such as a map/list/array so we need to handle
them specially than a regular key
boolean bound = false;
try {
if (isCollectionKey(name)) {
// collection key (list,map,array)
- if (configurer != null) {
+ if (configurer != null && !skipConfigurer) {
bound = setPropertyCollectionViaConfigurer(camelContext,
target, key, value, ignoreCase, configurer);
}
if (!bound && reflection) {
// fallback to reflection based
- bound = setPropertyCollectionViaReflection(camelContext,
target, key, value, ignoreCase, reference,
+ bound = setPropertyCollectionViaReflection(camelContext,
target, key, value, ignoreCase, effReference,
optional);
}
} else {
// regular key
- if (configurer != null) {
+ if (configurer != null && !skipConfigurer) {
bound = setSimplePropertyViaConfigurer(camelContext,
target, key, value, ignoreCase, configurer);
}
if (!bound && reflection) {
// fallback to reflection based
bound = setSimplePropertyViaReflection(camelContext,
target, key, value, fluentBuilder, allowPrivateSetter,
- reflection, ignoreCase);
+ !literal && reflection, ignoreCase);
Review Comment:
Nit: `effReference` is already defined on line 572 (`boolean effReference =
reference && !literal`) and used in the collection-key path at line 586. For
symmetry, the regular-key path here could use the same variable:
```suggestion
effReference, ignoreCase);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]