This is an automated email from the ASF dual-hosted git repository. Croway pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 35585595184c7d2ac330935dab84adfee28b6c01 Author: croway <[email protected]> AuthorDate: Mon Nov 23 18:55:53 2026 +0100 CAMEL-27454: camel-ftp - a producer without a directory refuses absolute file names Without a directory, a remote file endpoint starts in the home directory of the login, so with jailStartingDirectory (the default) the producer now refuses a file name that starts at a root: a name starting with / or \, or with a drive such as C:/ or C:\. A name such as a:b.txt is not absolute. Set jailStartingDirectory=false to write files at absolute paths from an endpoint without a directory. --- .../camel/component/file/GenericFileProducer.java | 21 +++++++++++++++++++++ ...RemoteFileProducerStartingDirectoryJailTest.java | 20 ++++++++++++++++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 12 ++++++++++++ 3 files changed, 53 insertions(+) diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java index 8e1cf3092c42..47bf43c0a98b 100644 --- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java +++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileProducer.java @@ -580,6 +580,10 @@ public class GenericFileProducer<T> extends DefaultAsyncProducer { boolean within; if (endpoint.getConfiguration().needToNormalize()) { within = GenericFileHelper.isWithinDirectory(compatchAnswer, compatchBaseDir); + } else if (baseDir.isEmpty() && isAbsoluteName(answer)) { + // without a directory a remote endpoint starts in the home directory of the login, which an absolute name + // is not within + within = false; } else { // the path is used on a remote server, which may take a backslash in it as part of a name, unless the // backslashes are replaced by / before the path is used @@ -602,6 +606,23 @@ public class GenericFileProducer<T> extends DefaultAsyncProducer { return false; } + /** + * Whether the name starts at a root: with a / or a \, or with a drive such as C:/ or C:\ that a server on Windows + * takes as absolute. A name such as a:b.txt does not. + */ + private static boolean isAbsoluteName(String name) { + if (name.isEmpty()) { + return false; + } + char first = name.charAt(0); + if (first == '/' || first == '\\') { + return true; + } + boolean drive = name.length() >= 2 && name.charAt(1) == ':' + && (first >= 'a' && first <= 'z' || first >= 'A' && first <= 'Z'); + return drive && (name.length() == 2 || name.charAt(2) == '/' || name.charAt(2) == '\\'); + } + private String evaluateName(Exchange exchange, Expression expression, Object value) { String name; if (expression != null) { diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProducerStartingDirectoryJailTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProducerStartingDirectoryJailTest.java index 2f43054bac2d..af7e7a8c5e72 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProducerStartingDirectoryJailTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProducerStartingDirectoryJailTest.java @@ -104,6 +104,26 @@ class RemoteFileProducerStartingDirectoryJailTest extends CamelTestSupport { assertEquals("upload/a\\b.txt", createFileName("ftp://hostname/upload", "a\\b.txt")); } + @Test + void shouldRefuseAbsoluteNamesWithoutDirectory() throws Exception { + for (String uri : new String[] { "ftp://hostname", "sftp://hostname" }) { + assertRefused(uri, "/home/other/planted.txt"); + assertRefused(uri, "\\home\\other\\planted.txt"); + // a drive that a server on Windows takes as absolute + assertRefused(uri, "C:/Users/other/planted.txt"); + assertRefused(uri, "c:\\Users\\other\\planted.txt"); + assertRefused(uri, "C:"); + } + // a colon that is not a drive + assertEquals("a:b.txt", createFileName("ftp://hostname", "a:b.txt")); + assertEquals("report 10:30.txt", createFileName("ftp://hostname", "report 10:30.txt")); + // with a directory, an absolute name is relative to it + assertEquals("upload//sub/hello.txt", createFileName("ftp://hostname/upload", "/sub/hello.txt")); + // the jail can be turned off + assertEquals("/home/other/planted.txt", + createFileName("ftp://hostname?jailStartingDirectory=false", "/home/other/planted.txt")); + } + @Test void shouldAcceptAnyNameWithoutJail() throws Exception { assertEquals("http:/../../other/planted.txt", diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 5c325b92ad14..9d89cf369ff7 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -564,6 +564,18 @@ current directory between two uploads is the directory of the last file, not the example the one set with the `ftpClient` option) and sends commands with relative names between two operations of Camel must change directory itself. +=== camel-ftp, camel-sftp, camel-mina-sftp - an absolute file name is refused when the endpoint has no directory + +With the default `jailStartingDirectory=true`, a producer whose endpoint has no directory (for example +`+sftp://user@host+`, which uploads into the home directory of the login) now refuses an absolute file name: a name +starting with `/` or `\`, or with a drive such as `C:/`, `C:\` or `C:` alone, which a server on Windows takes as +absolute (on other servers such a name was written as a relative name). The exchange fails with an +`IllegalArgumentException` stating that the filename is jailed to the starting directory. A name such as `a:b.txt` is +not refused. + +When the endpoint has a directory, an absolute name is relative to it, as before. To write files at absolute paths +from an endpoint without a directory, set `jailStartingDirectory=false` on the endpoint. + === camel-ai-resource - fixed resourceUri cannot contain braces Starting in Camel 4.24, `ai-resource` rejects a fixed `resourceUri` containing `{` or `}` at route startup. The MCP SDK interprets those characters as URI-template expressions. Routes that intend variable path segments must use `uriTemplate` instead, for example `+ai-resource:customer?uriTemplate=camel:///customers/{id}+`. If the braces are literal URI characters, percent-encode them as `%7B` and `%7D`.
