fix(ssh): ensure environment variable algorithms are always honored#473
Merged
billchurch merged 2 commits intomainfrom Jan 27, 2026
Merged
fix(ssh): ensure environment variable algorithms are always honored#473billchurch merged 2 commits intomainfrom
billchurch merged 2 commits intomainfrom
Conversation
The ssh2 library uses its own DEFAULT_KEX algorithms when none are explicitly passed to client.connect(). This caused user-provided algorithm configuration via environment variables (e.g., WEBSSH2_SSH_ALGORITHMS_KEX) to be silently ignored in edge cases. Changes: - Always pass algorithms to ssh2 with fallback to server config defaults - Add debug logging for config loading timeline and algorithm values - Add per-connection algorithm logging in ssh-config adapter - Add startup verification logging with algorithm summary - Fix test mocks to include proper ssh.algorithms configuration The fix ensures legacy SSH servers (e.g., those only supporting diffie-hellman-group14-sha1) can connect when users configure the appropriate algorithms via environment variables.
Replace async mainAsync wrapper with top-level await for cleaner initialization code. Use direct export...from syntax for re-exports. Addresses SonarLint rules S7785 and S7763.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Ensures user-provided SSH algorithm environment variables (e.g.,
WEBSSH2_SSH_ALGORITHMS_KEX) are always honored by WebSSH2.Problem
Problem reported that SSH algorithm environment variables were ignored on first connections but worked on reconnects. Investigation revealed:
DEFAULT_KEXalgorithms when none are explicitly passed toclient.connect()DEFAULT_KEXonly includes modern algorithms (curve25519, ecdh-nistp*, etc.)SUPPORTED_KEXincludes legacy algorithms likediffie-hellman-group14-sha1This caused connections to legacy SSH servers (e.g., those only supporting
diffie-hellman-group14-sha1) to fail even when users correctly configured the algorithm via environment variables.Root Cause
In
app/services/ssh/ssh-service.ts, thebuildConnectConfig()method only passed algorithms to ssh2 whenconfig.algorithms !== undefined. In edge cases where the connection config lacked algorithms, ssh2 would use its own defaults instead of the server's configured defaults (which honor env vars).Solution
Always explicitly pass algorithms to ssh2, using server config defaults as fallback:
Changes
app/services/ssh/ssh-service.tsapp/config.tsapp/socket/adapters/ssh-config.tsindex.tstests/test-utils.tsssh.algorithmstests/unit/socket-v2-test-utils.tsssh.algorithmstests/unit/socket-v2-exec-edge-cases.vitest.tsVerification
1. Test with Custom Algorithms
Expected: Config loading should show env vars being read, startup log should show custom KEX algorithms.
2. Test with Legacy SSH Server
Connect to a legacy SSH server - should succeed now.
3. Verify Fallback Warning
The warning
WARNING: No algorithms in connection config, using server defaultsshould NOT appear in normal operation. If it does, it indicates a bug in the config passing flow.Test plan