CAMEL-23765: remote-file consumers - contain localWorkDirectory downloads within the work directory#24180
Conversation
…oads within the work directory When localWorkDirectory was enabled, the remote-file consumers built the local work file path from the remote file name (target.getRelativeFilePath()) without ensuring the result stayed within the configured work directory. 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. This adds a shared GenericFileHelper.jailToLocalWorkDirectory containment check, mirroring the producer, and applies it (for both the in-progress temp file and the final file) in the localWorkDirectory download path of FtpOperations, SftpOperations, MinaSftpOperations (camel-mina-sftp), FilesOperations (camel-azure-files) and SmbOperations (camel-smb). The check reuses the existing jailStartingDirectory option (default true), so it is secure by default and can be disabled with jailStartingDirectory=false. A remote file resolving outside the work directory is rejected with a GenericFileOperationFailedException. Adds GenericFileHelperTest and a 4.21 upgrade-guide note. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
davsclaus
left a comment
There was a problem hiding this comment.
Solid, well-scoped security fix. The jailToLocalWorkDirectory check mirrors the existing GenericFileProducer.jailedCheck pattern, covers all five retrieveFileToFileInLocalWorkDirectory implementations, and is secure by default via the existing jailStartingDirectory option. No blocking issues found — two minor observations below.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
|
🧪 CI tested the following changed modules:
Build reactor — dependencies compiled but only changed modules were tested (9 modules)
|
…B jail ordering) Addresses the two non-blocking review observations from @davsclaus: - GenericFileEndpoint: jailStartingDirectory is now label="common" (was "producer") with an expanded description covering consumer localWorkDirectory downloads, since the option now governs both producer writes and consumer downloads. Regenerated the catalog, component metadata and endpoint-dsl factories for all file-based components (file, ftp, ftps, sftp, smb, azure-files, mina-sftp, scp). - SmbOperations: moved the localWorkDirectory jail check before directory creation to match FtpOperations/SftpOperations/MinaSftpOperations/FilesOperations, preserving SMB's existing mkdirs() on the base work directory. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes CAMEL-23765.
Problem
When
localWorkDirectoryis 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: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 viaFileUtil.compactPath+startsWithwhenjailStartingDirectoryis enabled. Per the security model, path traversal in file/FTP consumers is in scope.Change
GenericFileHelper.jailToLocalWorkDirectory(target, workDir)(camel-file) — throwsGenericFileOperationFailedExceptionifcompactPath(target)does notstartsWithcompactPath(workDir), mirroring the producer'sjailedCheck.mkdirs, in thelocalWorkDirectorydownload path of:FtpOperations+SftpOperations(camel-ftp)MinaSftpOperations(camel-mina-sftp)FilesOperations(camel-azure-files)SmbOperations(camel-smb)jailStartingDirectoryoption (defaulttrue, inherited by all file endpoints) — secure by default, consistent with the producer, opt-out viajailStartingDirectory=false. No new config surface.jailStartingDirectoryoption is nowlabel = "common"(was"producer") with an expanded description, since it now governs consumer-sidelocalWorkDirectorydownloads in addition to producer writes. Catalog/component metadata and endpoint-dsl factories are regenerated accordingly for all file-based components (file, ftp, ftps, sftp, smb, azure-files, mina-sftp, scp).Tests
GenericFileHelperTest— verifies files within the work directory (incl.../that still resolves inside) are allowed, and escaping paths are rejected.SmbConsumerLocalWorkDirectoryIT, camel-mina-sftp feature IT) cover legitimate-download regression.mvn clean install -DskipTests, 1874 modules) green. The only generated-file changes are thejailStartingDirectoryproducer → commonrelabel (catalog + component JSON + endpoint-dsl factories for the file components); no other drift.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 tocamel-4.18.xandcamel-4.14.x(per the JirafixVersions: 4.14.8, 4.18.3, 4.21.0). Matching 4_18/4_14 guide entries will be added onmainwith the backports.Claude Code on behalf of Andrea Cosentino