fix: support mongodb+srv:// connection URLs with SSH tunnels - #1433
Open
nick22985 wants to merge 5 commits into
Open
fix: support mongodb+srv:// connection URLs with SSH tunnels#1433nick22985 wants to merge 5 commits into
nick22985 wants to merge 5 commits into
Conversation
nick22985
force-pushed
the
fix/mongodb-srv-ssh-tunnel
branch
from
April 16, 2026 03:44
6431730 to
57c46d8
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds SSH SOCKS5 proxy support so MongoDB mongodb+srv:// connections can work through SSH tunneling without rewriting the URL (SRV URIs cannot include a port). This integrates with the existing SSH tunnel infrastructure and lets drivers choose between traditional local port-forwarding and SOCKS mode.
Changes:
- Introduced a driver hook (
getSSHTunnelMode) and implemented it in the MongoDB driver to select SOCKS mode formongodb+srv://URLs. - Extended SSH tunnel plumbing (
getSshTunnel*, forked forward process) to support a newmode: 'socks'. - Implemented a minimal local SOCKS5 server in
SSHConnectionand wired the MongoDB driver to passproxyHost/proxyPortto the MongoDB Node driver.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/dbgate-plugin-mongo/src/backend/drivers.js | Adds getSSHTunnelMode and uses MongoDB driver SOCKS proxy options when tunneling SRV URLs. |
| packages/api/src/utility/sshTunnelProxy.js | Passes tunnel “options” through IPC proxy layer. |
| packages/api/src/utility/sshTunnel.js | Adds tunnel mode selection + caching keying and forwards mode to forked process. |
| packages/api/src/utility/connectUtility.js | Chooses tunnel mode per-driver and sets either local forward host/port or SOCKS proxy host/port on the connection. |
| packages/api/src/utility/SSHConnection.js | Adds SOCKS5 server implementation using forwardOut per CONNECT. |
| packages/api/src/proc/sshForwardProcess.js | Starts either forward() or socksForward() based on mode. |
| packages/api/src/controllers/databaseConnections.js | Applies the same tunnel mode selection for native op command args flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
mongodb+srv://connection URLs crashed withMongoParseError: mongodb+srv URI cannot have port numberwhen used with SSH tunnelsmongodb://connections with SSH tunnels are unchangedHow it works
getSSHTunnelMode(connection)returning'socks'or'forward''socks'formongodb+srv://URLsforwardOutproxyHost/proxyPort) handles the rest. DNS SRV resolution and connections to all replica set members go through the proxy transparentlyCloses: #1343