From patchwork Wed May 13 19:12:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 11547123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4D3714E3 for ; Wed, 13 May 2020 19:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFCF7205ED for ; Wed, 13 May 2020 19:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KgShDzhs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390594AbgEMTM7 (ORCPT ); Wed, 13 May 2020 15:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390571AbgEMTM6 (ORCPT ); Wed, 13 May 2020 15:12:58 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 404D3C061A0C for ; Wed, 13 May 2020 12:12:57 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id dh14so735994qvb.4 for ; Wed, 13 May 2020 12:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sXvnFw5DSynKaqJB4JyX+C4cj+Wzy+yU2qOfv+2H8HQ=; b=KgShDzhsUxfkcrU+E4MGvqb1Y0hM4icJrkZOvzig9nsh0u9GciFvRvqBLv2ocCdqty EV/FxuW6LNLQZk7Ml5nXLvFWTKCEGmWw9ijXJHdIjeed/Ipb2j6npGt+pYHuSR7M+rJa vzO5ksR61ns8H+ZdnqmAelVJ3kup0A5snS+EUrlPVkbISgFT+MaJOj7DM9IAH24NvOk9 6hCDSJIIjXJencSETISJdWdfMRNImOvFHeULOiu1I3/kRzbEGatTH76wdALBecKnuQ1p riQIz8KSdoUIj2pBZ5ImBEPcZxZyMdiqmnXFz1n6c8Ls3oZluY3+dgVf3XLtVMRA6L2v RRwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sXvnFw5DSynKaqJB4JyX+C4cj+Wzy+yU2qOfv+2H8HQ=; b=oEHK0gVm8gJxEkoeh5waQOd4OLaWJSERPmf2QNFoF5alkRR1lePv5Ey0a8aB2zujsL 68q8pXBVYpqV6HrMcjOmfEUBwLJwYp9rqgvY6baNHz4D5hmWNQCCIG0T6m1KPFtNUScJ dW4n9EQBAJAxYOv5xUFcJS+NLi/xi6NhTac6HVYgMmrdfQYfQGYaYFFbOZx9/W4nZvGW B17Z5Lw89upcCRdjYy6Bj8bQYz+6Qt/fizmV7z7ah3FfpoWGut0xKxF3HGICLxtfociA 8zntarSy3ZI8dSnRTjgT8ej/qMUcLokMYRms2FHDp3P8FdOWb1s7pjkpICA0aIDr2Cky u7xA== X-Gm-Message-State: AOAM530Qr2mySXfk5grsbW2DTukp8xA0yM/O4R2KJbV7xRNWBz70SYOt D+GvxAy14QGG//rzLQWfIqS3KQPNzREw+SP2Vb/zlQ9z3BcKGih8WZJJt3pGuXy8AhCSlyyzxds SbY3kq4FAY0doSlC/SHVOvw9dcM7yEOpfTLJTitoOvoSr6lvs8DEAvboTS6TdQjVGsHhpLs27xx gS X-Google-Smtp-Source: ABdhPJwCpTpX0V6LoigeYjZAS97cJttPy5KPGPqNBegF9M1hRSuRjFRPM+P/vKUQ07tDIyB58ddCGTblHXsxoVFLFu2Z X-Received: by 2002:ad4:4c4d:: with SMTP id cs13mr1125575qvb.207.1589397176374; Wed, 13 May 2020 12:12:56 -0700 (PDT) Date: Wed, 13 May 2020 12:12:46 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog Subject: [PATCH v2 1/3] t5551: test that GIT_TRACE_CURL redacts password From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , sandals@crustytoothpaste.net, gitster@pobox.com, peff@peff.net Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Verify that when GIT_TRACE_CURL is set, Git prints out "Authorization: Basic " instead of the base64-encoded authorization details. Signed-off-by: Jonathan Tan --- t/t5551-http-fetch-smart.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index 6788aeface..acc8473a72 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -185,6 +185,18 @@ test_expect_success 'redirects send auth to new location' ' expect_askpass both user@host auth/smart/repo.git ' +test_expect_success 'GIT_TRACE_CURL redacts auth details' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth && + expect_askpass both user@host && + + # Ensure that there is no "Basic" followed by a base64 string, but that + # the auth details are redacted + ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace && + grep "Authorization: Basic " trace +' + test_expect_success 'disable dumb http on server' ' git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ config http.getanyfile false From patchwork Wed May 13 19:12:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 11547121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2D7290 for ; Wed, 13 May 2020 19:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27F25205ED for ; Wed, 13 May 2020 19:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BV6OhcPg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390458AbgEMTM7 (ORCPT ); Wed, 13 May 2020 15:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390588AbgEMTM7 (ORCPT ); Wed, 13 May 2020 15:12:59 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA3FC061A0C for ; Wed, 13 May 2020 12:12:58 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id b7so519059qkk.6 for ; Wed, 13 May 2020 12:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Rk25Qngqf87losHmTmrScdq2cP+siG5cCYmqHvFGzHY=; b=BV6OhcPguIRSDtWcYuhSFMi+Tosbg98W6CL5HC/8BYnA8/Poe1NVgjZnuM7Q74P0C0 Z6EdDKPv7fBlmbeOLz3iJa5bsmUA2lYJfVx4UlW0gCIYpoIAD6NobHZWOochpj109SJy g41eD01S9JaUDUizLtdqNFTVxpZKWmbQ+TIYHL9lFa3dnQIw6O1E4tlLXo8VsYjDRZEk 7H3zR7sFlfVr98u6I2l/xcnL9oTQDhsYoxvv6WAoDPU8KO+aiJyC9MPVX7GujxQ2XOAA QAyC+qtAlxV99YAXXuSYuCPqqBW/UoekPrC1zymTy5m3pmqFqxUVP3TRD9juYWd+SWBa Yx7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Rk25Qngqf87losHmTmrScdq2cP+siG5cCYmqHvFGzHY=; b=UcJTehaDvQ731SBPgqKhA/2I0+pqsI+7Z4zdzGFYnk/Ox6QCqs4tcJDNoYKMDt3/4y iC8YSZK1Ron8+ufvMGm95QaccKOnE0MOSDORZs5GLv7FMMW/EflFU/dFutxb1qAFjkVW 3ZHZNnSQyAsPJOnFnLl6tjrF66ZZ+VQdosCyLUj85VRxBcSLSo3fb/cB9GEOnLRMmmu2 w5IQwbJLovyB4nEsXFQ9sKtPgwxHUtugCDSKMWyZdopkM0TgDmxRmpT1eBAdGhJqu+nd ekMAjqU8bNiVPdoRuYJ0YivRjrxqGdHiI2VoaBK9dkY8C7RjtohBJ7FvcxZg9z2u9f0f 4kWw== X-Gm-Message-State: AOAM532lwvWvvzB8ZiE1mk1EfJZjYcCq0Fi13Bts/FHB7CCzrRyhn48h pdXuh7tKBW0gakCC2JVpEqg4qChe8VXRI7MIi7/itJQRGBVsx1uBXM0Ot9lGRo/on6COm1cTzrZ B2ciyJjyECeoWus7DsSFm97tkYzha+16PmxOZR4ZdpxhSh8hC4bY+yoTbg9v10V3ZcCHgtihNqs 4a X-Google-Smtp-Source: ABdhPJxTvo4mZEWeQ+DSgZP3C7ovJJXk793pCVjjZQAePys93OJxnFlUoqxO/X9rsTco4GHcOYV0jdS8ghNy38LHnmaf X-Received: by 2002:a0c:e403:: with SMTP id o3mr1152804qvl.24.1589397178014; Wed, 13 May 2020 12:12:58 -0700 (PDT) Date: Wed, 13 May 2020 12:12:47 -0700 In-Reply-To: Message-Id: <8c70a45b24861290b64d4487383bdfa5960332ab.1589394456.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog Subject: [PATCH v2 2/3] http: make GIT_TRACE_CURL auth redaction optional From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , sandals@crustytoothpaste.net, gitster@pobox.com, peff@peff.net Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By default, auth headers are redacted when a trace is output through GIT_TRACE_CURL. Allow the user to inhibit this redaction through an environment variable. Signed-off-by: Jonathan Tan --- Documentation/git.txt | 6 ++++++ http.c | 11 +++++++++-- t/t5551-http-fetch-smart.sh | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index 9d6769e95a..af98cd7dc2 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -777,6 +777,12 @@ for full details. See `GIT_TRACE2` for available trace output options and link:technical/api-trace2.html[Trace2 documentation] for full details. +`GIT_REDACT_AUTHORIZATION`:: + By default, when a curl trace is enabled (see `GIT_TRACE_CURL` above), + the values of "Authorization:" and "Proxy-Authorization:" headers in + the trace are redacted. Set this variable to `0` to prevent this + redaction. + `GIT_REDACT_COOKIES`:: This can be set to a comma-separated list of strings. When a curl trace is enabled (see `GIT_TRACE_CURL` above), whenever a "Cookies:" header diff --git a/http.c b/http.c index 62aa995245..77eac95d64 100644 --- a/http.c +++ b/http.c @@ -18,6 +18,7 @@ static struct trace_key trace_curl = TRACE_KEY_INIT(CURL); static int trace_curl_data = 1; +static int trace_curl_redact_authorization = 1; static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP; #if LIBCURL_VERSION_NUM >= 0x070a08 long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER; @@ -642,8 +643,9 @@ static void redact_sensitive_header(struct strbuf *header) { const char *sensitive_header; - if (skip_prefix(header->buf, "Authorization:", &sensitive_header) || - skip_prefix(header->buf, "Proxy-Authorization:", &sensitive_header)) { + if (trace_curl_redact_authorization && + (skip_prefix(header->buf, "Authorization:", &sensitive_header) || + skip_prefix(header->buf, "Proxy-Authorization:", &sensitive_header))) { /* The first token is the type, which is OK to log */ while (isspace(*sensitive_header)) sensitive_header++; @@ -859,6 +861,7 @@ static int get_curl_http_version_opt(const char *version_string, long *opt) static CURL *get_curl_handle(void) { CURL *result = curl_easy_init(); + const char *redact_authorization_envvar; if (!result) die("curl_easy_init failed"); @@ -997,6 +1000,10 @@ static CURL *get_curl_handle(void) setup_curl_trace(result); if (getenv("GIT_TRACE_CURL_NO_DATA")) trace_curl_data = 0; + redact_authorization_envvar = getenv("GIT_REDACT_AUTHORIZATION"); + if (redact_authorization_envvar && + !strcmp(redact_authorization_envvar, "0")) + trace_curl_redact_authorization = 0; if (getenv("GIT_REDACT_COOKIES")) { string_list_split(&cookies_to_redact, getenv("GIT_REDACT_COOKIES"), ',', -1); diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index acc8473a72..eeecfe01d7 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -197,6 +197,16 @@ test_expect_success 'GIT_TRACE_CURL redacts auth details' ' grep "Authorization: Basic " trace ' +test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_REDACT_AUTHORIZATION=0' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_REDACT_AUTHORIZATION=0 GIT_TRACE_CURL="$(pwd)/trace" \ + git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth && + expect_askpass both user@host && + + grep "Authorization: Basic [0-9a-zA-Z+/]" trace +' + test_expect_success 'disable dumb http on server' ' git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ config http.getanyfile false From patchwork Wed May 13 19:12:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 11547127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB33860D for ; Wed, 13 May 2020 19:13:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 164422054F for ; Wed, 13 May 2020 19:13:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="poMhFgga" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390598AbgEMTNC (ORCPT ); Wed, 13 May 2020 15:13:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390588AbgEMTNA (ORCPT ); Wed, 13 May 2020 15:13:00 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 836DEC061A0C for ; Wed, 13 May 2020 12:13:00 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i62so856813ybc.11 for ; Wed, 13 May 2020 12:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=8F6xDckkOakXEp5gZKjehDdJH7YrD+m+yewgY4GBvhY=; b=poMhFggaYAdqhnCvsuQFsUTRgYXv85TJFrdEzjKU8LXflKivtW8elIjn3KRN5f9nBE BpSDMW0m1QIihuxWjjK1McnYWDj/2kXLC4znr+1dHQJFkbnSaSTxuqJk480GcLdpnnCu EcSgbATzJWFqIif/UaRp8mr5mJZKp706dq2IwtY+gCOl+kvNUy9Nd2cWwyRTlmoywDL6 jXXrIJQ7uoAE1qiaQcGHvKueZgzImngb0jJ9JLHtnTP5s6bOea/lZQajEECyd5jjRX1Z bL55nL97uTa9qVJq7NrsNXP+MFs3WJZ0doZ1uEtugSp4gAfkujNDKtC/cKA9aXlf/8Ah x/aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8F6xDckkOakXEp5gZKjehDdJH7YrD+m+yewgY4GBvhY=; b=ZLQR+lIk7mkWQTj3EAZIJcxC/SAdUxvAdg5pcHeo+KjKOWpdTcwtYqDr/cWgZsgEpf tKRMk/CJLSx+birXjRVJx9dxB7a8b30Vp4ZSbvvL7kJ5ad9Pcwn0wV634MSCWoBQCFLs Sj47kVWo/lCzA8Dia+O+pxP8QrMERgwd+5KNI8wkP4PFcdD1iz5UlRLVyzrEvBTDcp7O KmWpZ+FFwQn2Wm1KLEdsrMu0uAAgf1Fkdes1lf+Z9KqmHIsv8vdeIOICnoFlQDCubsvs v4SBfTZiX6XhFjd0Tc4gxBTVim4zRlgDVWz2+VJQGd/7OKz8t0e91JTXBWXiLAhwtPOR AgUA== X-Gm-Message-State: AOAM530z9n1JBpzTnYrVKQY5P0pCPIxoZVednUL2xvxkdH/EEH/V7/x7 dzng27Jbb1sO4PbsNkizgkP1KRODVCAW7QzHzvA73ipeUDTKbofRtbX8VBY0ldH5SW+eAOT9RGn /Kndspq0xt9tVLsM69RFfCO5Z5wGWrkzgelxcGo2Q5YSw635bhnJaTrDx+cyncTU5PLLG/MNSHf T4 X-Google-Smtp-Source: ABdhPJw7n73+YwCsX9Ayv2IPZncYzrsQ9cDeGA0lch/FKMdQAqoHhgZH73IkjbgVrmwc76SFF24+RuW5lZGz8JRO8UB7 X-Received: by 2002:a25:e8a:: with SMTP id 132mr832897ybo.425.1589397179583; Wed, 13 May 2020 12:12:59 -0700 (PDT) Date: Wed, 13 May 2020 12:12:48 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog Subject: [PATCH v2 3/3] http, imap-send: stop using CURLOPT_VERBOSE From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , sandals@crustytoothpaste.net, gitster@pobox.com, peff@peff.net Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Whenever GIT_CURL_VERBOSE is set, teach Git to behave as if GIT_TRACE_CURL=1 and GIT_TRACE_CURL_NO_DATA=1 is set, instead of setting CURLOPT_VERBOSE. This is to prevent inadvertent revelation of sensitive data. In particular, GIT_CURL_VERBOSE redacts neither the "Authorization" header nor any cookies specified by GIT_REDACT_COOKIES. Unifying the tracing mechanism also has the future benefit that any improvements to the tracing mechanism will benefit both users of GIT_CURL_VERBOSE and GIT_TRACE_CURL, and we do not need to remember to implement any improvement twice. Signed-off-by: Jonathan Tan --- Documentation/git.txt | 2 -- http.c | 8 +++++++- http.h | 7 +++++++ imap-send.c | 2 +- t/t5551-http-fetch-smart.sh | 24 ++++++++++++++++++++++++ t/t5581-http-curl-verbose.sh | 2 +- trace.c | 20 ++++++++++++++++---- trace.h | 6 ++++++ 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index af98cd7dc2..43a440bae4 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -721,8 +721,6 @@ of clones and fetches. Enables a curl full trace dump of all incoming and outgoing data, including descriptive information, of the git transport protocol. This is similar to doing curl `--trace-ascii` on the command line. - This option overrides setting the `GIT_CURL_VERBOSE` environment - variable. See `GIT_TRACE` for available trace output options. `GIT_TRACE_CURL_NO_DATA`:: diff --git a/http.c b/http.c index 77eac95d64..d0cea72cbd 100644 --- a/http.c +++ b/http.c @@ -806,6 +806,12 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, return 0; } +void http_trace_curl_no_data(void) +{ + trace_override_envvar(&trace_curl, "1"); + trace_curl_data = 0; +} + void setup_curl_trace(CURL *handle) { if (!trace_want(&trace_curl)) @@ -996,7 +1002,7 @@ static CURL *get_curl_handle(void) warning(_("Protocol restrictions not supported with cURL < 7.19.4")); #endif if (getenv("GIT_CURL_VERBOSE")) - curl_easy_setopt(result, CURLOPT_VERBOSE, 1L); + http_trace_curl_no_data(); setup_curl_trace(result); if (getenv("GIT_TRACE_CURL_NO_DATA")) trace_curl_data = 0; diff --git a/http.h b/http.h index 5e0ad724f9..faf8cbb0d1 100644 --- a/http.h +++ b/http.h @@ -252,6 +252,13 @@ int finish_http_object_request(struct http_object_request *freq); void abort_http_object_request(struct http_object_request *freq); void release_http_object_request(struct http_object_request *freq); +/* + * Instead of using environment variables to determine if curl tracing happens, + * behave as if GIT_TRACE_CURL=1 and GIT_TRACE_CURL_NO_DATA=1 is set. Call this + * before calling setup_curl_trace(). + */ +void http_trace_curl_no_data(void); + /* setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */ void setup_curl_trace(CURL *handle); #endif /* HTTP_H */ diff --git a/imap-send.c b/imap-send.c index 6c54d8c29d..52737546f3 100644 --- a/imap-send.c +++ b/imap-send.c @@ -1464,7 +1464,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred) curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); if (0 < verbosity || getenv("GIT_CURL_VERBOSE")) - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + http_trace_curl_no_data(); setup_curl_trace(curl); return curl; diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index eeecfe01d7..209f2f8427 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -207,6 +207,18 @@ test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_REDACT_A grep "Authorization: Basic [0-9a-zA-Z+/]" trace ' +test_expect_success 'GIT_CURL_VERBOSE redacts auth details' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace && + expect_askpass both user@host && + + # Ensure that there is no "Basic" followed by a base64 string, but that + # the auth details are redacted + ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace && + grep "Authorization: Basic " trace +' + test_expect_success 'disable dumb http on server' ' git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ config http.getanyfile false @@ -464,6 +476,18 @@ test_expect_success 'GIT_REDACT_COOKIES redacts cookies' ' ! grep "Cookie:.*Bar=2" err ' +test_expect_success 'GIT_REDACT_COOKIES redacts cookies when GIT_CURL_VERBOSE=1' ' + rm -rf clone && + echo "Set-Cookie: Foo=1" >cookies && + echo "Set-Cookie: Bar=2" >>cookies && + GIT_CURL_VERBOSE=1 GIT_REDACT_COOKIES=Bar,Baz \ + git -c "http.cookieFile=$(pwd)/cookies" clone \ + $HTTPD_URL/smart/repo.git clone 2>err && + grep "Cookie:.*Foo=1" err && + grep "Cookie:.*Bar=" err && + ! grep "Cookie:.*Bar=2" err +' + test_expect_success 'GIT_REDACT_COOKIES handles empty values' ' rm -rf clone && echo "Set-Cookie: Foo=" >cookies && diff --git a/t/t5581-http-curl-verbose.sh b/t/t5581-http-curl-verbose.sh index 5129b0724f..927aad0820 100755 --- a/t/t5581-http-curl-verbose.sh +++ b/t/t5581-http-curl-verbose.sh @@ -20,7 +20,7 @@ test_expect_success 'failure in git-upload-pack is shown' ' test_might_fail env GIT_CURL_VERBOSE=1 \ git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \ 2>curl_log && - grep "< HTTP/1.1 500 Intentional Breakage" curl_log + grep "<= Recv header: HTTP/1.1 500 Intentional Breakage" curl_log ' test_done diff --git a/trace.c b/trace.c index b3ef0e627f..f726686fd9 100644 --- a/trace.c +++ b/trace.c @@ -29,7 +29,7 @@ struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); struct trace_key trace_setup_key = TRACE_KEY_INIT(SETUP); /* Get a trace file descriptor from "key" env variable. */ -static int get_trace_fd(struct trace_key *key) +static int get_trace_fd(struct trace_key *key, const char *override_envvar) { const char *trace; @@ -37,7 +37,7 @@ static int get_trace_fd(struct trace_key *key) if (key->initialized) return key->fd; - trace = getenv(key->key); + trace = override_envvar ? override_envvar : getenv(key->key); if (!trace || !strcmp(trace, "") || !strcmp(trace, "0") || !strcasecmp(trace, "false")) @@ -68,6 +68,18 @@ static int get_trace_fd(struct trace_key *key) return key->fd; } +void trace_override_envvar(struct trace_key *key, const char *value) +{ + trace_disable(key); + key->initialized = 0; + + /* + * Invoke get_trace_fd() to initialize key using the given value + * instead of the value of the environment variable. + */ + get_trace_fd(key, value); +} + void trace_disable(struct trace_key *key) { if (key->need_close) @@ -112,7 +124,7 @@ static int prepare_trace_line(const char *file, int line, static void trace_write(struct trace_key *key, const void *buf, unsigned len) { - if (write_in_full(get_trace_fd(key), buf, len) < 0) { + if (write_in_full(get_trace_fd(key, NULL), buf, len) < 0) { warning("unable to write trace for %s: %s", key->key, strerror(errno)); trace_disable(key); @@ -383,7 +395,7 @@ void trace_repo_setup(const char *prefix) int trace_want(struct trace_key *key) { - return !!get_trace_fd(key); + return !!get_trace_fd(key, NULL); } #if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) diff --git a/trace.h b/trace.h index 9826618b33..0dbbad0e41 100644 --- a/trace.h +++ b/trace.h @@ -101,6 +101,12 @@ void trace_repo_setup(const char *prefix); */ int trace_want(struct trace_key *key); +/** + * Enables or disables tracing for the specified key, as if the environment + * variable was set to the given value. + */ +void trace_override_envvar(struct trace_key *key, const char *value); + /** * Disables tracing for the specified key, even if the environment variable * was set.