Skip to content

fix(python/ssh): confine known_hosts_file to cwd or ~/.ssh - #1428

Open
SashaMIT wants to merge 2 commits into
coinbase:mainfrom
SashaMIT:fix/python-ssh-host-key-path
Open

fix(python/ssh): confine known_hosts_file to cwd or ~/.ssh#1428
SashaMIT wants to merge 2 commits into
coinbase:mainfrom
SashaMIT:fix/python-ssh-host-key-path

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Aug 9, 2026

Copy link
Copy Markdown

Why

Follow-up to #1427 (included in this branch). ssh_add_host_key still took agent-controlled known_hosts_file, expanded ~, and wrote with bare open / makedirs. A prompt-injected path can overwrite arbitrary local files (e.g. plant SSH trust).

Default ~/.ssh/known_hosts remains allowed; cwd-relative custom files remain allowed; other absolute paths fail closed.

This branch also carries #1427 (ssh_upload / ssh_download cwd confine). Prefer merging this PR and closing #1427 as superseded, or merge #1427 first and rebase this head.

Fix

  • Extend resolve_safe_local_path with allowed_roots (cwd + ~/.ssh for host keys)
  • Apply to ssh_add_host_key
  • Catch ValidationError before ValueError (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)
  • Default ~/.ssh/known_hosts still works
  • /etc/... known_hosts path fails closed

Made with Cursor

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).
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions Bot added action provider New action provider python labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider python

Development

Successfully merging this pull request may close these issues.

2 participants