Skip to content

Cherry pick #119846 to 26.7: Reject paths with an embedded NUL byte in filesystem containment checks - #120789

Merged
PedroTadim merged 7 commits into
backport/26.7/119846from
cherrypick/26.7/119846
Sep 18, 2026
Merged

PedroTadim merged 7 commits into
backport/26.7/119846from
cherrypick/26.7/119846

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 6 commits September 13, 2026 20:01
`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
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Sep 18, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants