Skip to content

Commit c1284b2

Browse files
dschogitster
authored andcommitted
curl: anonymize URLs in error messages and warnings
Just like 47abd85 (fetch: Strip usernames from url's before storing them, 2009-04-17) and later 882d49c (push: anonymize URL in status output, 2016-07-13), this change anonymizes URLs (read: strips them of user names and especially passwords) in user-facing error messages and warnings. Signed-off-by: Johannes Schindelin <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98cdfbb commit c1284b2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

remote-curl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "send-pack.h"
1717
#include "protocol.h"
1818
#include "quote.h"
19+
#include "transport.h"
1920

2021
static struct remote *remote;
2122
/* always ends with a trailing slash */
@@ -250,7 +251,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
250251
if (data[i] == '\n') {
251252
if (mid - start != 40)
252253
die("%sinfo/refs not valid: is this a git repository?",
253-
url.buf);
254+
transport_anonymize_url(url.buf));
254255
data[i] = 0;
255256
ref_name = mid + 1;
256257
ref = alloc_ref(ref_name);
@@ -388,17 +389,23 @@ static struct discovery *discover_refs(const char *service, int for_push)
388389
break;
389390
case HTTP_MISSING_TARGET:
390391
show_http_message(&type, &charset, &buffer);
391-
die("repository '%s' not found", url.buf);
392+
die("repository '%s' not found",
393+
transport_anonymize_url(url.buf));
392394
case HTTP_NOAUTH:
393395
show_http_message(&type, &charset, &buffer);
394-
die("Authentication failed for '%s'", url.buf);
396+
die("Authentication failed for '%s'",
397+
transport_anonymize_url(url.buf));
395398
default:
396399
show_http_message(&type, &charset, &buffer);
397-
die("unable to access '%s': %s", url.buf, curl_errorstr);
400+
die("unable to access '%s': %s",
401+
transport_anonymize_url(url.buf), curl_errorstr);
398402
}
399403

400-
if (options.verbosity && !starts_with(refs_url.buf, url.buf))
401-
warning(_("redirecting to %s"), url.buf);
404+
if (options.verbosity && !starts_with(refs_url.buf, url.buf)) {
405+
char *u = transport_anonymize_url(url.buf);
406+
warning(_("redirecting to %s"), u);
407+
free(u);
408+
}
402409

403410
last= xcalloc(1, sizeof(*last_discovery));
404411
last->service = xstrdup(service);

0 commit comments

Comments
 (0)