Repository navigation
fix(mongodb): connect to exactly the validated host - #10473
Conversation
validateDatabaseHost now refuses anything but a single hostname or IP literal before resolving it, so a seed list, userinfo, port, path or options can no longer pass the address check while the driver connects elsewhere. The MongoDB client builds its connection string from the validated host and port only, passes credentials, authSource and TLS as driver options, sets directConnection so server-advertised members are never followed, and validates the port and database name.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
[High impact] The PR appears safe to merge with the documented single-node connection behavior. SummaryThis PR keeps MongoDB connections tied to the checked host.
waleedlatif1 explicitly documented that connecting to a secondary no longer discovers the primary; writes require the primary’s host. Tests were inspected, not run during this review.
|
There was a problem hiding this comment.
All reported issues were addressed across 6 files
This PR changes authentication, authorization, or input validation. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.
Turn on auto-fix | Re-trigger cubic
Summary
validateDatabaseHostnow accepts exactly one hostname or IP literal and refuses anything with,/@?#:(outside an IPv6 literal), brackets around a non-IPv6 value, whitespace, or an IPv6 zone id, before any DNS lookup. Previously it resolved the whole string, so with a wildcard DNS zone a value like127.0.0.1:6379,db.attacker.examplepassed the check while the MongoDB driver split it into a seed list and connected to every seed; literal IP seeds never go through the pinnedlookup, so loopback/private addresses were reachableauthSourceand TLS go through the driver options object, sodatabase/authSourcecan no longer append or duplicate connection-string options (directConnection,proxyHost/proxyPort,tls,authMechanism, ...)directConnection: trueso the driver never follows replica-set members a server advertises, validates the port as an integer in 1–65535, and checks the database name against MongoDB's naming rules.authSourcestill defaults to the database when credentials are givenvalidateDatabaseHost(PostgreSQL, MySQL, MSSQL, Neo4j, ClickHouse, Redis, SMTP, IMAP, SFTP, SSH, Oracle CONNECT proxy) pass the host as a single driver field or into a URL built after validation and connect to the pinned resolved IP; the stricter shape check closes the same multi-host/userinfo shapes for Neo4j and ClickHouse, which interpolate the host into a URIBehavior change: a MongoDB host that is a replica-set secondary now connects to that node only instead of discovering the primary, so writes need the primary's host.
Type of Change
Testing
lib/core/security/input-validation.server.test.ts: seed lists, userinfo, path/options, fragment, port suffix, bracketed name, zone id and whitespace are refused before resolution (resolver mocked to answer like a wildcard zone); DNS names, underscore service names, trailing-dot names, IPv4 and bare/bracketed IPv6 are acceptedlib/internal/mongodb/client.test.tsagainst the realMongoClientoption parser (onlyconnect/closestubbed): one host,directConnection: true, no proxy, TLS and credentials from options; seed-list and option-injecting hosts, option-injecting/invalid database names, and out-of-range ports are refused before connectingproxyHostdatabase, which connected on the old code); all pass with the fixlib/internal/{ssh,sftp,redis,mysql,postgresql,mssql,neo4j,clickhouse,smtp,oracledb,mongodb},lib/imap,lib/core/security): 51 files passbun run generate,bun run lint,bun run type-check,bun run check:auditsChecklist
test-auditauthoring gate)