Repository navigation
Cherry pick #119846 to 26.7: Reject paths with an embedded NUL byte in filesystem containment checks - #120789
Merged
Conversation
`pathStartsWith` and `fileOrSymlinkPathStartsWith` compare the whole value of the path, while every syscall that the path is later passed to (`open`, `mkdir`, `stat`) stops at the first NUL byte. A path shaped as `<target>\0/<traversal back into the base directory>` was therefore reported as contained in the base directory, while the kernel addressed `<target>`, which can be anywhere on the filesystem. Both helpers now report such a path as not contained, so that every containment check built on them fails closed - among them `assertLocalPathCorrect`, the `user_files` fence of the local data lake table engines and table functions. `resolvePathRelativelyToBase` rejects it explicitly, because it returns a path that is passed to syscalls directly; `listObjects` already had that check for a reason of its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`grep -c` counted the error twice, because the client prints the log line of the server next to the exception. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The existing regression only exercised `deltaLakeLocal` / `icebergLocal`, whose check ANDs `fileOrSymlinkPathStartsWith` with `pathStartsWith`, so it stayed green if either helper regressed alone and never reached the guard in `resolvePathRelativelyToBase`. Add: - helper-level tests for `pathStartsWith` (both overloads) and `fileOrSymlinkPathStartsWith`, with the escape shape `<prefix>/../probe\0/../<prefix>/file` and the same traversal without a NUL as a positive control; - a direct test of `resolvePathRelativelyToBase`, asserting `BAD_ARGUMENTS` for NUL-bearing paths and keeping the plain-traversal `PATH_ACCESS_DENIED` and accepted-path behaviour as controls; - a functional test for a `fileOrSymlinkPathStartsWith`-only surface (the `file` function) and a `pathStartsWith`-only surface (the `Filesystem` database engine). Each names an existing entry in `user_files` followed by a NUL and a suffix, so a check that ignored the NUL would let the truncated path through and the query would succeed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…irst filesystem probe `getPathsList` stats the user-supplied path (`fs::is_directory`, `fs::file_size`) and expands its globs on the filesystem before the matched paths are checked for containment in `user_files_path`, and every syscall stops at the first NUL byte. The `file` table function and the `File` engine could therefore still make the server probe a truncated location that the containment check never sees. Reject such a path up front with `BAD_ARGUMENTS`, and do the same in `checkCreationIsAllowedResolvingDotDot`, whose `..` resolver canonicalizes the head of the path on the filesystem. Test `05213_storage_file_embedded_nul` covers the table function (plain, glob, archive syntax, `INSERT`) and the engine, each with an existing entry followed by a NUL and a suffix, so that the truncated path would succeed. Addresses the AI review on #119846 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reject paths with an embedded NUL byte in filesystem containment checks
One conflict, in `StorageFile.cpp`. Upstream puts its new `throwIfPathContainsEmbeddedNul` call in `checkCreationIsAllowedResolvingDotDot`, a wrapper that resolves `..` on the filesystem before the containment check and therefore has to reject the path first. That wrapper, and the `resolveDotDotForContainmentCheck` it is built on, do not exist on this branch: the four sites that call it on master call `checkCreationIsAllowed` directly here. The wrapper is dropped and the call is placed at the top of `checkCreationIsAllowed` instead, which is the function the wrapper delegates to and which has no other callers on this branch, so the four sites are covered exactly as upstream covers them. It runs before the `ApplicationType::SERVER` early return, as upstream's does. The other two hunks of the file, the helper itself and the `getPathsList` call, are taken unchanged, as are `filesystemHelpers.cpp` and `LocalObjectStorage.cpp`. Without this the branch would still fail closed - a NUL path reaches `fileOrSymlinkPathStartsWith`, which the same change teaches to report it as not contained - but with DATABASE_ACCESS_DENIED instead of upstream's BAD_ARGUMENTS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #119846
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job