Claus Ibsen created CAMEL-26928:
-----------------------------------

             Summary: camel-file - jailStartingDirectory also checks links in 
consumer move targets
                 Key: CAMEL-26928
                 URL: https://issues.apache.org/jira/browse/CAMEL-26928
             Project: Camel
          Issue Type: Bug
          Components: camel-file
            Reporter: Claus Ibsen
            Assignee: Claus Ibsen
             Fix For: 4.24.0, 4.22.3, 4.18.6


The file component option jailStartingDirectory (enabled by default) keeps the 
producer and the consumer listing inside the starting directory, also when a 
path resolves through a symbolic link (CAMEL-25412). The consumer's 
post-processing move does not apply the same check yet.

*Today*
After an exchange completes (move, or the default .camel folder), before 
processing (preMove) or after a failure (moveFailed), 
GenericFileProcessStrategySupport.renameFile deletes an existing target file, 
creates the target's parent directories and renames the file onto the target, 
using plain filesystem calls. When the target path lies inside the starting 
directory but a directory or file on that path is a symbolic link that resolves 
elsewhere, the delete, the directory creation and the rename (and the 
copy-and-delete fallback of copyAndDeleteOnRenameFail) act on the resolved 
location instead of a location inside the starting directory.

*After the change*
With jailStartingDirectory=true, a move, preMove or moveFailed target that is 
lexically inside the starting directory, including the default .camel folder, 
must also resolve inside it once symbolic links are followed. Otherwise the 
move is refused before anything is deleted, created or renamed, and it fails 
like any other failed move: the file stays where it is and the commit or 
rollback reports the error. Targets that are configured outside the starting 
directory on purpose (for example move=../archive/${file:onlyname} or an 
absolute archive path) keep working as before. jailStartingDirectory=false 
keeps the current behaviour.

*Code changes*
- GenericFileProcessStrategySupport.renameFile: check the target before the 
delete, before buildDirectory and before the rename (not inside the existing 
try/catch around deleteFile), only when the operations are FileOperations, as 
GenericFileProducer.writeFile already does.
- FileOperations: make the starting-directory containment check reachable from 
the strategy package (reusing 
GenericFileHelper.isWithinDirectoryResolvingLinks), with a message that fits a 
move.
- file-component.adoc: document that the consumer's move, preMove and 
moveFailed targets are checked as well; regenerate the catalog copy.
- Upgrade guide entry for the changed behaviour.

*Tests*
New test in core/camel-core next to 
FileConsumerJailStartingDirectorySymlinkTest (skipped where links cannot be 
created), covering: the default .camel folder, move, preMove and moveFailed 
folders that are links resolving elsewhere, recursive=true with a sub 
directory, the copy-and-delete rename path, a link that resolves inside the 
starting directory (still used), a move target configured outside the starting 
directory (still works), and jailStartingDirectory=false (old behaviour).



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

Reply via email to