Skip to content

Normalize relative File() backup paths before the backups.allowed_path check - #125911

Merged
jkartseva merged 3 commits into
ClickHouse:masterfrom
groeneai:backup-file-relative-path-allowed-path-dot
Oct 15, 2026
Merged

jkartseva merged 3 commits into
ClickHouse:masterfrom
groeneai:backup-file-relative-path-allowed-path-dot

Conversation

@groeneai

@groeneai groeneai commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125871
Related: #111394

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix the backups.allowed_path check for relative File() backup destinations: the destination is now normalized before the check, so a relative path whose .. leaves every allowed entry is rejected even when one allowed entry contains another. Closes #125871.

Description

On 26.9, a relative File() destination whose .. leaves the first backups.allowed_path entry is accepted when a later entry contains the first one, and the backup is written outside every entry: the destination is joined with the first entry without normalization and the later entry then matches it lexically.

On master, #111394 normalizes the entries but not the joined path, so BACKUP ... TO File('b1') and RESTORE ... FROM File('b1') fail with BAD_ARGUMENTS when the first entry is not in lexical normal form (/w/./backups, /w/sub/../backups, or a relative ../backups). With clickhouse-local and a relative --path, the area also stays relative, and when it does not exist yet the directory fsync added by #111394 fails with Cannot open directory for fsync.

The data path is made absolute and the joined path is normalized before the check. A relative path now resolves exactly like its absolute spelling: a .. that comes back into an allowed entry (File('../backups/b2')) is accepted, and a path that ends outside every entry is rejected. Like absolute paths and the entries, the joined path is normalized lexically, so a .. that follows a symbolic link in an entry, or in the data path a relative entry is resolved against, no longer goes through the link as it did in 26.9. Absolute File('/...') destinations and Disk() are not affected.

The new test covers five cases (four spellings of the entry and --path, and overlapping entries), the re-entry, and escapes that must be rejected. It fails on master and passes with the fix (50/50 randomized runs); the existing backup tests show no new failures.

A backport to 26.9 or older also needs the entry normalization from #111394: with raw entries, a normalized path is rejected under an entry like /w/./backups.


Workflow [PR]
Sync PR [sync-upstream/pr/125911]

Version info

  • Merged into: 26.11.1.3-master (included in 26.11 and later)

groeneai and others added 3 commits October 14, 2026 22:25
…r .. components

checkPath joined a relative File() destination with the raw first
backups.allowed_path entry, while ClickHouse#111394 started comparing it with the
lexically normalized entries. When the first entry was not in normal form
(`/w/./backups`, `/w/sub/../backups`, or a relative `../backups` resolved
against the data path), lexically_proximate returned a path starting with
`..` and every entry was rejected with BAD_ARGUMENTS. Absolute paths were
not affected because they are normalized before the check.

Normalize the joined path as well, so a relative destination resolves
exactly like its absolute spelling: a `..` that comes back into an allowed
entry is accepted, one that ends outside every entry is still rejected.

Closes ClickHouse#125871

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-local keeps a relative --path as given, so a relative
backups.allowed_path entry resolved to a relative backup area (for
example `--path ./data` with `../backups`, or `--path .` with
`backups`). The directory fsync added by ClickHouse#111394 assumes an absolute
area: for a relative one that does not exist yet, the boundary walk in
the BackupWriterFile constructor climbs to the empty path, and BACKUP
fails with `Cannot open directory  for fsync` after writing the whole
backup. 26.9 accepted these spellings.

Make the data path absolute before checkPath joins it. fs::absolute is
lexical, like the rest of checkPath, and is the identity for the server,
whose path is already absolute. The test gets the relative --path arm.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ancestor entry

With overlapping backups.allowed_path entries where a later entry
contains the first one, a relative destination such as
`../../escape` was joined with the first entry without normalization,
and the later entry then matched the joined path lexically
(`backups/../../escape` does not start with `..`), so the backup was
written outside every entry. The normalization of the joined path
in checkPath closes this; add the overlapping-entry case to 05398 so
that a revert of it fails the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 rounds, 2 findings, the last round clean) plus my own review (3 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ clickhouse-local with a relative --path: the area stayed relative and the fsync walk recorded "" AGREE, fixed @ 088d776 the data path is made absolute before the join; test arm relative_data_path
2 ❌ lexical normalization relocates a relative path when a .. in the entry follows a symlink DISAGREE master already rejects that spelling (measured with sub/../backups); the path now resolves where its absolute spelling and the normalized entries resolve, so the checked path is the written one; stated in the description
3 ⚠️ overlapping entries (a later entry contains the first): a relative path leaving every entry was accepted and not covered by the test AGREE, fixed @ e1d6e61 measured on 26.9.16.11, 26.3.42.3 and master (backup written outside both entries), rejected with the fix; test case overlapping added
4 💡 leftover cd in the test once the relative-data-path arm was gone AGREE, fixed @ 088d776 the arm is restored

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261015-001800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pamarcos @jkartseva, could you review this and add can be tested? Since #111394, checkPath normalizes the backups.allowed_path entries but joins a relative File() destination with the raw first entry, so File('b1') is rejected when that entry contains . or ..; the fix normalizes the joined path and makes the data path absolute.

@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1d6e61]

Summary: ✅


AI Review

Summary

The PR normalizes relative File backup destinations before checking backups.allowed_path and resolves relative data directories to absolute paths. This restores valid relative backup and restore destinations and rejects escapes through overlapping allowed entries. No actionable findings at e1d6e6153dc1; the focused regression test 05398_backup_file_relative_path_allowed_path_dot passes in Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 15, 2026
@jkartseva jkartseva self-assigned this Oct 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Oct 15, 2026
@jkartseva jkartseva added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e1d6e6153 with master 324e8a3a1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline.

Job report

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jkartseva
jkartseva added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit d93763c Oct 15, 2026
521 of 525 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-backup Backup/restore infrastructure and backup formats. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relative File() backup paths rejected when allowed_path contains ./..

3 participants