Skip to content

optim(utils): sanitize and clamp subpaths to handle path escaping - #6159

Open
TrafalgarZZZ wants to merge 3 commits into
fluid-cloudnative:masterfrom
TrafalgarZZZ:optim/clean_filepaths
Open

optim(utils): sanitize and clamp subpaths to handle path escaping#6159
TrafalgarZZZ wants to merge 3 commits into
fluid-cloudnative:masterfrom
TrafalgarZZZ:optim/clean_filepaths

Conversation

@TrafalgarZZZ

Copy link
Copy Markdown
Member

Ⅰ. Describe what this PR does

Ⅱ. Does this pull request fix one issue?

fixes #XXXX

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

…oots

Signed-off-by: 东伝 <dongyun.xzh@alibaba-inc.com>
@TrafalgarZZZ TrafalgarZZZ changed the title optim(utils): sanitize and clamp subpaths to handle escaping optim(utils): sanitize and clamp subpaths to handle path escaping Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.64706% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.11%. Comparing base (05f0665) to head (076f0ba).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/csi/plugins/nodeserver.go 68.57% 7 Missing and 4 partials ⚠️
pkg/ddc/base/runtime_helper.go 0.00% 3 Missing and 1 partial ⚠️
pkg/ddc/thin/referencedataset/volume.go 20.00% 2 Missing and 2 partials ⚠️
pkg/ddc/thin/referencedataset/engine.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6159      +/-   ##
==========================================
- Coverage   65.13%   65.11%   -0.02%     
==========================================
  Files         485      485              
  Lines       34039    34090      +51     
==========================================
+ Hits        22171    22198      +27     
- Misses      10127    10144      +17     
- Partials     1741     1748       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Sanitizes Fluid dataset subpaths to prevent lexical parent-directory traversal.

Changes:

  • Adds reusable subpath normalization with unit tests.
  • Applies normalization across dataset references, runtime metadata, CSI mounts, and sidecar injection.
  • Rejects absolute CSI subpaths.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/utils/mount.go Adds subpath normalization helper.
pkg/utils/mount_test.go Tests normalization cases.
pkg/ddc/base/runtime_helper.go Normalizes PV subpaths.
pkg/ddc/base/dataset.go Normalizes referenced-dataset subpaths.
pkg/ddc/base/dataset_test.go Tests reference-path clamping.
pkg/csi/plugins/nodeserver.go Validates and clamps CSI subpaths.
pkg/application/inject/fuse/mutator/mutator_default.go Safely joins sidecar host paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/ddc/base/runtime_helper.go Outdated
Comment thread pkg/csi/plugins/nodeserver.go Outdated
Comment thread pkg/utils/mount.go Outdated
- Reject relative fluid_path values to ensure absolute paths
- Validate fluid_path to be within the configured mount root only
- Disallow fluid_path paths outside mount root

Signed-off-by: 东伝 <dongyun.xzh@alibaba-inc.com>
@fluid-e2e-bot

fluid-e2e-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from trafalgarzzz by writing /assign @trafalgarzzz in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: 东伝 <dongyun.xzh@alibaba-inc.com>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Suppressed comments (1)

pkg/ddc/base/dataset.go:61

  • This error is emitted when there is exactly one mount but its scheme is not dataset://, so saying the dataset should have one mount is inaccurate and hides the actual validation failure.
		return "", fmt.Errorf("the dataset \"%s/%s\" should only have one mount", virtualDataset.Namespace, virtualDataset.Name)


// 2. Reject mountPath if it is a symlink. A symlink planted under the FUSE mount point could
// otherwise redirect the bind mount or the symlink to an arbitrary path on the host.
if isSymlinkFile, err := checkSymlinkFile(mountPath); err != nil {
path = pv.Spec.CSI.VolumeAttributes[common.VolumeAttrFluidPath]
mountType = pv.Spec.CSI.VolumeAttributes[common.VolumeAttrMountType]
subpath = pv.Spec.CSI.VolumeAttributes[common.VolumeAttrFluidSubPath]
if len(subpath) != 0 && !filepath.IsLocal(subpath) {
return errors.Wrapf(err, "failed to get mount root for validating %s \"%s\"", attrName, path)
}

if !utils.IsSubPath(mountRoot, path) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants