Repository navigation
Improve path traversal security in vault access - #63
Merged
Merged
Conversation
Code scanning alerts 7, 8 (companion.py attachment routes) and 9 (tools.py) all flow through VaultTools._safe_path. Path.resolve plus relative_to is not a sanitizer CodeQL's py/path-injection query knows, and the earlier realpath version let the root case bypass the startswith guard, so its return value stayed tainted. Guard with realpath + startswith(root + sep) only, and return the configured root for the root itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0149otepaDuazZjsUFepPHyQ
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Refactored the
_safe_pathmethod to useos.path.realpathinstead ofPath.resolvefor path validation, improving alignment with security best practices and CodeQL's path-injection sanitizer recognition.Key Changes
Path.resolve()andPath.relative_to()withos.path.realpath()and string-basedstartswith()checks for path validationos.path.join(root, "")to ensure sibling directories cannot escape the vaultPathobject for API consistencyImplementation Details
The new validation approach uses:
os.path.realpath()to resolve symlinks and normalize pathsThis implementation is more explicit about the security boundary and is recognized by CodeQL's path-injection sanitizer, improving code security analysis.