Skip to content

Commit 0b925a4

Browse files
committed
Merge branch 'jt/curl-verbose-on-trace-curl'
Rewrite support for GIT_CURL_VERBOSE in terms of GIT_TRACE_CURL. Looking good. * jt/curl-verbose-on-trace-curl: http, imap-send: stop using CURLOPT_VERBOSE t5551: test that GIT_TRACE_CURL redacts password
2 parents 8d04c98 + 7167a62 commit 0b925a4

File tree

8 files changed

+74
-9
lines changed

8 files changed

+74
-9
lines changed

Documentation/git.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,6 @@ of clones and fetches.
721721
Enables a curl full trace dump of all incoming and outgoing data,
722722
including descriptive information, of the git transport protocol.
723723
This is similar to doing curl `--trace-ascii` on the command line.
724-
This option overrides setting the `GIT_CURL_VERBOSE` environment
725-
variable.
726724
See `GIT_TRACE` for available trace output options.
727725

728726
`GIT_TRACE_CURL_NO_DATA`::

http.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,12 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
804804
return 0;
805805
}
806806

807+
void http_trace_curl_no_data(void)
808+
{
809+
trace_override_envvar(&trace_curl, "1");
810+
trace_curl_data = 0;
811+
}
812+
807813
void setup_curl_trace(CURL *handle)
808814
{
809815
if (!trace_want(&trace_curl))
@@ -993,7 +999,7 @@ static CURL *get_curl_handle(void)
993999
warning(_("Protocol restrictions not supported with cURL < 7.19.4"));
9941000
#endif
9951001
if (getenv("GIT_CURL_VERBOSE"))
996-
curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
1002+
http_trace_curl_no_data();
9971003
setup_curl_trace(result);
9981004
if (getenv("GIT_TRACE_CURL_NO_DATA"))
9991005
trace_curl_data = 0;

http.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ int finish_http_object_request(struct http_object_request *freq);
252252
void abort_http_object_request(struct http_object_request *freq);
253253
void release_http_object_request(struct http_object_request *freq);
254254

255+
/*
256+
* Instead of using environment variables to determine if curl tracing happens,
257+
* behave as if GIT_TRACE_CURL=1 and GIT_TRACE_CURL_NO_DATA=1 is set. Call this
258+
* before calling setup_curl_trace().
259+
*/
260+
void http_trace_curl_no_data(void);
261+
255262
/* setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */
256263
void setup_curl_trace(CURL *handle);
257264
#endif /* HTTP_H */

imap-send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
14641464
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
14651465

14661466
if (0 < verbosity || getenv("GIT_CURL_VERBOSE"))
1467-
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
1467+
http_trace_curl_no_data();
14681468
setup_curl_trace(curl);
14691469

14701470
return curl;

t/t5551-http-fetch-smart.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ test_expect_success 'redirects send auth to new location' '
185185
expect_askpass both user@host auth/smart/repo.git
186186
'
187187

188+
test_expect_success 'GIT_TRACE_CURL redacts auth details' '
189+
rm -rf redact-auth trace &&
190+
set_askpass user@host pass@host &&
191+
GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
192+
expect_askpass both user@host &&
193+
194+
# Ensure that there is no "Basic" followed by a base64 string, but that
195+
# the auth details are redacted
196+
! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
197+
grep "Authorization: Basic <redacted>" trace
198+
'
199+
200+
test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
201+
rm -rf redact-auth trace &&
202+
set_askpass user@host pass@host &&
203+
GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace &&
204+
expect_askpass both user@host &&
205+
206+
# Ensure that there is no "Basic" followed by a base64 string, but that
207+
# the auth details are redacted
208+
! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
209+
grep "Authorization: Basic <redacted>" trace
210+
'
211+
188212
test_expect_success 'disable dumb http on server' '
189213
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
190214
config http.getanyfile false
@@ -442,6 +466,18 @@ test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
442466
! grep "Cookie:.*Bar=2" err
443467
'
444468

469+
test_expect_success 'GIT_REDACT_COOKIES redacts cookies when GIT_CURL_VERBOSE=1' '
470+
rm -rf clone &&
471+
echo "Set-Cookie: Foo=1" >cookies &&
472+
echo "Set-Cookie: Bar=2" >>cookies &&
473+
GIT_CURL_VERBOSE=1 GIT_REDACT_COOKIES=Bar,Baz \
474+
git -c "http.cookieFile=$(pwd)/cookies" clone \
475+
$HTTPD_URL/smart/repo.git clone 2>err &&
476+
grep "Cookie:.*Foo=1" err &&
477+
grep "Cookie:.*Bar=<redacted>" err &&
478+
! grep "Cookie:.*Bar=2" err
479+
'
480+
445481
test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
446482
rm -rf clone &&
447483
echo "Set-Cookie: Foo=" >cookies &&

t/t5581-http-curl-verbose.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_expect_success 'failure in git-upload-pack is shown' '
2020
test_might_fail env GIT_CURL_VERBOSE=1 \
2121
git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \
2222
2>curl_log &&
23-
grep "< HTTP/1.1 500 Intentional Breakage" curl_log
23+
grep "<= Recv header: HTTP/1.1 500 Intentional Breakage" curl_log
2424
'
2525

2626
test_done

trace.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);
2929
struct trace_key trace_setup_key = TRACE_KEY_INIT(SETUP);
3030

3131
/* Get a trace file descriptor from "key" env variable. */
32-
static int get_trace_fd(struct trace_key *key)
32+
static int get_trace_fd(struct trace_key *key, const char *override_envvar)
3333
{
3434
const char *trace;
3535

3636
/* don't open twice */
3737
if (key->initialized)
3838
return key->fd;
3939

40-
trace = getenv(key->key);
40+
trace = override_envvar ? override_envvar : getenv(key->key);
4141

4242
if (!trace || !strcmp(trace, "") ||
4343
!strcmp(trace, "0") || !strcasecmp(trace, "false"))
@@ -68,6 +68,18 @@ static int get_trace_fd(struct trace_key *key)
6868
return key->fd;
6969
}
7070

71+
void trace_override_envvar(struct trace_key *key, const char *value)
72+
{
73+
trace_disable(key);
74+
key->initialized = 0;
75+
76+
/*
77+
* Invoke get_trace_fd() to initialize key using the given value
78+
* instead of the value of the environment variable.
79+
*/
80+
get_trace_fd(key, value);
81+
}
82+
7183
void trace_disable(struct trace_key *key)
7284
{
7385
if (key->need_close)
@@ -112,7 +124,7 @@ static int prepare_trace_line(const char *file, int line,
112124

113125
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
114126
{
115-
if (write_in_full(get_trace_fd(key), buf, len) < 0) {
127+
if (write_in_full(get_trace_fd(key, NULL), buf, len) < 0) {
116128
warning("unable to write trace for %s: %s",
117129
key->key, strerror(errno));
118130
trace_disable(key);
@@ -383,7 +395,7 @@ void trace_repo_setup(const char *prefix)
383395

384396
int trace_want(struct trace_key *key)
385397
{
386-
return !!get_trace_fd(key);
398+
return !!get_trace_fd(key, NULL);
387399
}
388400

389401
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)

trace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ void trace_repo_setup(const char *prefix);
101101
*/
102102
int trace_want(struct trace_key *key);
103103

104+
/**
105+
* Enables or disables tracing for the specified key, as if the environment
106+
* variable was set to the given value.
107+
*/
108+
void trace_override_envvar(struct trace_key *key, const char *value);
109+
104110
/**
105111
* Disables tracing for the specified key, even if the environment variable
106112
* was set.

0 commit comments

Comments
 (0)