jamesnetherton commented on code in PR #31250:
URL: https://github.com/apache/camel/pull/31250#discussion_r4768371210
##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRestClient.java:
##########
@@ -630,6 +639,15 @@ private String urlEncode(String query) throws
UnsupportedEncodingException {
return encodedQuery;
}
+ private String encodePathSegment(String value) {
+ try {
+ return urlEncode(value);
Review Comment:
Nit: a null `id` (e.g. a DTO without an id) now fails with an NPE from
`URLEncoder`, reported as `Cannot invoke "String.length()" because "s" is
null`. Previously the request was sent as `/Account/null`, so a not found
response could be handled by `notFoundBehaviour=NULL`. An explicit "id is
required" check would give a clearer error.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRestClient.java:
##########
@@ -281,7 +281,7 @@ private Map<String, InputStream> getBinaryFieldMap(Object
sObject) {
@Override
public void updateSObject(
String sObjectName, String id, InputStream sObject, Map<String,
List<String>> headers, ResponseCallback callback) {
- final Request patch = getRequest("PATCH", sobjectsUrl(sObjectName +
"/" + id), headers);
+ final Request patch = getRequest("PATCH", sobjectsUrl(sObjectName +
"/" + encodePathSegment(id)), headers);
Review Comment:
`updateSObjectMultipart` (line 300) still concatenates the raw `id`. The
processor uses it instead of `updateSObject` when the DTO has binary fields, so
the id is encoded on one path and not the other. It should use
`encodePathSegment(id)` too, with a test.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/AbstractClientBase.java:
##########
@@ -177,6 +178,48 @@ protected Request getRequest(String method, String url,
Map<String, List<String>
return request;
}
+ /**
+ * Resolves the request URL for a path that is relative to the configured
Salesforce instance and verifies that it
+ * stays on that instance. The {@code relativePath} must be an absolute
path (it has to begin with a single
+ * {@code /}), and the fully resolved URL must keep the scheme, host and
port of the configured instance URL.
+ * Operations that build a request URL by appending a caller-supplied path
onto {@link #instanceUrl} use this to
+ * keep the request on the configured instance.
+ *
+ * @param relativePath the path to append to the configured
instance URL
+ * @return the fully resolved request URL
+ * @throws SalesforceException if {@code relativePath} is not an absolute
path on the configured instance
+ */
+ protected String resolveInstanceUrl(String relativePath) throws
SalesforceException {
+ if (relativePath == null || !relativePath.startsWith("/") ||
relativePath.startsWith("//")) {
+ throw new SalesforceException(
+ "Request path must be an absolute path on the configured
Salesforce instance: " + relativePath);
+ }
+ final String requestUrl = instanceUrl + relativePath;
+ final URI instanceUri;
+ final URI requestUri;
+ try {
+ instanceUri = new URI(instanceUrl);
+ requestUri = new URI(requestUrl);
+ } catch (URISyntaxException e) {
+ throw new SalesforceException("Invalid request URL: " +
requestUrl, e);
+ }
+ if (!onSameInstance(instanceUri, requestUri)) {
Review Comment:
Nit: once the path has to start with a single `/`, it cannot change the
scheme, host or port, so this check looks redundant, and no test reaches it.
Fine as defence in depth, otherwise it could be dropped.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRestClient.java:
##########
@@ -156,7 +156,7 @@ public void getSObject(
}
params = fieldsValue.toString();
}
- Request get = getRequest(HttpMethod.GET, sobjectsUrl(sObjectName + "/"
+ id + params), headers);
+ Request get = getRequest(HttpMethod.GET, sobjectsUrl(sObjectName + "/"
+ encodePathSegment(id) + params), headers);
Review Comment:
Nit: `URLEncoder` leaves dots alone, so an id of `..` still produces
`/sobjects/Account/..`. It stays on the same instance, but can still change the
path. The same applies to the other encoded ids.
_Claude Code on behalf of jamesnetherton_
--
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]