Skip to content

SFTPHookAsync lets a connection known_hosts extra override an explicit constructor path #73584

Closed

Description

@potiuk

SFTPHookAsync._parse_extras() decides whether to take known_hosts from the connection extras with:

if "known_hosts" in extra_options and self.known_hosts != self.default_known_hosts:
    self.known_hosts = extra_options["known_hosts"]

self.known_hosts has already been through os.path.expanduser() in __init__, while default_known_hosts is the literal "~/.ssh/known_hosts". The two never compare equal, so the condition is always true whenever the extra is present: a connection-level known_hosts overrides even a path passed explicitly to the constructor. SSHHookAsync gets this right — it compares against the expanded default and only falls back to the extra when the constructor left the default in place.

Expected: an explicit constructor path wins; the extra applies only when the constructor used the default — consistent with SSHHookAsync.

Regression test: construct SFTPHookAsync(known_hosts="/explicit/known_hosts"), parse a connection with {"known_hosts": "/connection/known_hosts"}, and assert /explicit/known_hosts is kept.

Pre-existing; surfaced during review of #73419 and deliberately left out of that PR's scope.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Activity

  1. abhishekmauryaKsolves commented on Sep 23, 2026

    @abhishekmauryaKsolves
    Contributor

    Hi @potiuk, I'd like to work on this issue. I'll fix the comparison in SFTPHookAsync._parse_extras() to compare against the expanded default (matching SSHHookAsync's pattern) and add the regression test as described.

  2. added a commit that references this issue on Sep 23, 2026
    a361e78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions