Conversation
…ssue #113) When SSH key authentication fails, russh may disconnect the connection before returning the authentication failure result, resulting in SshError(Disconnect) instead of KeyAuthFailed. This prevented the password fallback mechanism from triggering. Changes: - Update is_auth_error_for_password_fallback() to recognize SshError(Disconnect) and SshError(RecvError) as auth failures - Refactor establish_connection() to use the helper function for consistent error classification - Add comprehensive tests for the new error handling - Add integration tests for issue #113 scenarios
Security & Performance ReviewAnalysis Summary
Changes OverviewThis PR fixes issue #113 where password fallback was not working when SSH key authentication fails. The root cause was that the russh library may disconnect the connection before returning Key Changes:
Prioritized IssuesMEDIUM - Potential False Positive Authentication FallbackLocation: Issue: The PR treats
Security Consideration: If a connection fails before authentication is attempted, the user might be prompted for a password unnecessarily. In an adversarial scenario, a MITM attacker could trigger this behavior. Mitigating Factors:
Risk Assessment: The trade-off is acceptable because:
Status: Acceptable - No changes required LOW - Test Coverage Enhancement OpportunityLocation: Issue: Tests cover individual error type classification well, but lack integration-level mock testing for the actual connection flow where:
Recommendation: Consider adding a future integration test with a mock SSH server to validate the end-to-end flow. Status: Acceptable - Current unit tests are sufficient for this fix LOW - Documentation EnhancementLocation: Issue: The documentation is thorough but could note that Recommendation: Consider adding a note like: /// # Heuristics
/// The `Disconnect` and `RecvError` cases are heuristics - these errors
/// may occasionally occur outside of authentication contexts. This trade-off
/// prioritizes OpenSSH-compatible behavior over absolute precision.
Status: Acceptable - Current documentation is adequate Positive Observations
Test ResultsVerdictApproved - The changes correctly address issue #113 with appropriate security considerations. The heuristic approach to treating Checklist
|
Summary
Fixes #113 - Password fallback not working when SSH key authentication fails
When SSH key authentication fails, the russh library may disconnect the connection before returning the authentication failure result. This causes the error to manifest as
SshError(Disconnect)instead ofKeyAuthFailed, which previously prevented the password fallback mechanism from triggering.Changes
is_auth_error_for_password_fallback()function to recognize:SshError(Disconnect)- server disconnects after key auth rejectionSshError(RecvError)- server closes connection during authestablish_connection()to use the helper function for consistent error classificationconnection.rspassword_fallback_test.rsRoot Cause Analysis
The russh library behavior when key authentication fails:
This means the password fallback condition matching was not receiving
KeyAuthFailederror, but insteadSshError(Disconnect).Test plan
SshError(Disconnect)handling passSshError(RecvError)handling pass