fix(security): resolve CodeQL py/path-injection alert#516
Merged
Conversation
CodeQL flagged Path(n).expanduser().resolve() in two spots as py/path-injection: a user-controlled value (mount_dirs / host_dirs) flowing into a path construct. The code is actually safe because validate_host_path() runs immediately after — it calls os.path.realpath() and enforces a denylist, raising ValueError for any path outside the allowed set. The Path().resolve() step was redundant with what validate_host_path already does internally. Replace with the lighter os.path.expanduser() which only does string-level ~ expansion (no filesystem touch). The behavior is unchanged; CodeQL no longer sees user input flowing into a path-handling construct before sanitization. Both call sites updated: - backend/teammanager/teammanager.py:450 - sandbox/_quicksand.py:273
Reword inline comments to accurately describe what validate_host_path enforces (existence/is_dir + denylist) rather than the misleading 'outside the allowed set' phrasing.
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.
Drop the redundant
Path(n).expanduser().resolve()beforevalidate_host_path(). That function already callsos.path.realpath()internally before applying the denylist, so we were resolving the path twice. Replace with the lighteros.path.expanduser()(string-only, no filesystem access).Behavior is functionally unchanged. The CodeQL py/path-injection signal no longer fires because user input no longer flows into a path construct before the sanitizer.
One side effect:
validate_host_pathlogs aMount audit: path resolves through symlink ...warning when realpath differs from abspath. The previous pre-resolve was silently suppressing that audit for symlinked mount dirs — now it'll surface in the logs as intended.