Skip to content

CSHARP-6205: Credential exposure via sensitive connection string values included in parse-error messages - #2214

Open
sanych-sun wants to merge 2 commits into
mongodb:mainfrom
sanych-sun:CSHARP-6316
Open

sanych-sun wants to merge 2 commits into
mongodb:mainfrom
sanych-sun:CSHARP-6316

Conversation

@sanych-sun

Copy link
Copy Markdown
Member

No description provided.

@sanych-sun
sanych-sun requested a review from a team as a code owner November 25, 2026 21:21
@sanych-sun sanych-sun added the bug Fixes issues or unintended behavior. label Nov 25, 2026
@sanych-sun
sanych-sun requested review from ajcvickers and a balanced review from Copilot November 25, 2026 21:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Redacted output still exposes sensitive auth-mechanism property names, and MongoUrlTypeConverter string round trips replace credentials with redaction markers, breaking authentication.

2 open issues
3 files not reviewed
What changed in this PR

This PR reduces credential exposure in the MongoDB C# driver’s parsing errors and diagnostic output, while separating redacted representations from connection strings used to connect.

Changes:

  • Remove sensitive input from connection-string, endpoint, and authentication errors.
  • Redact diagnostic string output while retaining unredacted URLs for connection setup and identity.
  • Update callers and add regression coverage for redaction and credential preservation.
File Description
tests/​MongoDB.Driver.Tests/​Support/​EndPointExtensionsTests.cs Test endpoint conversion round-trips.
tests/​MongoDB.Driver.Tests/​Specifications/​server-discovery-and-monitoring/​ServerDiscoveryAndMonitoringProseTests.cs Use explicit endpoint conversion for failpoints.
tests/​MongoDB.Driver.Tests/​Specifications/​Runner/​MongoClientJsonDrivenTestRunnerBase.cs Avoid parsing redacted server strings.
tests/​MongoDB.Driver.Tests/​Specifications/​retryable-writes/​prose-tests/​PoolClearRetryability.cs Use explicit endpoint conversion.
tests/​MongoDB.Driver.Tests/​Specifications/​retryable-reads/​RetryableReadsProseTests.cs Use explicit endpoint conversion.
tests/​MongoDB.Driver.Tests/​Specifications/​connection-string/​ConnectionStringTestRunner.cs Handle disclosure cases and check exception text.
tests/​MongoDB.Driver.Tests/​Specifications/​connection-string/​ConnectionStringProseTests.cs Add settings and parse-error redaction tests.
tests/​MongoDB.Driver.Tests/​PipelineStageDefinitionBuilderTests.cs Use unredacted connection strings for clients.
tests/​MongoDB.Driver.Tests/​MongoUrlTests.cs Test redaction separately from URL identity.
tests/​MongoDB.Driver.Tests/​MongoUrlBuilderTests.cs Separate canonical-output and redaction assertions.
tests/​MongoDB.Driver.Tests/​MongoServerAddressTests.cs Test address and error-message redaction.
tests/​MongoDB.Driver.Tests/​MongoCredentialTests.cs Verify credential values stay out of diagnostics.
tests/​MongoDB.Driver.Tests/​MongoClientSettingsTests.cs Test server redaction and safe boolean validation.
tests/​MongoDB.Driver.Tests/​Core/​Misc/​EndPointHelperTests.cs Check endpoint errors for sensitive input.
tests/​MongoDB.Driver.Tests/​Core/​Configuration/​ConnectionStringTests.cs Update resolution assertions and redaction coverage.
tests/​MongoDB.Driver.Tests/​Communication/​Security/​PlainAuthenticationTests.cs Preserve credentials during test setup.
tests/​MongoDB.Driver.Tests/​Authentication/​MongoDBX509AuthenticatorTests.cs Check outer authentication messages for username disclosure.
tests/​MongoDB.Driver.TestHelpers/​DriverTestConfiguration.cs Preserve usable connection strings in helpers.
tests/​MongoDB.Driver.TestHelpers/​Core/​CoreTestConfiguration.cs Expose unredacted test connection strings.
src/​MongoDB.Driver/​Support/​EndPointExtensions.cs Add explicit server-address-to-endpoint conversion.
src/​MongoDB.Driver/​PasswordEvidence.cs Remove an unused hashing helper and imports.
src/​MongoDB.Driver/​MongoUrlBuilder.cs Separate redacted formatting from canonical URL generation.
src/​MongoDB.Driver/​MongoUrl.cs Retain canonical identity while redacting ToString().
src/​MongoDB.Driver/​MongoServerAddress.cs Remove address values from diagnostics and errors.
src/​MongoDB.Driver/​MongoCredential.cs Redact credential output and simplify validation errors.
src/​MongoDB.Driver/​MongoClientSettings.cs Avoid exposing invalid mechanism-property boolean values.
src/​MongoDB.Driver/​Core/​Misc/​EndPointHelper.cs Remove supplied endpoint values from parse errors.
src/​MongoDB.Driver/​Core/​Configuration/​ConnectionString.cs Sanitize parsing errors and redact diagnostic output.
src/​MongoDB.Driver/​Core/​Clusters/​DnsMonitor.cs Remove seed hostnames from normalization errors.
src/​MongoDB.Driver/​ClusterRegistry.cs Build endpoints without diagnostic string conversion.
src/​MongoDB.Driver/​Authentication/​MongoDBX509Authenticator.cs Remove usernames from outer authentication errors.
src/​MongoDB.Driver/​AGENTS.md Document redacted output versus canonical URLs.

Review effort: Balanced

"authMechanismProperties={0}&",
string.Join(",", _authenticationMechanismProperties
.Select(x => string.Format("{0}:{1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value ?? ""))).ToArray()));
.Select(x => string.Format("{0}:{1}", Uri.EscapeDataString(x.Key), redact ? RedactedMarker : Uri.EscapeDataString(x.Value ?? ""))).ToArray()));
public override string ToString()
{
return _url;
return _redactedUrl;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a real bug. Will need a fix and backporting to v3.x

@sanych-sun
sanych-sun requested review from BorisDog and papafe and removed request for BorisDog and ajcvickers November 26, 2026 22:38

This branch has not been deployed

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

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants