gnodet opened a new pull request, #30673: URL: https://github.com/apache/camel/pull/30673
## Summary Normalize remote file paths without special prefix handling in the three starting-directory jail-check sites: `RemoteFileConsumer.isWithinStartingDirectory`, `GenericFileProducer.jailedCheck`, and `SmbConsumer.isWithinStartingDirectory`. ## Root Cause `FileUtil.compactPath`, previously used at all three sites, gives certain leading prefixes a special meaning that does not apply to remote file paths: - Paths starting with `http:` or `https:` are returned **unchanged** — any `../` sequences in the path are left unresolved. - `file:`, `classpath:` and `http:` prefixes are stripped as URI schemes before the `..` processing runs. - Segments that look like Windows drive letters (e.g. `C:`) receive special `..`-processing treatment. An FTP or SMB server can return a file name that resembles a URI scheme (e.g. `http:/../../../etc/passwd`). When such a path also contains `../` sequences, `compactPath` returns it unchanged (because of the `http:` prefix check at lines 296–298 of `FileUtil`), leaving the `../` segments unresolved. The jail-check in `isWithinDirectory` then operates on the unresolved string rather than on the semantically meaningful normalized path. ## Fix Add `GenericFileHelper.normalizeRemotePath(String)`: a pure lexical path normalizer that: - resolves `.` and `..` segments, - uses `/` as the only separator, - preserves absolute/relative distinction and trailing slashes, - treats **every segment identically** — no URI scheme, no Windows drive-letter exceptions. Replace `FileUtil.compactPath(…, '/')` with `GenericFileHelper.normalizeRemotePath(…)` at the three jail-check sites. ## Tests Extended `GenericFileHelperTest` with: - `normalizeRemotePathResolvesDotsAndDoubleDots` — basic `.` / `..` normalization, absolute and relative, `null` passthrough. - `normalizeRemotePathDoesNotTreatUriSchemesSpecially` — `http:`, `classpath:`, `file:`, `https:` are all treated as plain path segments. - `normalizeRemotePathDoesNotTreatWindowsDriveLettersSpecially` — `C:` is treated as a plain segment. - `isWithinStartingDirectoryDoesNotBypassJailForUriSchemeLikePaths` — the combination of `normalizeRemotePath` + `isWithinDirectory` correctly handles URI-scheme-like paths. Fixes CAMEL-27453 --- _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- 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]
