-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix encodeBase64
for empty password or user in HTTP Basic Authentication
#4326
Conversation
I cannot reproduce (via https://webhook.site/) the current system not working. |
Maybe off topic and maybe an edge case. If |
Commited a simplified version: |
Before changes:After changes:Please reopen this bugfix. HTTP Auth was set up for C# Server (Kestrel): public async Task InvokeAsync(HttpContext context)
{
// Make sure we are hitting the swagger path, and not doing it locally as it just gets annoying :-)
if (context.Request.Path.StartsWithSegments("/swagger") && !IsLocalRequest(context))
{
string authHeader = context.Request.Headers["Authorization"];
if (authHeader != null && authHeader.StartsWith("Basic "))
{
// Get the encoded username and password
var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1]?.Trim();
// Decode from Base64 to string
var decodedUsernamePassword = Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernamePassword));
// Split username and password
var username = decodedUsernamePassword.Split(':', 2)[0];
var password = decodedUsernamePassword.Split(':', 2)[1];
if (IsAuthorized(username, password))
{
await _next.Invoke(context);
return;
}
}
// Return authentication type (causes browser to show login dialog)
context.Response.Headers["WWW-Authenticate"] = "Basic";
// Return unauthorized
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
}
else
{
await _next.Invoke(context);
}
}
public bool IsAuthorized(string username, string password)
{
// Check that username and password are correct
return username.Equals("", StringComparison.InvariantCultureIgnoreCase) && password.Equals("xxxxxxxxxxxxxxxxxx");
} |
Is it because the |
Please include a type hint here like /**
* Encode user and password to Base64 encoding
* for HTTP "basic" auth, as per RFC-7617
* @param {string|null} user - The username (nullable if not changed by a user)
* @param {string|null} pass - The password (nullable if not changed by a user)
* @returns {string}
*/ |
Note This function in your code is not resistent to timing attacks
See CWE-385 for further details: https://cwe.mitre.org/data/definitions/385.html |
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma
Tick the checkbox if you understand [x]:
Description
Fix basic authorization for servers with empty password or empty user.
Type of change
Please delete any options that are not relevant.
Checklist
Screenshots (if any)
Proof of empty user auth with Postman
No auth - error 401
Auth with empty user - 200 OK