[ 
https://issues.apache.org/jira/browse/CAMEL-27054?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on CAMEL-27054 started by Claus Ibsen.
-------------------------------------------
> camel-ftp - refuse a file or directory name with a carriage return or line 
> feed
> -------------------------------------------------------------------------------
>
>                 Key: CAMEL-27054
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27054
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-ftp
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.18.6, 4.22.3, 4.24.0
>
>
> The FTP control connection sends one command per line. The ftp and ftps 
> components pass remote file and directory names unchanged to the commons-net 
> {{FTPClient}} (STOR, APPE, RETR, DELE, RNFR/RNTO, MKD, CWD, NLST and the SITE 
> chmod command). A name that contains a carriage return (CR) or line feed (LF) 
> therefore cannot be sent as a single command: the server reads the rest of 
> the name as a separate line, and the operation does not do what the route 
> asked for. commons-net does not check for this either.
> *Today*
> A name with a CR or LF (for example from the {{CamelFileName}} header, a 
> {{tempFileName}} or {{doneFileName}} expression, or a directory segment of 
> the name) is written to the control connection as is.
> *After the change*
> The ftp and ftps file operations refuse such a name before any command is 
> sent, with a {{GenericFileOperationFailedException}} that gives the character 
> code and its index (not the name). This matches what the scp producer already 
> does for a line feed. Names without CR or LF behave as before. The sftp 
> component is not changed (it uses a binary protocol), and the {{siteCommand}} 
> option keeps splitting its configured value on new lines.
> *Code*
> * 
> {{components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java}}
>  (also used by {{FtpsOperations}}): add one private static check that refuses 
> {{\r}} and {{\n}}, in the style of {{ScpOperations.checkFileName}}.
> * Call it on every name that reaches {{FTPClient}}: {{storeFile}} (the full 
> name, before changing directory step by step), {{storeFileDirectly}}, 
> {{deleteFile}}, {{renameFile}} (from and to), {{buildDirectory}} / 
> {{buildDirectoryChunks}}, {{changeCurrentDirectory}} / {{doChangeDirectory}}, 
> {{existsFile}} / {{fastExistsFile}}, the {{retrieveFile}} variants and 
> {{listFiles(path)}}. The chmod SITE command is covered through the target 
> name.
> *Tests*
> * {{FtpProducerFileNameLineBreakTest}} (uses the existing {{FakeFtpServer}}, 
> which records the commands it receives): a CR, a LF and a CR LF in 
> {{CamelFileName}}, in a directory segment, in {{tempFileName}} and 
> {{doneFileName}} expressions built from {{$\{file:name\}}}, and with 
> {{fileExist=Move}}. The exchange fails with 
> {{GenericFileOperationFailedException}}, and no STOR, DELE, RNFR, RNTO or MKD 
> is sent for it.
> * {{FtpProducerFileNameLineBreakIT}} (embedded FTP server via 
> {{FtpServerTestSupport}}): the same name fails and nothing is created on the 
> server.
> * A plain name still uploads.
> *Docs*
> One sentence in {{ftp-component.adoc}} (and the ftps page if it has its own 
> note), with the catalog copy regenerated, and short upgrade-guide entries for 
> 4.24, 4.22.3 and 4.18.6 (on main).
> Backport to camel-4.22.x and camel-4.18.x. Those branches do not have 
> {{FakeFtpServer}}, so the backports use the embedded-server test (or bring 
> {{FakeFtpServer}} along as a test file).



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

Reply via email to