Fix Basic auth passwords containing colons
What changed, and why it matters
This commit fixes a bug in BTCPay Server's Basic authentication handling. Previously, if a user's password contained a colon character (like 'Kitten0@:with:colons'), the system would split the username:password string at every colon and only use the part before the second colon as the password. This meant users with colons in their passwords could not log in properly through the Greenfield API's Basic auth. The fix now splits only on the first colon, treating everything after it as the password.
Deploy the patched version to restore correct Basic authentication for users whose passwords contain colons. Review other credential-parsing code for similar split-on-all-delimiter bugs. No immediate incident response is indicated beyond normal patching.
Security signals we found
Authentication bypass/failure due to incorrect parsing of Basic auth credentials
Violation of RFC 7617 behavior for passwords containing colons
Potential account lockout or inability to use generated/strong passwords with colons
No evidence of memory disclosure, credential leakage, or remote code execution
Evidence from the diff
The BasicAuthenticationHandler in BTCPay Server’s Greenfield API was using string.Split(‘:’) without a count limit on the decoded ‘username:password’ credential. RFC 7617 allows colons in passwords, so splitting on all colons truncated passwords containing colons, causing authentication failure. The patch replaces the unbounded split with IndexOf(‘:’) and a single split at the first colon, preserving the rest of the string as the password. A unit test was added with a password containing multiple colons.
Changed components
BTCPayServer/Security/GreenField/BasicAuthenticationHandler.csBTCPayServer.Tests/GreenfieldAPITests.csInspect captured patch +7 / −3
### BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -1738,6 +1738,7 @@ public async Task UsersControllerTests()
tester.PayTester.HostEnvironment = Environments.Production;
await tester.StartAsync();
var user = tester.NewAccount();
+ user.Password = "Kitten0@:with:colons";
await user.GrantAccessAsync();
await user.MakeAdmin();
var clientProfile = await user.CreateClient(Policies.CanModifyProfile);
### BTCPayServer/Security/GreenField/BasicAuthenticationHandler.cs
@@ -44,9 +44,12 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
var encodedUsernamePassword =
authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
var decodedUsernamePassword =
- Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernamePassword)).Split(':');
- username = decodedUsernamePassword[0];
- password = decodedUsernamePassword[1];
+ Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernamePassword));
+ var separatorIndex = decodedUsernamePassword.IndexOf(':');
+ if (separatorIndex < 0)
+ throw new FormatException();
+ username = decodedUsernamePassword[..separatorIndex];
+ password = decodedUsernamePassword[(separatorIndex + 1)..];
}
catch (Exception)
{Why this scored 47/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.