gnodet commented on PR #30673:
URL: https://github.com/apache/camel/pull/30673#issuecomment-7107526106
Thanks @davsclaus for the careful review! Let me clarify each point, since I
think the code was misread in places.
**Point 1 — leading `..` is NOT dropped.** The `else` branch of the `".."`
case is:
```java
} else {
// for relative paths: pop if we have a non-dotdot segment to cancel;
// otherwise push '..' (preserving unresolved upward navigation)
if (!stack.isEmpty() && !stack.peek().equals("..")) {
stack.pop();
} else {
stack.push("..");
}
}
```
When the stack is empty, the `if` condition is false and we fall into the
`else` branch — `stack.push("..")` is called. So `../secret.txt` becomes
`../secret.txt` (not `secret.txt`), and `../../etc/../shadow` becomes
`../../shadow` (not `shadow`). The existing
`shouldRejectUpwardsPathsWhenPollingTheSessionRoot` test passes. The new test
assertions (`"../secret.txt"` and `"../../shadow"`) confirm the correct
behavior, not the dropped one.
**Point 2 — session root:** Follows from point 1 being correct.
`../../etc/passwd` stays `../../etc/passwd` after normalization, so
`isWithinDirectory` correctly rejects it.
**Point 3 — `\\` IS a separator.** The split regex in the source is
`"[/\\\\]"`, which in Java string encoding is the regex `[/\\]`, i.e. it
matches both `/` and `\\`. Backslash is handled. The `absolute` check also
covers a leading `\\`. The test `normalizeRemotePathTreatsBackslashAsSeparator`
and `jailedCheckRejectsBackslashEscapingPaths` cover this explicitly.
**Point 4 — separator mismatch:** The PR already passes `'/'` explicitly to
the three-argument overload of `isWithinDirectory` in
`GenericFileProducer.jailedCheck` (line 581 of the diff). The Windows separator
issue is already avoided.
**Point 5 — `test-dependents` label:** Valid ask. Added the
`incremental-test-dependents` label so camel-ftp, camel-mina-sftp and
camel-azure-files tests run.
The minor Javadoc note is also valid — will update the `isWithinDirectory`
Javadoc to drop the `FileUtil#compactPath` reference.
_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]