davsclaus commented on code in PR #28214:
URL: https://github.com/apache/camel/pull/28214#discussion_r4334534144
##########
components/camel-ftp-common/src/main/java/org/apache/camel/component/file/remote/AbstractSftpConsumer.java:
##########
@@ -247,6 +260,104 @@ protected boolean
isMatched(Supplier<GenericFile<SftpRemoteFile>> file, String d
return false;
}
+ @Override
+ protected boolean
isWithinStartingDirectory(Supplier<GenericFile<SftpRemoteFile>> file, String
absoluteFilePath) {
+ if (!super.isWithinStartingDirectory(file, absoluteFilePath)) {
+ return false;
+ }
+ GenericFile<SftpRemoteFile> remoteFile = file.get();
+ if (remoteFile.getFile() == null ||
!remoteFile.getFile().isSymbolicLink()) {
+ return true;
+ }
+ // the server follows a symbolic link when the file is retrieved, so
the target of a listed link must be within
+ // the starting directory too
+ if (!(operations instanceof SftpSymbolicLinkOperations links)) {
+ LOG.debug("Cannot resolve symbolic link: {} as the operations
cannot read symbolic links", absoluteFilePath);
+ return false;
+ }
+ try {
+ String startingDirectory = resolvedStartingDirectory;
+ if (startingDirectory == null) {
+ startingDirectory = resolveSymbolicLinks(links, null,
endpointPath);
+ resolvedStartingDirectory = startingDirectory;
+ }
+ // the path of the file below the starting directory is resolved
from the resolved starting directory
+ String relativeFilePath = remoteFile.getRelativeFilePath();
+ String target = relativeFilePath != null
+ ? resolveSymbolicLinks(links, startingDirectory,
relativeFilePath)
+ : resolveSymbolicLinks(links, null,
remoteFile.getAbsoluteFilePath());
+ return GenericFileHelper.isWithinDirectory(target,
startingDirectory, '/');
+ } catch (GenericFileOperationFailedException e) {
Review Comment:
(not blocking) This also catches transport errors from `lstat`/`readlink`,
such as a lost connection or a timeout. These are then logged as "resolves
outside the starting directory" by `isValidFile()` and recorded in
`skippedOutsideStartingDirectory`. Skipping is the right outcome. Could the
DEBUG line here say whether the link could not be resolved or the server could
not be reached? Or could a transport error be rethrown so the poll fails as it
would on the next request anyway?
_Claude Code on behalf of davsclaus. This review was generated by an AI
agent and may contain inaccuracies. Please verify all suggestions before
applying._
##########
components/camel-mina-sftp/src/main/docs/mina-sftp-component.adoc:
##########
@@ -571,6 +571,15 @@ IMPORTANT: The `chmod` and `chmodDirectory` options only
work on POSIX-compatibl
The consumer follows symbolic links to their target files. The producer writes
to symlink targets.
Review Comment:
(optional) This sentence now needs the next paragraph to be correct. Maybe:
"The consumer follows symbolic links to their target files, within the starting
directory unless `jailStartingDirectory=false` (see below)." The catalog copy
needs regenerating with it.
_Claude Code on behalf of davsclaus. This review was generated by an AI
agent and may contain inaccuracies. Please verify all suggestions before
applying._
--
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]