-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(security): improve path traversal validation with comprehensive test #25515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
🔴 Preview Environment stopped on BunnyshellSee: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25515 +/- ##
==========================================
+ Coverage 62.45% 62.48% +0.03%
==========================================
Files 351 351
Lines 49490 49495 +5
==========================================
+ Hits 30910 30928 +18
+ Misses 15621 15606 -15
- Partials 2959 2961 +2 ☔ View full report in Codecov by Sentry. |
ppapapetrou76
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - nice
Clean and concise
| } | ||
| return requestedDir + string(filepath.Separator) + requestedFile, nil | ||
| } | ||
| cleanRoot := filepath.Clean(currentRoot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please use os.Root for this?
blakepettersson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment
5dbf279 to
d264016
Compare
…ests Signed-off-by: Duncan Kibet <[email protected]>
76bcf07 to
3951087
Compare
2818859 to
2daa044
Compare
2daa044 to
3951087
Compare
8d91975 to
3079182
Compare
Signed-off-by: Duncan Kibet <[email protected]>
3079182 to
ad247a1
Compare
|
@blakepettersson, as requested, I have made the necessary changes. I've also incorporated the necessary path normalization changes from PR #25370 into this branch to ensure all tests pass. The path normalization changes were needed because the security refactor's tests require properly cleaned paths to validate correctly. If the changes are now in line with what you suggested, then we can close the other PR. |
Description
This PR enhances the security logic in
EnforceToCurrentRootby refactoring it to usefilepath.Relfor validation. This serves as a security hardening improvement for the path traversal logic discussed in #25370.Instead of manual string prefix checking, this implementation uses Go's standard library to robustly handle complex paths (including
..notation), ensuring strict directory containment.Implementation changes
filepath.Relfor lexical containment.filepath.Cleanto normalize paths before validation...to detect and block escape attempts.Test improvements
Related
Checklist: