Skip to content

fix: Reject root path and narrow path traversal check in createNewFile#1116

Open
spolti wants to merge 2 commits intoopendatahub-io:release-v0.15from
spolti:pathTraversal
Open

fix: Reject root path and narrow path traversal check in createNewFile#1116
spolti wants to merge 2 commits intoopendatahub-io:release-v0.15from
spolti:pathTraversal

Conversation

@spolti
Copy link
Member

@spolti spolti commented Feb 13, 2026

chore: Changes on pkg/agent/storage/https.go:
1. Added "/" to the invalid path rejection (root filesystem path)
2. Changed strings.Contains(fileFullName, "..") to strings.HasPrefix(fileFullName, "..")
— after filepath.Clean, .. can only survive at the start of relative paths, so Contains was overly broad and would false-positive on legitimate filenames like "file..v2.bin"
3. Reordered checks: cheap rejections (".", "", "/") now come before the protected-paths loop

   Test updated to reflect the changes.

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Feature/Issue validation/testing:

  • Test A

  • Test B

  • Logs

Special notes for your reviewer:

Checklist:

  • Have you added unit/e2e tests that prove your fix is effective or that this feature works?
  • Has code been commented, particularly in hard-to-understand areas?
  • Have you made corresponding changes to the documentation?
  • Have you linked the JIRA issue(s) to this PR?

Release note:


chore: Changes on pkg/agent/storage/https.go:
        1. Added "/" to the invalid path rejection (root filesystem path)
        2. Changed strings.Contains(fileFullName, "..") to strings.HasPrefix(fileFullName, "..")
        	 — after filepath.Clean, .. can only survive at the start of relative paths, so Contains was overly broad and would false-positive on legitimate filenames like "file..v2.bin"
        3. Reordered checks: cheap rejections (".", "", "/") now come before the protected-paths loop

       Test updated to reflect the changes.

Signed-off-by: Spolti <fspolti@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@spolti
Copy link
Member Author

spolti commented Feb 16, 2026

/retest

1 similar comment
@spolti
Copy link
Member Author

spolti commented Feb 16, 2026

/retest

@spolti
Copy link
Member Author

spolti commented Feb 16, 2026

/retest

@mwaykole
Copy link
Member

mwaykole commented Feb 16, 2026

Hey @spolti, took a look at this PR.

The security improvements here make sense - protecting system directories and tightening up the path traversal check is the right call.

Few things I noticed:

  • The test file header says 2023 but it's new code, might want to bump that to 2026
  • Might be worth adding /proc, /sys, /lib to the protected list too since those are equally sensitive
  • Some of the success tests (like /tmp/test/model.bin) assume parent directories exist - using t.TempDir() would make the tests more reliable across different environments

The test coverage looks good

LGTM overall, just minor nits above.

@opendatahub-io opendatahub-io deleted a comment from openshift-ci bot Feb 16, 2026
@spolti
Copy link
Member Author

spolti commented Feb 16, 2026

/retest

@openshift-ci
Copy link

openshift-ci bot commented Feb 16, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jlost, mwaykole, spolti

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

The pull request process is described 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

Co-authored-by: Milind Waykole <mwaykole@redhat.com>
Signed-off-by: Filippe Spolti <filippespolti@gmail.com>
@spolti
Copy link
Member Author

spolti commented Feb 16, 2026

/retest

@spolti
Copy link
Member Author

spolti commented Feb 19, 2026

Depends on #1125

@spolti
Copy link
Member Author

spolti commented Feb 25, 2026

/retest

@openshift-ci
Copy link

openshift-ci bot commented Feb 25, 2026

@spolti: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-llm-inference-service 94b14f3 link true /test e2e-llm-inference-service
ci/prow/e2e-predictor 94b14f3 link true /test e2e-predictor

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: New/Backlog

Development

Successfully merging this pull request may close these issues.

3 participants