Conversation
extractDatabaseFromMongoUri ran decodeURIComponent on the URI path without guarding against URIError. URL parsing does not validate percent-encoding, so a connection string whose database path contains a literal "%" or truncated escape (for example db%zz) crashed the relay with an uncaught URIError before any validation could run. Treat an undecodable path like an unparseable URI and return null, which matches the existing URL.canParse guard just above. Adds a regression test that fails with URIError: URI malformed before the fix.
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.
What
extractDatabaseFromMongoUriinpackages/server/src/services/mongodb/relay.tsrandecodeURIComponenton the connection-string path without guarding againstURIError.Why
URL.canParse/new URL(...)do not validate percent-encoding, so a MongoDB connection string whose database path contains a literal%or a truncated escape (for examplemongodb://user:pass@host:27017/db%zz) passes the existing parse guards and then crashesresolveMongoDatabaseAccesswith an uncaughtURIError: URI malformed. That exception fires before any database validation and surfaces as an unhelpful server error from the relay endpoints (listMongoDatabases,listMongoCollections,findMongoDocuments).Change
Treat an undecodable path exactly like an unparseable URI: catch the
URIErrorand returnnull, matching theURL.canParseguard directly above. Valid percent-encoded database names keep decoding as before.Validation
relay.test.tsfails before the fix (thrownURIError: URI malformedinstead of the expected allowlist error) and passes after it:vitest run src/services/mongodb/relay.test.ts— 4/4.oxfmt --checkpasses on the changed files.oxlintaborts with a Rust allocator panic in this environment, so lint was not run locally.