Skip to content

Commit 3306edb

Browse files
bk2204gitster
authored andcommitted
http: allow using netrc for WebDAV-based HTTP protocol
For an extended period of time, we've enabled libcurl's netrc functionality, which will read credentials from the netrc file if none are provided. Unfortunately, we have also not documented this fact or written any tests for it, but people have come to rely on it. In 610cbc1 ("http: allow authenticating proactively", 2024-07-10), we accidentally broke the ability of users to use the netrc file for the WebDAV-based HTTP protocol. Notably, it works on the initial request but does not work on subsequent requests, which causes failures because that version of the protocol will necessarily make multiple requests. This happens because curl_empty_auth_enabled never returns -1, only 0 or 1, and so if http.proactiveAuth is not enabled, the username and password are always set to empty credentials, which prevents libcurl's fallback to netrc from working. However, in other cases, the server continues to get a 401 response and the credential helper is invoked, which is the normal behavior, so this was not noticed earlier. To fix this, change the condition to check for enabling empty auth and also not having proactive auth enabled, which should result in the username and password not being set to a single colon in the typical case, and thus the netrc file being used. Reported-by: Peter Georg <[email protected]> Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d2a71c commit 3306edb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

http.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,7 @@ static void init_curl_http_auth(CURL *result)
598598
{
599599
if ((!http_auth.username || !*http_auth.username) &&
600600
(!http_auth.credential || !*http_auth.credential)) {
601-
int empty_auth = curl_empty_auth_enabled();
602-
if ((empty_auth != -1 && !always_auth_proactively()) || empty_auth == 1) {
601+
if (!always_auth_proactively() && curl_empty_auth_enabled()) {
603602
curl_easy_setopt(result, CURLOPT_USERPWD, ":");
604603
return;
605604
} else if (!always_auth_proactively()) {

t/t5540-http-push-webdav.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,14 @@ test_expect_failure 'push to password-protected repository (no user in URL)' '
201201
test_cmp expect actual
202202
'
203203

204+
test_expect_success 'push to password-protected repository (netrc)' '
205+
test_commit pw-netrc &&
206+
echo "default login user@host password pass@host" >"$HOME/.netrc" &&
207+
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
208+
git rev-parse --verify HEAD >expect &&
209+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
210+
rev-parse --verify HEAD >actual &&
211+
test_cmp expect actual
212+
'
213+
204214
test_done

0 commit comments

Comments
 (0)