Skip to content

Commit 882d49c

Browse files
peffgitster
authored andcommitted
push: anonymize URL in status output
Commit 47abd85 (fetch: Strip usernames from url's before storing them, 2009-04-17) taught fetch to anonymize URLs. The primary purpose there was to avoid sticking passwords in merge-commit messages, but as a side effect, we also avoid printing them to stderr. The push side does not have the merge-commit problem, but it probably should avoid printing them to stderr. We can reuse the same anonymizing function. Note that for this to come up, the credentials would have to appear either on the command line or in a git config file, neither of which is particularly secure. So people _should_ be switching to using credential helpers instead, which makes this problem go away. But that's no excuse not to improve the situation for people who for whatever reason end up using credentials embedded in the URL. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7654286 commit 882d49c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

t/t5541-http-push-smart.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,12 @@ test_expect_success GPG 'push with post-receive to inspect certificate' '
368368
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
369369
'
370370

371+
test_expect_success 'push status output scrubs password' '
372+
test_commit scrub &&
373+
git push --porcelain "$HTTPD_URL_USER_PASS/smart/test_repo.git" >status &&
374+
# should have been scrubbed down to vanilla URL
375+
grep "^To $HTTPD_URL/smart/test_repo.git" status
376+
'
377+
371378
stop_httpd
372379
test_done

transport.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,11 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
681681

682682
static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
683683
{
684-
if (!count)
685-
fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
684+
if (!count) {
685+
char *url = transport_anonymize_url(dest);
686+
fprintf(porcelain ? stdout : stderr, "To %s\n", url);
687+
free(url);
688+
}
686689

687690
switch(ref->status) {
688691
case REF_STATUS_NONE:

0 commit comments

Comments
 (0)