-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5471: Incorrectly resolving the authentication mechanism param… #1605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c9e6c02
02374e3
68d8f3b
71a4ad2
db0f8e2
a374d7f
3fb9ada
a3bb82b
1351319
84687aa
f3e4a7e
8b02d81
99df11a
a9c9dda
5e24912
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -684,29 +684,30 @@ private ConnectionString BuildResolvedConnectionString(ConnectionStringScheme re | |
.AllKeys | ||
.SelectMany(key => resolvedOptions | ||
.GetValues(key) | ||
.Select(value => $"{key}={Uri.EscapeDataString(value)}"))); | ||
.Select(value => $"{key}={EscapeOptionValue(key, value)}"))); | ||
|
||
if (mergedOptions.Count > 0) | ||
{ | ||
connectionString += "?" + string.Join("&", mergedOptions); | ||
} | ||
|
||
return new ConnectionString(connectionString, isResolved: true); | ||
|
||
string EscapeOptionValue(string key, string value) | ||
=> string.Equals(key, "authmechanismproperties", StringComparison.OrdinalIgnoreCase) ? value : Uri.EscapeDataString(value); | ||
|
||
} | ||
|
||
private void ExtractScheme(Match match) | ||
{ | ||
var schemeGroup = match.Groups["scheme"]; | ||
if (schemeGroup.Success) | ||
if (schemeGroup.Success && schemeGroup.Value == "mongodb+srv") | ||
{ | ||
if (schemeGroup.Value == "mongodb+srv") | ||
_scheme = ConnectionStringScheme.MongoDBPlusSrv; | ||
if (!_tls.HasValue) | ||
{ | ||
_scheme = ConnectionStringScheme.MongoDBPlusSrv; | ||
if (!_tls.HasValue) | ||
{ | ||
_tls = true; | ||
_allOptions.Add("tls", "true"); | ||
} | ||
_tls = true; | ||
_allOptions.Add("tls", "true"); | ||
} | ||
} | ||
} | ||
|
@@ -761,7 +762,13 @@ private void ExtractOptions(Match match) | |
var parts = option.Value.Split('='); | ||
var name = parts[0].Trim(); | ||
var value = parts[1].Trim(); | ||
_allOptions.Add(name, Uri.UnescapeDataString(value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think this change is safe, as we are stopping decoding for all options and that options are available via public API, not just for building the resolved connection string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest either introduce new private collection to contain the unprocessed options (like a |
||
// Should not decode authmechanismproperties before splitting by separator. | ||
if (!string.Equals(name, "authmechanismproperties", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
value = Uri.UnescapeDataString(value); | ||
} | ||
|
||
_allOptions.Add(name, value); | ||
ParseOption(name, value); | ||
} | ||
} | ||
|
@@ -905,12 +912,6 @@ string ProtectConnectionString(string connectionString) | |
|
||
private void ParseOption(string name, string value) | ||
{ | ||
// Should not decode authmechanismproperties before splitting by separator. | ||
if (!string.Equals(name, "authmechanismproperties", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
value = Uri.UnescapeDataString(value); | ||
} | ||
|
||
switch (name.ToLowerInvariant()) | ||
{ | ||
case "appname": | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change, but I looked at it :)