-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 3.1.0
-
Component/s: Authentication
-
None
-
Dotnet Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Summary
Mongo driver is incorrectly resolving the key/value pairs of authMechanismProperties in a SRV connection string.
Driver version: 3.1.0
Mongo server version: v8
Topology: Standalone cloud cluster
How to Reproduce
public static void Process() { var text = "mongodb+srv://<cluseter>/?retryWrites=true&w=1&maxPoolSize=100&authMechanism=MONGODB-OIDC&authSource=%24external&authMechanismProperties=ENVIRONMENT:azure,prop1:user,prop2:userType"; var mongoConnection = MongoClientSettings.FromConnectionString(text); Console.WriteLine(mongoConnection.Credential.GetMechanismProperty<string>("ENVIRONMENT", "")); // Prints "azure,prop1:user,prop2:userType" instead of just "azure" }
Additional Background
Noticed this is happening because of the line of code https://github.com/mongodb/mongo-csharp-driver/blob/660f33d01fe9604044e2877e4564ce10dbfc2593/src/MongoDB.Driver/Core/Configuration/ConnectionString.cs#L909, which doesn't unescape the authMechanismProperties value(it contains the encoded values for all special characters and doesn't work well with the split happening in GetAuthMechanismProperties method) while building a resolved SRV connection string