[Backport] Validate base_path in FsRepository to prevent path.repo containment bypass - #22381
Conversation
…ypass (opensearch-project#22328) The fs repository base_path setting was read verbatim from REST input with no validation. An absolute base_path causes Path.resolve to discard the path.repo-validated location, redirecting all blob-store operations outside the repository (CWE-22) and enabling arbitrary filesystem deletion via the snapshot _cleanup API. Add two layers of defense: - BASE_PATH_SETTING validator rejects absolute and upward-escaping (..) values after normalization (benign interior '..' that cancels out is allowed). - validateBasePathWithinRepo() resolves base_path against the location and verifies the result stays within a configured path.repo directory. Signed-off-by: Aditya Khera <kheraadi@amazon.com> Co-authored-by: Aditya Khera <kheraadi@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.19 #22381 +/- ##
============================================
+ Coverage 71.92% 72.11% +0.18%
+ Complexity 66009 64486 -1523
============================================
Files 5342 5121 -221
Lines 307392 300247 -7145
Branches 44862 44095 -767
============================================
- Hits 221105 216532 -4573
+ Misses 67823 65525 -2298
+ Partials 18464 18190 -274 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
The fs repository base_path setting was read verbatim from REST input with no validation. An absolute base_path causes Path.resolve to discard the path.repo-validated location, redirecting all blob-store operations outside the repository (CWE-22) and enabling arbitrary filesystem deletion via the snapshot _cleanup API.
Add two layers of defense:
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.