security(utilities): harden path traversal validation in safe_extract#12347
Merged
StpMax merged 2 commits intoApr 17, 2026
Merged
Conversation
Replaced the flawed os.path.commonprefix check with a robust os.path.relpath validation in __is_within_directory. The previous implementation was susceptible to bypasses where a target path started with the same prefix as the directory (e.g., /app/data and /app/data-secret). Added more descriptive error messages to safe_extract to provide better context when a traversal attempt is detected.
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
|
I have read the CLA Document and I hereby sign the CLA |
StpMax
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a security vulnerability in the path traversal validation logic within mindsdb/utilities/fs.py.
The previous implementation relied on os.path.commonprefix, which performs a character-by-character string comparison rather than a path-component-aware check. This made the validation susceptible to bypasses where a malicious target path shares a prefix with the intended directory but resides outside of it (e.g., /app/data incorrectly validating /app/data-secret).
Changes:
detected, aiding in security auditing and debugging.
Fixes # (if there is a related issue, otherwise leave blank)
Type of change
Verification Process
To ensure the changes are working as expected:
Checklist: