Optimization: Do not check password for ineligible basic accounts (#7861)
What changed, and why it matters
This commit changes how BTCPay Server handles Basic authentication. Previously, the system would check a user's password even if that account was not allowed to use Basic authentication, and then return specific error messages explaining why (for example, 'Basic authentication is not enabled' or 'multi-factor is enabled'). After the change, if an account is ineligible for Basic authentication, the system immediately returns a generic 'Basic authentication failed' message without checking the password at all. The stated goal is an optimization, but it also removes detailed failure messages and avoids password verification for ineligible accounts.
Review whether the unified error message and skipped password check are acceptable from a security standpoint. In particular, confirm that the early return does not bypass lockout or logging requirements, and assess whether the loss of distinct failure reasons affects monitoring or user support. If this is intended as a security hardening measure, document it as such.
Security signals we found
Authentication logic changed to skip password verification for ineligible accounts
Distinct error messages for disabled Basic auth, login restrictions, and 2FA replaced by a single generic failure
Rate-limiting path for new accounts still precedes the early return
Test expectation changed from a specific reason to a generic message
Evidence from the diff
The patch modifies BasicAuthenticationHandler.cs so that when canUseBasic is false, it returns Fail(invalidCredentials) before calling any password-checking method. Previously, the code called CheckPasswordAsync even for ineligible accounts and then returned distinct failure reasons based on canLogin, allowsBasic, and requiresTwoFactor. The test is updated to expect the generic ‘Basic authentication failed’ message instead of ‘not enabled’. The change reduces password-checking calls and unifies error responses.
Changed components
BTCPayServer/Security/GreenField/BasicAuthenticationHandler.csBTCPayServer.Tests/GreenfieldAPITests.csInspect captured patch +5 / −15
### BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -1878,7 +1878,7 @@ await ctx.Database.GetDbConnection().ExecuteAsync("""
var basicAuthDisabled = await AssertEx.AssertApiError(401, "unauthenticated",
() => clientBasic.GetCurrentUser());
- Assert.Contains("not enabled", basicAuthDisabled.Message);
+ Assert.Equal("Basic authentication failed", basicAuthDisabled.Message);
var updatedUser = await clientProfile.UpdateCurrentUser(new UpdateApplicationUserRequest
{
### BTCPayServer/Security/GreenField/BasicAuthenticationHandler.cs
@@ -82,22 +82,12 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
if (isNewAccount && !canUseBasic && ip is not null && !await rateLimitService.Throttle(ZoneLimits.Login, ip))
return Fail(invalidCredentials);
- var passwordVerified = canUseBasic
- ? (await signInManager.CheckPasswordSignInAsync(user, password, lockoutOnFailure: true)).Succeeded
- : await userManager.CheckPasswordAsync(user, password);
- if (!passwordVerified)
+ if (!canUseBasic)
+ return Fail(invalidCredentials);
+
+ if (!(await signInManager.CheckPasswordSignInAsync(user, password, lockoutOnFailure: true)).Succeeded)
return Fail(invalidCredentials);
- if (!canLogin)
- {
- return Fail($"Basic authentication failed: {loggingContext.Failures[0].Text.Value}");
- }
- if (!allowsBasic)
- return Fail("Basic authentication for the Greenfield API is not enabled for this user.");
- if (requiresTwoFactor)
- {
- return Fail("Cannot use Basic authentication when multi-factor is enabled.");
- }
var claims = new List<Claim>()
{
new Claim(identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, user.Id),Why this scored 49/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.