Skip to content

Reject path traversal in file names from part checksums - #120356

Merged
alesapin merged 3 commits into
masterfrom
checksums-reject-path-traversal
Sep 17, 2026
Merged

alesapin merged 3 commits into
masterfrom
checksums-reject-path-traversal

Conversation

@alesapin

@alesapin alesapin commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

File names read from checksums.txt were stored without validation and later used verbatim to build paths inside the part directory, both in MergeTreeDataPartChecksum::checkSize and when the part directory is cleared on removal. A forged checksums.txt could therefore reference files outside the part directory.

Validate names in MergeTreeDataPartChecksums::readV2 and readV3 (readV4 delegates to readV3): reject empty names, absolute names and names containing . or .. path components with
UNEXPECTED_FILE_IN_DATA_PART.

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):

Now ClickHouse reject relative paths in checksums.txt.


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

Version info

  • Merged into: 26.10.1.19 (included in 26.10 and later)
  • Backported to: 26.9.1.1597, 26.8.7.12, 26.6.9.13, 26.3.33.102

File names read from `checksums.txt` were stored without validation and
later used verbatim to build paths inside the part directory, both in
`MergeTreeDataPartChecksum::checkSize` and when the part directory is
cleared on removal. A forged `checksums.txt` could therefore reference
files outside the part directory.

Validate names in `MergeTreeDataPartChecksums::readV2` and `readV3`
(`readV4` delegates to `readV3`): reject empty names, absolute names and
names containing `.` or `..` path components with
`UNEXPECTED_FILE_IN_DATA_PART`.

Related: ClickHouse/clickhouse-private#72532

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7615af5]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected A, found B (STID: 2270-3184) FAIL cidb, issue ISSUE CREATED
Stress test (arm_debug) FAIL
Cannot start clickhouse-server FAIL cidb, issue ISSUE CREATED
Check failed FAIL cidb, issue ISSUE CREATED
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED
Build profile diff ERROR IGNORED

AI Review

Summary

This PR closes the original path-traversal bug by validating file names while parsing MergeTree part checksums.txt: the current head now rejects empty names, absolute names, . / .. path components, and embedded NUL bytes before those names reach the file-size and part-removal paths. I traced the shared parser call sites used by part load, CHECK TABLE, detached-part handling, projection cleanup, and the read-checksums utility, and I did not find a remaining traversal bypass in the code that currently lands. The remaining concern is evidence rather than control flow: the PR still merges a security-sensitive parser change without any regression coverage for a forged checksums.txt, so I do not think it is ready to merge yet.

Findings

⚠️ Majors

  • [src/Storages/MergeTree/MergeTreeDataPartChecksum.cpp:186,224] [dismissed by author -- https://github.com/Reject path traversal in file names from part checksums #120356#discussion_r4025007444] The fix is security-sensitive and easy to regress, but this PR still adds no test that actually forges a part checksums.txt and proves one of the supported load paths rejects it with UNEXPECTED_FILE_IN_DATA_PART. That leaves the change without the proof required by the PR’s contract even though the nearby test surface already exists: tests/queries/0_stateless/04326_disks_app_read_checksums.sh can cheaply grow a negative read-checksums case, or a focused MergeTree shell test can rewrite a real part’s checksums.txt and verify CHECK TABLE / reload rejects it.
Final Verdict

⚠️ Needs changes before merge: add a focused regression test for forged file names in part checksums.txt.

LLVM Coverage Report

Measured on commit 7615af5.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 13/24 (54.17%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 7615af54d74d2744aa9d57fea88053d7544d7d5e with master failed: RuntimeError: CI logs cluster query failed: SELECT count() AS c FROM binary_sizes W….

See the job log for details.

alesapin and others added 2 commits September 16, 2026 18:13
`readStringBinary` accepts embedded NUL bytes and `std::filesystem::path`
keeps them inside a single component, so a name like `"..\0/x"` passed the
`..` component check. On local disks the joined path is then handed to C
APIs which truncate at the first NUL, so it acted as `..` and escaped the
part directory. Reject names containing `\0` before splitting them into
components.

Addresses: #120356 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alesapin

Copy link
Copy Markdown
Member Author

It's important bugfix, can be merged red.

@alesapin alesapin added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 17, 2026
@alesapin
alesapin added this pull request to the merge queue Sep 17, 2026
Merged via the queue into master with commit ffb12c0 Sep 17, 2026
172 of 177 checks passed
@alesapin
alesapin deleted the checksums-reject-path-traversal branch September 17, 2026 10:31
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 17, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 17, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #120356 to 26.8: Reject path traversal in file names from part checksums
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #120356 to 26.9: Reject path traversal in file names from part checksums
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #120356 to 26.6: Reject path traversal in file names from part checksums
clickgapai added a commit to clickgapai/ClickHouse that referenced this pull request Sep 17, 2026
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Backport #120356 to 26.3: Reject path traversal in file names from part checksums
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
PedroTadim added a commit that referenced this pull request Sep 18, 2026
Backport #120356 to 26.7: Reject path traversal in file names from part checksums
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

3 participants