Skip to content

Commit f8db0bd

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 a942fa7 commit f8db0bd

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
@@ -175,6 +175,9 @@ struct credential {
175175
struct credential_capability capa_authtype;
176176
struct credential_capability capa_state;
177177

178+
unsigned ntlm_suppressed:1,
179+
ntlm_allow:1;
180+
178181
char *username;
179182
char *password;
180183
char *credential;

http.c

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

656656
credential_fill(&http_auth, 1);
657657

658+
if (http_auth.ntlm_allow && !(http_auth_methods & CURLAUTH_NTLM)) {
659+
http_auth_methods |= CURLAUTH_NTLM;
660+
curl_easy_setopt(result, CURLOPT_HTTPAUTH, http_auth_methods);
661+
}
662+
658663
if (http_auth.password) {
659664
if (always_auth_proactively()) {
660665
/*
@@ -1906,6 +1911,12 @@ static int handle_curl_result(struct slot_results *results)
19061911
} else if (missing_target(results))
19071912
return HTTP_MISSING_TARGET;
19081913
else if (results->http_code == 401) {
1914+
http_auth.ntlm_suppressed = (results->auth_avail & CURLAUTH_NTLM) &&
1915+
!(http_auth_any & CURLAUTH_NTLM);
1916+
if (http_auth.ntlm_suppressed && http_auth.ntlm_allow) {
1917+
http_auth_methods |= CURLAUTH_NTLM;
1918+
return HTTP_REAUTH;
1919+
}
19091920
if ((http_auth.username && http_auth.password) ||\
19101921
(http_auth.authtype && http_auth.credential)) {
19111922
if (http_auth.multistage) {
@@ -1915,8 +1926,7 @@ static int handle_curl_result(struct slot_results *results)
19151926
credential_reject(&http_auth);
19161927
if (always_auth_proactively())
19171928
http_proactive_auth = PROACTIVE_AUTH_NONE;
1918-
if ((results->auth_avail & CURLAUTH_NTLM) &&
1919-
!(http_auth_any & CURLAUTH_NTLM)) {
1929+
if (http_auth.ntlm_suppressed) {
19201930
warning(_("Due to its cryptographic weaknesses, "
19211931
"NTLM authentication has been\n"
19221932
"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
@@ -689,8 +689,19 @@ test_expect_success NTLM 'access using NTLM auth' '
689689
test_must_fail env GIT_TRACE_CURL=1 git \
690690
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" 2>err &&
691691
test_grep "allowNTLMAuth" err &&
692+
693+
# Can be enabled via config
692694
GIT_TRACE_CURL=1 git -c http.$HTTPD_URL.allowNTLMAuth=true \
693-
ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
695+
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" &&
696+
697+
# Or via credential helper responding with ntlm=allow
698+
set_credential_reply get <<-EOF &&
699+
username=user
700+
password=pwd
701+
ntlm=allow
702+
EOF
703+
704+
git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
694705
'
695706

696707
test_done

0 commit comments

Comments
 (0)