fix(security): add CodeQL SafeAccessCheck guard for path injection#121
Merged
Conversation
Add startswith("/") guard after realpath() to satisfy CodeQL's
py/path-injection two-state taint model (code-scanning alert #5).
CodeQL recognizes str.startswith() as a SafeAccessCheck that clears
NormalizedUnchecked taint state. The guard is always true after
realpath() but explicitly rejects relative paths and satisfies the
static analysis requirement.
Regression was introduced in d22ebde (#110) which removed the
startswith(home_dir) guard to allow paths outside ~/. This fix
restores CodeQL compliance without re-restricting allowed paths.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
fix(security): resolve CodeQL py/path-injection alert in tmux client
Summary
py/path-injection: Uncontrolled data used in path expression)startswith("/")guard afterrealpath()to satisfy CodeQL's two-state taint modelRoot Cause
PR #110 (
d22ebde) relaxed the working directory validation to allow paths outside~/(e.g.,/Volumes/workplaceon macOS). This removed thestartswith(home_dir)guard that CodeQL relied on as aSafeAccessCheckto clear taint from user-supplied paths. Therealpath()normalization was still present, but CodeQL requires both normalization + astartswithcheck to consider a path safe.Fix
Added an explicit
startswith("/")guard betweenrealpath()and filesystem operations. This satisfies CodeQL'sPathNormalization → SafeAccessChecktwo-state model:os.path.realpath()— transitions taint toNormalizedUncheckedstr.startswith("/")— recognized by CodeQL asSafeAccessCheck→ clears taintThe guard is always true after
realpath()on POSIX systems but explicitly rejects relative paths and satisfies the static analysis requirement without re-restricting allowed directories.Test plan
test_tmux_working_directory.pytests pass~/still allowed (PR Fixes the400 Bad Requesterror when launching agents in directories outside~/, such as/Volumes/workplaceon macOS. #110 behavior preserved)