Skip to content

fix(security): resolve CodeQL py/path-injection alert#516

Merged
cheng-tan merged 2 commits into
mainfrom
fix/codeql-path-injection
May 21, 2026
Merged

fix(security): resolve CodeQL py/path-injection alert#516
cheng-tan merged 2 commits into
mainfrom
fix/codeql-path-injection

Conversation

@cheng-tan

@cheng-tan cheng-tan commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Drop the redundant Path(n).expanduser().resolve() before validate_host_path(). That function already calls os.path.realpath() internally before applying the denylist, so we were resolving the path twice. Replace with the lighter os.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_path logs a Mount 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.

cheng-tan added 2 commits May 21, 2026 15:55
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.
@cheng-tan
cheng-tan merged commit eb93c51 into main May 21, 2026
13 checks passed
@cheng-tan
cheng-tan deleted the fix/codeql-path-injection branch May 21, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant