Skip to content

Commit 2884124

Browse files
committed
http: don't require a password
Attempt authentication when a username is presented but a password is not; this can happen in particular when users are doing token authentication and specifying the token in the URL itself. For example, `https://token@host/` is a valid URI and should be treated as a username of `token` with an empty password.
1 parent c87e476 commit 2884124

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/transports/http.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ static int apply_url_credentials(
104104
const char *username,
105105
const char *password)
106106
{
107+
GIT_ASSERT_ARG(username);
108+
109+
if (!password)
110+
password = "";
111+
107112
if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
108113
return git_credential_userpass_plaintext_new(cred, username, password);
109114

@@ -138,8 +143,7 @@ static int handle_auth(
138143
/* Start with URL-specified credentials, if there were any. */
139144
if ((allowed_credtypes & GIT_CREDENTIAL_USERPASS_PLAINTEXT) &&
140145
!server->url_cred_presented &&
141-
server->url.username &&
142-
server->url.password) {
146+
server->url.username) {
143147
error = apply_url_credentials(&server->cred, allowed_credtypes, server->url.username, server->url.password);
144148
server->url_cred_presented = 1;
145149

0 commit comments

Comments
 (0)