-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Milestone
Description
Description
PrincipalContext.ValidateCredentials() returns true if the username begins with the null character and the password is either empty or begins with the null character. This seemed like unexpected behavior and a potential security concern for applications that use this to validate user credentials.
Reproduction Steps
using System.DirectoryServices.AccountManagement;
string domainControllerHost = "your.domain.controller";
using (var pc = new PrincipalContext(ContextType.Domain, domainControllerHost))
{
bool nullCharUsernameIsValid = pc.ValidateCredentials("\0", "");
Console.WriteLine($"Null char username is valid: {nullCharUsernameIsValid}");
bool emptyUsernameIsValid = pc.ValidateCredentials("", "");
Console.WriteLine($"Empty username is valid: {emptyUsernameIsValid}");
}Expected behavior
Output:
Null char username is valid: False
Empty username is valid: False
Actual behavior
Output:
Null char username is valid: True
Empty username is valid: False
Regression?
No response
Known Workarounds
Calling code can check for null chars in username and password to reject suspicious input before calling PrincipalContext.Validate():
if (userName.Contains('\0') || password.Contains('\0'))
{
return false;
}
using (var pc = new PrincipalContext(ContextType.Domain, domainControllerHost))
{
return pc.ValidateCredentials(userName, password);
}Configuration
No response
Other information
Lines 241 to 245 in c81f403
| // empty username and password on the local box | |
| // causes authentication to succeed. If the username is empty we should just fail it | |
| // here. | |
| if (userName != null && userName.Length == 0) | |
| return false; |