Skip to content

Commit de7b93b

Browse files
committed
wincredmgr: only match cred entries with correct namespace
GCM by default creates entries in the Windows Credential Manager on Windows, and prefixes the 'target name' of the entry with "git:". This 'namespace' prefix is configurable, but is not often changed in practice outside of tests. Visual Studio, when adding GitHub accounts (either natively or by the older GitHub extension for VS), it creates three credential entries: 1. GitHub for Visual Studio - https://github.com 2. git:https://github.com 3. https://github.com Entry 1 is used by VS for it's own purposes. Entry 2 is created for the benefit for GCM, so that we are 'primed'. It is unknown what entry 3 is for at this time. There is an error in our existing logic for enumerating credentials that is also matching entry 3 as well as the expected entry 2. Modify and fix the matching logic to ensure that the namespace prefix matches, rather than just stripping it and matching (even if it doesn't exist!).
1 parent 397f05d commit de7b93b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/shared/Core/Interop/Windows/WindowsCredentialManager.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,19 @@ private WindowsCredential CreateCredentialFromStructure(Win32Credential credenti
274274
return false;
275275
}
276276

277-
// Trim the "LegacyGeneric" prefix Windows adds and any namespace we have been filtered with
277+
// Trim the "LegacyGeneric" prefix Windows adds
278278
string targetName = credential.TargetName.TrimUntilIndexOf(TargetNameLegacyGenericPrefix);
279+
280+
// Only match credentials with the namespace we have been configured with (if any)
279281
if (!string.IsNullOrWhiteSpace(_namespace))
280282
{
281-
targetName = targetName.TrimUntilIndexOf($"{_namespace}:");
283+
string nsPrefix = $"{_namespace}:";
284+
if (!targetName.StartsWith(nsPrefix, StringComparison.Ordinal))
285+
{
286+
return false;
287+
}
288+
289+
targetName = targetName.Substring(nsPrefix.Length);
282290
}
283291

284292
// If the target name matches the service name exactly then return 'match'

0 commit comments

Comments
 (0)