You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "oscerd (via GitHub)" <gi...@apache.org> on 2026/06/22 12:11:31 UTC

[PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

oscerd opened a new pull request, #24180:
URL: https://github.com/apache/camel/pull/24180

   Fixes [CAMEL-23765](https://issues.apache.org/jira/browse/CAMEL-23765).
   
   ## Problem
   
   When `localWorkDirectory` is enabled, the remote-file consumers build the local work file path from the remote file name (`target.getRelativeFilePath()`) **without ensuring the result stays within the configured work directory**:
   
   ```java
   File local = new File(normalizePath(localWorkDirectory));
   String relativeName = target.getRelativeFilePath();   // untrusted remote name
   local = new File(local, relativeName);                // "../" escapes the work dir
   local.mkdirs(); // ... writes outside localWorkDirectory
   ```
   
   A remote file name containing `../` sequences could therefore resolve to a path **outside** the work directory (arbitrary local file write) — unlike the file producer, which already jails writes via `FileUtil.compactPath` + `startsWith` when `jailStartingDirectory` is enabled. Per the security model, *path traversal in file/FTP consumers* is in scope.
   
   ## Change
   
   - New shared **`GenericFileHelper.jailToLocalWorkDirectory(target, workDir)`** (camel-file) — throws `GenericFileOperationFailedException` if `compactPath(target)` does not `startsWith` `compactPath(workDir)`, mirroring the producer's `jailedCheck`.
   - Applied (to both the in-progress temp file and the final file), **before `mkdirs`**, in the `localWorkDirectory` download path of:
     - `FtpOperations` + `SftpOperations` (camel-ftp)
     - `MinaSftpOperations` (camel-mina-sftp)
     - `FilesOperations` (camel-azure-files)
     - `SmbOperations` (camel-smb)
   - **Reuses the existing `jailStartingDirectory` option** (default `true`, inherited by all 5 endpoints) — secure by default, consistent with the producer, opt-out via `jailStartingDirectory=false`. No new config surface.
   
   ## Tests
   
   - New `GenericFileHelperTest` — verifies files within the work directory (incl. `../` that still resolves inside) are allowed, and escaping paths are rejected.
   - Existing localWorkDirectory ITs (camel-smb `SmbConsumerLocalWorkDirectoryIT`, camel-mina-sftp feature IT) cover legitimate-download regression.
   - Full reactor build (`mvn clean install -DskipTests`, 1874 modules) green, no drift. No generated-file impact (no `@UriParam`).
   
   ## Documentation
   
   - `camel-4x-upgrade-guide-4_21.adoc` — note added for the remote-file consumers.
   
   ## Compatibility / backport
   
   Default-secure with an opt-out (`jailStartingDirectory=false`), so suitable for backport to `camel-4.18.x` and `camel-4.14.x` (per the Jira `fixVersions`). Matching 4_18/4_14 guide entries will be added on `main` with the backports.
   
   ---
   _Claude Code on behalf of Andrea Cosentino_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24180:
URL: https://github.com/apache/camel/pull/24180#issuecomment-4768140233

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24180:
URL: https://github.com/apache/camel/pull/24180#issuecomment-4768339275

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-azure/camel-azure-files`
   - `components/camel-file`
   - `components/camel-ftp`
   - `components/camel-mina-sftp`
   - `components/camel-smb`
   - `docs`
   
   > :information_source: Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the `test-dependents` label to force testing all dependents.
   
   <details><summary>Build reactor — dependencies compiled but only changed modules were tested (6 modules)</summary>
   
   - Camel :: Azure :: Files
   - Camel :: Docs
   - Camel :: FTP
   - Camel :: File
   - Camel :: MINA SFTP
   - Camel :: SMB
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/27951675769)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #24180:
URL: https://github.com/apache/camel/pull/24180#discussion_r3452210236


##########
components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java:
##########
@@ -337,12 +338,19 @@ private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exc
             // use relative filename in local work directory
             String relativeName = file.getRelativeFilePath();
 
+            java.io.File localWorkDir = local;
             temp = new java.io.File(local, relativeName + ".inprogress");
 
             // create directory to local work file
             local.mkdirs();
             local = new java.io.File(local, relativeName);
 
+            // ensure the local work file stays within the local work directory (CAMEL-23765)
+            if (endpoint.isJailStartingDirectory()) {

Review Comment:
   Style (non-blocking): In the other four implementations (`FtpOperations`, `SftpOperations`, `MinaSftpOperations`, `FilesOperations`), the jail check is placed **before** `mkdirs()`. Here it comes **after** `local.mkdirs()` (line 343). This is safe because `mkdirs()` at that point runs on the base work directory (before `relativeName` is appended), so no escaped path is created. But reordering to match the other implementations would improve consistency for future reviewers.



##########
components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileHelper.java:
##########
@@ -16,16 +16,39 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
 import java.util.function.Supplier;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.support.MessageHelper;
+import org.apache.camel.util.FileUtil;
 
 public final class GenericFileHelper {
 
     private GenericFileHelper() {
     }
 
+    /**
+     * Ensures the resolved local work file stays within the configured local work directory. The remote file name used
+     * to build the local work file path may contain {@code ../} sequences that would otherwise resolve to a path
+     * outside the work directory.
+     *
+     * @param  target                              the resolved local work file (or its in-progress temp file)

Review Comment:
   Minor (non-blocking): The `jailStartingDirectory` option on `GenericFileEndpoint` is declared with `label = "producer"`, so it only appears in the **Producer Options** table in generated component docs. This PR extends its meaning to also govern consumer-side `localWorkDirectory` downloads. Since the default is `true`, users only need to find the option if they want to *disable* it (and the upgrade guide entry names it), so practical impact is low. A follow-up to change the label to `"common"` and expand the description would improve discoverability.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd merged PR #24180:
URL: https://github.com/apache/camel/pull/24180


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory [camel]

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on code in PR #24180:
URL: https://github.com/apache/camel/pull/24180#discussion_r3459960339


##########
components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileHelper.java:
##########
@@ -16,16 +16,39 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
 import java.util.function.Supplier;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.support.MessageHelper;
+import org.apache.camel.util.FileUtil;
 
 public final class GenericFileHelper {
 
     private GenericFileHelper() {
     }
 
+    /**
+     * Ensures the resolved local work file stays within the configured local work directory. The remote file name used
+     * to build the local work file path may contain {@code ../} sequences that would otherwise resolve to a path
+     * outside the work directory.
+     *
+     * @param  target                              the resolved local work file (or its in-progress temp file)

Review Comment:
   Good call — applied here rather than as a follow-up (commit 9709484). `jailStartingDirectory` is now `label = "common"` (was `"producer"`) with an expanded description noting that, for consumers using a `localWorkDirectory`, it also restricts downloads to within that directory. It now appears in the common options for all file-based components, and the catalog/component metadata + endpoint-dsl factories are regenerated in this PR.
   
   Since this PR introduces the consumer-side semantic, documenting it here also keeps the 4.18.x / 4.14.x backports consistent (the option governs consumer downloads on those branches too).
   
   _Claude Code on behalf of Andrea Cosentino_



##########
components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java:
##########
@@ -337,12 +338,19 @@ private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exc
             // use relative filename in local work directory
             String relativeName = file.getRelativeFilePath();
 
+            java.io.File localWorkDir = local;
             temp = new java.io.File(local, relativeName + ".inprogress");
 
             // create directory to local work file
             local.mkdirs();
             local = new java.io.File(local, relativeName);
 
+            // ensure the local work file stays within the local work directory (CAMEL-23765)
+            if (endpoint.isJailStartingDirectory()) {

Review Comment:
   Done (commit 9709484) — reordered so the jail check runs before directory creation, matching `FtpOperations` / `SftpOperations` / `MinaSftpOperations` / `FilesOperations`. I kept SMB's existing `mkdirs()` on the base work directory (now `localWorkDir.mkdirs()`, equivalent to the previous `local.mkdirs()` call) rather than switching to `local.mkdirs()` on the full path, to avoid changing pre-existing behavior unrelated to this fix.
   
   _Claude Code on behalf of Andrea Cosentino_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org