Repository navigation
CSHARP-6205: Credential exposure via sensitive connection string values included in parse-error messages - #2214
Open
sanych-sun wants to merge 2 commits into
Open
sanych-sun wants to merge 2 commits into
sanych-sun wants to merge 2 commits into
Conversation
…es included in parse-error messages
sanych-sun
requested review from
ajcvickers
and
a balanced review from Copilot
November 25, 2026 21:21
Contributor
There was a problem hiding this comment.
🟡 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
specifications/connection-string/tests/README.md: Excluded by your content exclusion settingsspecifications/connection-string/tests/credential-disclosure.json: Excluded by your content exclusion settingsspecifications/connection-string/tests/credential-disclosure.yml: Excluded by your content exclusion settings
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; |
Member
Author
There was a problem hiding this comment.
It's a real bug. Will need a fix and backporting to v3.x
sanych-sun
requested review from
BorisDog and
papafe
and removed request for
BorisDog and
ajcvickers
November 26, 2026 22:38
papafe
approved these changes
Nov 27, 2026
This branch has not been deployed
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.


No description provided.