-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix: Properly close SshClient and avoid reusing proxy SSH sessions #3944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi maintainers 👋 |
|
Hi maintainers 👋 All requested fixes are now complete. Could someone please review the PR and approve the pending workflows when convenient? Thanks! |
1 similar comment
|
Hi maintainers 👋 All requested fixes are now complete. Could someone please review the PR and approve the pending workflows when convenient? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request addresses SSH ProxyJump authentication leakage issues in Apache MINA SSHD by preventing reuse of proxy SSH sessions and ensuring proper resource cleanup.
Changes:
- Modified connection caching logic to exclude proxy connections from reuse (
reuseConnection && !useProxy) - Added exception handling to close ClientSession on failures in proxy scenarios
- Improved error logging messages for better diagnostics
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Apache SSHD requires the password for the proxy to be preloaded into the sshClient instance before connecting | ||
| if (StringUtils.hasText(sshProtocol.getProxyPassword())) { | ||
| sshClient.addPasswordIdentity(sshProtocol.getProxyPassword()); |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding proxy password to the shared SshClient instance creates a potential security issue. Since CommonSshClient.getSshClient() returns a singleton SSH_CLIENT that is shared across all connections, adding a proxy password here will persist on that client instance and could leak to subsequent connections. This proxy password should be removed after use or the password identity should be added to the session instead of the client.
| CONNECTION_COMMON_CACHE.addCache(identifier, sshConnect); | ||
| if (!clientSession.auth() | ||
| .verify(timeout, TimeUnit.MILLISECONDS) | ||
| .isSuccess()) { |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authentication failure does not close the clientSession before throwing the exception. This creates a resource leak. The clientSession should be closed here similar to line 129 in the first method.
| .isSuccess()) { | |
| .isSuccess()) { | |
| if (clientSession != null && clientSession.isOpen()) { | |
| clientSession.close(); | |
| } |
| Iterable<KeyPair> keyPairs = | ||
| SecurityUtils.loadKeyPairIdentities( | ||
| null, | ||
| () -> resourceKey, | ||
| new FileInputStream(resourceKey), | ||
| passwordProvider); |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This FileInputStream is not always closed on method exit.
| Iterable<KeyPair> keyPairs = | |
| SecurityUtils.loadKeyPairIdentities( | |
| null, | |
| () -> resourceKey, | |
| new FileInputStream(resourceKey), | |
| passwordProvider); | |
| Iterable<KeyPair> keyPairs; | |
| try (InputStream is = new FileInputStream(resourceKey)) { | |
| keyPairs = | |
| SecurityUtils.loadKeyPairIdentities( | |
| null, | |
| () -> resourceKey, | |
| is, | |
| passwordProvider); | |
| } |
|
Please review Copilot's results. |
Problem
When using SSH ProxyJump, Apache MINA SSHD may leak authentication state.
Reusing sessions or incorrectly closing SshClient could cause the first
connection to fail or leave resources open.
Solution
Impact
Fixes #3925