fix: Reject root path and narrow path traversal check in createNewFile#1116
fix: Reject root path and narrow path traversal check in createNewFile#1116spolti wants to merge 2 commits intoopendatahub-io:release-v0.15from
Conversation
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>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
/retest |
1 similar comment
|
/retest |
|
/retest |
|
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 coverage looks good LGTM overall, just minor nits above. |
|
/retest |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Co-authored-by: Milind Waykole <mwaykole@redhat.com> Signed-off-by: Filippe Spolti <filippespolti@gmail.com>
|
/retest |
|
Depends on #1125 |
|
/retest |
|
@spolti: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
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
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:
Release note: