Skip to content

Commit 816db62

Browse files
committed
credential: advertise NTLM suppression and allow helpers to re-enable
The previous commits disabled NTLM authentication by default due to its cryptographic weaknesses. Users can re-enable it via the config setting http.<url>.allowNTLMAuth, but this requires manual intervention. Credential helpers may have knowledge about which servers are trusted for NTLM authentication (e.g., known on-prem Azure DevOps instances). To allow them to signal this trust, introduce a simple negotiation: when NTLM is suppressed and the server offered it, Git advertises ntlm=suppressed to the credential helper. The helper can respond with ntlm=allow to re-enable NTLM for this request. This happens precisely at the point where we would otherwise warn the user about NTLM being suppressed, ensuring the capability is only advertised when relevant. Helped-by: Matthew John Cheetham <mjcheetham@outlook.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b24f377 commit 816db62

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

credential.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ int credential_read(struct credential *c, FILE *fp,
360360
credential_set_capability(&c->capa_authtype, op_type);
361361
else if (!strcmp(value, "state"))
362362
credential_set_capability(&c->capa_state, op_type);
363+
} else if (!strcmp(key, "ntlm")) {
364+
if (!strcmp(value, "allow"))
365+
c->ntlm_allow = 1;
363366
} else if (!strcmp(key, "continue")) {
364367
c->multistage = !!git_config_bool("continue", value);
365368
} else if (!strcmp(key, "password_expiry_utc")) {
@@ -420,6 +423,8 @@ void credential_write(const struct credential *c, FILE *fp,
420423
if (c->ephemeral)
421424
credential_write_item(c, fp, "ephemeral", "1", 0);
422425
}
426+
if (c->ntlm_suppressed)
427+
credential_write_item(c, fp, "ntlm", "suppressed", 0);
423428
credential_write_item(c, fp, "protocol", c->protocol, 1);
424429
credential_write_item(c, fp, "host", c->host, 1);
425430
credential_write_item(c, fp, "path", c->path, 0);

credential.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ struct credential {
177177
struct credential_capability capa_authtype;
178178
struct credential_capability capa_state;
179179

180+
unsigned ntlm_suppressed:1,
181+
ntlm_allow:1;
182+
180183
char *username;
181184
char *password;
182185
char *credential;

http.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ static void init_curl_http_auth(CURL *result)
638638

639639
credential_fill(the_repository, &http_auth, 1);
640640

641+
if (http_auth.ntlm_allow && !(http_auth_methods & CURLAUTH_NTLM)) {
642+
http_auth_methods |= CURLAUTH_NTLM;
643+
curl_easy_setopt(result, CURLOPT_HTTPAUTH, http_auth_methods);
644+
}
645+
641646
if (http_auth.password) {
642647
if (always_auth_proactively()) {
643648
/*
@@ -1865,6 +1870,12 @@ static int handle_curl_result(struct slot_results *results)
18651870
} else if (missing_target(results))
18661871
return HTTP_MISSING_TARGET;
18671872
else if (results->http_code == 401) {
1873+
http_auth.ntlm_suppressed = (results->auth_avail & CURLAUTH_NTLM) &&
1874+
!(http_auth_any & CURLAUTH_NTLM);
1875+
if (http_auth.ntlm_suppressed && http_auth.ntlm_allow) {
1876+
http_auth_methods |= CURLAUTH_NTLM;
1877+
return HTTP_REAUTH;
1878+
}
18681879
if ((http_auth.username && http_auth.password) ||\
18691880
(http_auth.authtype && http_auth.credential)) {
18701881
if (http_auth.multistage) {
@@ -1874,8 +1885,7 @@ static int handle_curl_result(struct slot_results *results)
18741885
credential_reject(the_repository, &http_auth);
18751886
if (always_auth_proactively())
18761887
http_proactive_auth = PROACTIVE_AUTH_NONE;
1877-
if ((results->auth_avail & CURLAUTH_NTLM) &&
1878-
!(http_auth_any & CURLAUTH_NTLM)) {
1888+
if (http_auth.ntlm_suppressed) {
18791889
warning(_("Due to its cryptographic weaknesses, "
18801890
"NTLM authentication has been\n"
18811891
"disabled in Git by default. You can "

t/t5563-simple-http-auth.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,19 @@ test_expect_success NTLM 'access using NTLM auth' '
688688
test_must_fail env GIT_TRACE_CURL=1 git \
689689
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" 2>err &&
690690
test_grep "allowNTLMAuth" err &&
691+
692+
# Can be enabled via config
691693
GIT_TRACE_CURL=1 git -c http.$HTTPD_URL.allowNTLMAuth=true \
692-
ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
694+
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" &&
695+
696+
# Or via credential helper responding with ntlm=allow
697+
set_credential_reply get <<-EOF &&
698+
username=user
699+
password=pwd
700+
ntlm=allow
701+
EOF
702+
703+
git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
693704
'
694705

695706
test_done

0 commit comments

Comments
 (0)