Skip to content

Commit a1c07d3

Browse files
authored
Excluding AzureAuthToken from use in session ID construction (#2476)
1 parent 30df4ce commit a1c07d3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,19 @@ internal static string GetConnectionContextKey(ConnectionDetails details)
125125
foreach (KeyValuePair<string, object> entry in details.Options.OrderBy(entry => entry.Key))
126126
{
127127
// Filter out properties we already have or don't want (password)
128-
if (entry.Key != "server" && entry.Key != "database" && entry.Key != "user"
129-
&& entry.Key != "authenticationType" && entry.Key != "databaseDisplayName"
130-
&& entry.Key != "groupId" && entry.Key != "password" && entry.Key != "connectionName")
128+
if (
129+
// Exclude properties that are already used above
130+
entry.Key != "server" &&
131+
entry.Key != "database" &&
132+
entry.Key != "user" &&
133+
entry.Key != "authenticationType" &&
134+
entry.Key != "databaseDisplayName" &&
135+
// Exclude strictly-organizational properties that have no bearing on the connection
136+
entry.Key != "connectionName" &&
137+
entry.Key != "groupId" &&
138+
// Exclude secrets/credentials that should never be logged or stored in plaintext
139+
entry.Key != "password" &&
140+
entry.Key != "azureAccountToken")
131141
{
132142
// Boolean values are explicitly labeled true or false instead of undefined.
133143
if (entry.Value is bool v)

test/Microsoft.SqlTools.ServiceLayer.UnitTests/ObjectExplorer/ObjectExplorerServiceTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,23 @@ public async Task VerifyGeneratesSessionId()
321321

322322
ObjectExplorerService oeService = new();
323323

324+
string testPassword = "test_password", testAzureToken = "test_azure_account_token";
325+
324326
await oeService.HandleGetSessionIdRequest(new()
325327
{
326328
ServerName = "serverName",
327329
DatabaseName = "msdb",
328330
AuthenticationType = SqlConstants.ActiveDirectoryPassword,
329331
UserName = "TestUser",
330-
Password = "test_password",
332+
Password = testPassword,
333+
AzureAccountToken = testAzureToken,
331334
SecureEnclaves = "fakeEnclave"
332335

333336
}, requestContext.Object);
334337

335338
Assert.That(error, Is.Null, "No error should have been sent for an invalid input");
336-
Assert.That(result.SessionId, Does.Not.Contain("test_password"), "Password should not appear in SessionId");
339+
Assert.That(result.SessionId, Does.Not.Contain(testPassword), "Password should not appear in SessionId");
340+
Assert.That(result.SessionId, Does.Not.Contain(testAzureToken), "AzureAccountToken should not appear in SessionId");
337341
Assert.That(result.SessionId, Is.EqualTo("serverName_msdb_TestUser_ActiveDirectoryPassword_secureEnclaves:fakeEnclave"), "SessionId not as expected");
338342

339343
// reset

0 commit comments

Comments
 (0)