fix(python/ssh): confine known_hosts_file to cwd or ~/.ssh - #1428
Open
SashaMIT wants to merge 2 commits into
Open
fix(python/ssh): confine known_hosts_file to cwd or ~/.ssh#1428SashaMIT wants to merge 2 commits into
SashaMIT wants to merge 2 commits into
Conversation
Resolve agent-supplied local_path under process cwd (realpath) before SFTP upload/download so prompt-injected paths cannot read or write arbitrary files.
Extend resolve_safe_local_path with allowed_roots and apply it to ssh_add_host_key so agent paths cannot write arbitrary host-key files. Also catch ValidationError before ValueError (Pydantic subclass).
3 tasks
🟡 Heimdall Review Status
|
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.
Why
Follow-up to #1427 (included in this branch).
ssh_add_host_keystill took agent-controlledknown_hosts_file, expanded~, and wrote with bareopen/makedirs. A prompt-injected path can overwrite arbitrary local files (e.g. plant SSH trust).Default
~/.ssh/known_hostsremains allowed; cwd-relative custom files remain allowed; other absolute paths fail closed.This branch also carries #1427 (
ssh_upload/ssh_downloadcwd confine). Prefer merging this PR and closing #1427 as superseded, or merge #1427 first and rebase this head.Fix
resolve_safe_local_pathwithallowed_roots(cwd +~/.sshfor host keys)ssh_add_host_keyValidationErrorbeforeValueError(Pydantic subclass)Test plan
uv run pytest tests/action_providers/ssh/test_path_utils.py tests/action_providers/ssh/test_upload.py tests/action_providers/ssh/test_download.py tests/action_providers/ssh/test_add_host_key.py(21/21)~/.ssh/known_hostsstill works/etc/...known_hosts path fails closedMade with Cursor