Skip to content

Commit 6adf170

Browse files
committed
Merge branch 'gc/redact-h2h3-headers'
Redact headers from cURL's h2h3 module in GIT_CURL_VERBOSE and others. * gc/redact-h2h3-headers: http: redact curl h2h3 headers in info t: run t5551 tests with both HTTP and HTTP/2
2 parents 4b76998 + b637a41 commit 6adf170

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

http.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,13 +560,15 @@ static void set_curl_keepalive(CURL *c)
560560
}
561561
#endif
562562

563-
static void redact_sensitive_header(struct strbuf *header)
563+
/* Return 1 if redactions have been made, 0 otherwise. */
564+
static int redact_sensitive_header(struct strbuf *header, size_t offset)
564565
{
566+
int ret = 0;
565567
const char *sensitive_header;
566568

567569
if (trace_curl_redact &&
568-
(skip_iprefix(header->buf, "Authorization:", &sensitive_header) ||
569-
skip_iprefix(header->buf, "Proxy-Authorization:", &sensitive_header))) {
570+
(skip_iprefix(header->buf + offset, "Authorization:", &sensitive_header) ||
571+
skip_iprefix(header->buf + offset, "Proxy-Authorization:", &sensitive_header))) {
570572
/* The first token is the type, which is OK to log */
571573
while (isspace(*sensitive_header))
572574
sensitive_header++;
@@ -575,8 +577,9 @@ static void redact_sensitive_header(struct strbuf *header)
575577
/* Everything else is opaque and possibly sensitive */
576578
strbuf_setlen(header, sensitive_header - header->buf);
577579
strbuf_addstr(header, " <redacted>");
580+
ret = 1;
578581
} else if (trace_curl_redact &&
579-
skip_iprefix(header->buf, "Cookie:", &sensitive_header)) {
582+
skip_iprefix(header->buf + offset, "Cookie:", &sensitive_header)) {
580583
struct strbuf redacted_header = STRBUF_INIT;
581584
const char *cookie;
582585

@@ -612,6 +615,26 @@ static void redact_sensitive_header(struct strbuf *header)
612615

613616
strbuf_setlen(header, sensitive_header - header->buf);
614617
strbuf_addbuf(header, &redacted_header);
618+
ret = 1;
619+
}
620+
return ret;
621+
}
622+
623+
/* Redact headers in info */
624+
static void redact_sensitive_info_header(struct strbuf *header)
625+
{
626+
const char *sensitive_header;
627+
628+
/*
629+
* curl's h2h3 prints headers in info, e.g.:
630+
* h2h3 [<header-name>: <header-val>]
631+
*/
632+
if (trace_curl_redact &&
633+
skip_iprefix(header->buf, "h2h3 [", &sensitive_header)) {
634+
if (redact_sensitive_header(header, sensitive_header - header->buf)) {
635+
/* redaction ate our closing bracket */
636+
strbuf_addch(header, ']');
637+
}
615638
}
616639
}
617640

@@ -629,7 +652,7 @@ static void curl_dump_header(const char *text, unsigned char *ptr, size_t size,
629652

630653
for (header = headers; *header; header++) {
631654
if (hide_sensitive_header)
632-
redact_sensitive_header(*header);
655+
redact_sensitive_header(*header, 0);
633656
strbuf_insertstr((*header), 0, text);
634657
strbuf_insertstr((*header), strlen(text), ": ");
635658
strbuf_rtrim((*header));
@@ -668,14 +691,26 @@ static void curl_dump_data(const char *text, unsigned char *ptr, size_t size)
668691
strbuf_release(&out);
669692
}
670693

694+
static void curl_dump_info(char *data, size_t size)
695+
{
696+
struct strbuf buf = STRBUF_INIT;
697+
698+
strbuf_add(&buf, data, size);
699+
700+
redact_sensitive_info_header(&buf);
701+
trace_printf_key(&trace_curl, "== Info: %s", buf.buf);
702+
703+
strbuf_release(&buf);
704+
}
705+
671706
static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp)
672707
{
673708
const char *text;
674709
enum { NO_FILTER = 0, DO_FILTER = 1 };
675710

676711
switch (type) {
677712
case CURLINFO_TEXT:
678-
trace_printf_key(&trace_curl, "== Info: %s", data);
713+
curl_dump_info(data, size);
679714
break;
680715
case CURLINFO_HEADER_OUT:
681716
text = "=> Send header";

t/lib-httpd.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ prepare_httpd() {
174174
fi
175175
}
176176

177+
enable_http2 () {
178+
HTTPD_PARA="$HTTPD_PARA -DHTTP2"
179+
test_set_prereq HTTP2
180+
}
181+
177182
start_httpd() {
178183
prepare_httpd >&3 2>&4
179184

t/lib-httpd/apache.conf

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ ErrorLog error.log
2929
LoadModule setenvif_module modules/mod_setenvif.so
3030
</IfModule>
3131

32+
<IfDefine HTTP2>
33+
LoadModule http2_module modules/mod_http2.so
34+
Protocols h2c
35+
</IfDefine>
36+
3237
<IfVersion < 2.4>
3338
LockFile accept.lock
3439
</IfVersion>
@@ -64,12 +69,20 @@ LockFile accept.lock
6469
<IfModule !mod_access_compat.c>
6570
LoadModule access_compat_module modules/mod_access_compat.so
6671
</IfModule>
67-
<IfModule !mod_mpm_prefork.c>
68-
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
69-
</IfModule>
7072
<IfModule !mod_unixd.c>
7173
LoadModule unixd_module modules/mod_unixd.so
7274
</IfModule>
75+
76+
<IfDefine HTTP2>
77+
<IfModule !mod_mpm_event.c>
78+
LoadModule mpm_event_module modules/mod_mpm_event.so
79+
</IfModule>
80+
</IfDefine>
81+
<IfDefine !HTTP2>
82+
<IfModule !mod_mpm_prefork.c>
83+
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
84+
</IfModule>
85+
</IfDefine>
7386
</IfVersion>
7487

7588
PassEnv GIT_VALGRIND

t/t5551-http-fetch-smart.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/bin/sh
22

3-
test_description='test smart fetching over http via http-backend'
3+
: ${HTTP_PROTO:=HTTP}
4+
test_description="test smart fetching over http via http-backend ($HTTP_PROTO)"
45
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
56
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
67

78
. ./test-lib.sh
89
. "$TEST_DIRECTORY"/lib-httpd.sh
10+
test "$HTTP_PROTO" = "HTTP/2" && enable_http2
911
start_httpd
1012

13+
test_expect_success HTTP2 'enable client-side http/2' '
14+
git config --global http.version HTTP/2
15+
'
16+
1117
test_expect_success 'setup repository' '
1218
git config push.default matching &&
1319
echo content >file &&
@@ -347,7 +353,10 @@ test_expect_success CMDLINE_LIMIT \
347353
test_expect_success 'large fetch-pack requests can be sent using chunked encoding' '
348354
GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
349355
clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
350-
grep "^=> Send header: Transfer-Encoding: chunked" err
356+
{
357+
test_have_prereq HTTP2 ||
358+
grep "^=> Send header: Transfer-Encoding: chunked" err
359+
}
351360
'
352361

353362
test_expect_success 'test allowreachablesha1inwant' '

t/t5559-http-fetch-smart-http2.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
HTTP_PROTO=HTTP/2
4+
. ./t5551-http-fetch-smart.sh

0 commit comments

Comments
 (0)