Skip to content

Conversation

@love12yadav
Copy link

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

  • Prevent reuse of proxy SSH sessions
  • Ensure SshClient is closed when sessions are not cached
  • Keep connection reuse behavior unchanged for non-proxy connections

Impact

  • Fixes authentication failures in proxy scenarios
  • Prevents SshClient resource leaks
  • No behavior change for existing reuseConnection flows

Fixes #3925

@love12yadav
Copy link
Author

Hi maintainers 👋
All requested fixes are completed.
Could someone please review the PR and approve the pending workflows when convenient?
Thanks!

@love12yadav
Copy link
Author

Hi maintainers 👋

All requested fixes are now complete.
The merge conflict has been resolved, and the SSH client lifecycle logic has been corrected accordingly.

Could someone please review the PR and approve the pending workflows when convenient?

Thanks!

1 similar comment
@love12yadav
Copy link
Author

Hi maintainers 👋

All requested fixes are now complete.
The merge conflict has been resolved, and the SSH client lifecycle logic has been corrected accordingly.

Could someone please review the PR and approve the pending workflows when convenient?

Thanks!

Copy link
Contributor

Copilot AI left a 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());
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.
CONNECTION_COMMON_CACHE.addCache(identifier, sshConnect);
if (!clientSession.auth()
.verify(timeout, TimeUnit.MILLISECONDS)
.isSuccess()) {
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
.isSuccess()) {
.isSuccess()) {
if (clientSession != null && clientSession.isOpen()) {
clientSession.close();
}

Copilot uses AI. Check for mistakes.
Comment on lines +114 to +119
Iterable<KeyPair> keyPairs =
SecurityUtils.loadKeyPairIdentities(
null,
() -> resourceKey,
new FileInputStream(resourceKey),
passwordProvider);
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.
@zqr10159
Copy link
Member

Please review Copilot's results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ssh monitor with proxyjump, triggering "Too many authentication failures" exception

4 participants