[ 
https://issues.apache.org/jira/browse/CAMEL-28020?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-28020.
---------------------------------
    Resolution: Fixed

Fixed by https://github.com/apache/camel/pull/31250 (merged as 1b237910a5ba).

_Claude Code on behalf of davsclaus_

> camel-salesforce - validate REST client request URLs and encode id segments
> ---------------------------------------------------------------------------
>
>                 Key: CAMEL-28020
>                 URL: https://issues.apache.org/jira/browse/CAMEL-28020
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-salesforce
>            Reporter: Andrea Cosentino
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 4.25.0
>
>
> h3. Background
> The camel-salesforce component's internal REST client builds some outbound 
> request URLs by string-concatenating the configured Salesforce instance URL 
> with a value taken from the exchange, and issues the request without checking 
> that the result still points at the configured instance.
> h3. Current behaviour
> For the {{queryMore}} operation, {{DefaultRestClient.queryMore(...)}} issues 
> a {{GET}} to {{instanceUrl + nextRecordsUrl}}. The {{nextRecordsUrl}} value 
> is resolved from the exchange (request header, endpoint option, or message 
> body). {{AbstractClientBase.getRequest(...)}} hands the concatenated string 
> straight to {{java.net.URI.create(url)}} and then to the Jetty HTTP client. 
> Because the value is appended verbatim, a {{nextRecordsUrl}} that is not a 
> plain path can make the resolved {{URI}} parse to an authority different from 
> the configured instance, so the request is issued to a location other than 
> the configured Salesforce instance.
> The same concatenation pattern is used by 
> {{DefaultRawClient.makeRequest(...)}} (the {{raw}} operation), which builds 
> {{instanceUrl + path}} in the same way.
> Separately, {{DefaultRestClient}} inserts the object id into the request path 
> without URL-encoding it in {{getSObject}}, {{deleteSObject}}, 
> {{getBlobField}} and {{updateSObject}}, while the sibling operations 
> {{query}}, {{queryAll}} and {{search}} (via {{urlEncode}}) and 
> {{getSObjectWithId}}, {{upsert}} and {{deleteSObjectWithId}} (via 
> {{sobjectsExternalIdUrl}}) do encode their values. This is an inconsistency: 
> an id containing characters such as {{/}}, {{?}}, {{#}} or a space is not 
> handled correctly.
> h3. Proposed change
> * In {{DefaultRestClient.queryMore(...)}}, validate the fully resolved 
> request URL before issuing it: the scheme, host and port of the resolved URL 
> must equal those of the configured instance URL, and {{nextRecordsUrl}} must 
> be an absolute path (a single leading {{/}}). If the resolved URL would point 
> at a different scheme, host or port, fail fast with a {{SalesforceException}} 
> rather than sending the request.
> * Apply the same instance check in {{DefaultRawClient.makeRequest(...)}} for 
> consistency.
> * Add a small shared validation helper in {{AbstractClientBase}} (which 
> already owns {{instanceUrl}} and {{getRequest}}) so both clients share one 
> implementation.
> * URL-encode the object id path segment in {{getSObject}}, {{deleteSObject}}, 
> {{getBlobField}} and {{updateSObject}}, matching the operations that already 
> encode.
> h3. Classes involved
> * 
> {{components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRestClient.java}}
> * 
> {{components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClient.java}}
> * 
> {{components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/AbstractClientBase.java}}
> h3. Tests
> New and extended unit tests in the {{internal.client}} package, written in 
> JUnit style to match the module's existing tests:
> * a normal {{/services/data/vNN.0/query/...}} {{nextRecordsUrl}} resolves to 
> the configured instance and is accepted;
> * a {{nextRecordsUrl}} that resolves to a different scheme, host or port is 
> rejected with {{SalesforceException}};
> * the {{raw}} {{makeRequest}} path rejects a value that changes the instance 
> the same way;
> * {{getSObject}} and {{deleteSObject}} with an id containing {{/}}, {{?}}, 
> {{#}} or a space produce a correctly percent-encoded path.
> h3. Documentation
> A functional note will be added to the upgrade guide on {{main}} 
> ({{docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc}}) 
> describing the behaviour change: {{queryMore}} (and {{raw}}) now reject a 
> value that resolves to a host other than the configured instance. No 
> {{@UriParam}}, header-constant or {{@Metadata}} change is involved, so no 
> catalog/DSL regeneration is expected.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to