Skip to content

Commit e1813a3

Browse files
committed
Merge branch 'jk/redact-h2h3-headers-fix' into maint-2.42
HTTP Header redaction code has been adjusted for a newer version of cURL library that shows its traces differently from earlier versions. * jk/redact-h2h3-headers-fix: http: update curl http/2 info matching for curl 8.3.0 http: factor out matching of curl http/2 trace lines This backport to `maint-2.39` is needed to bring the following test cases back to a working state in conjunction with recent libcurl versions: - t5559.17 GIT_TRACE_CURL redacts auth details - t5559.18 GIT_CURL_VERBOSE redacts auth details - t5559.38 cookies are redacted by default Signed-off-by: Johannes Schindelin <[email protected]>
2 parents ef0fc42 + 0763c3a commit e1813a3

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

http.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,43 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
618618
return ret;
619619
}
620620

621+
static int match_curl_h2_trace(const char *line, const char **out)
622+
{
623+
const char *p;
624+
625+
/*
626+
* curl prior to 8.1.0 gives us:
627+
*
628+
* h2h3 [<header-name>: <header-val>]
629+
*
630+
* Starting in 8.1.0, the first token became just "h2".
631+
*/
632+
if (skip_iprefix(line, "h2h3 [", out) ||
633+
skip_iprefix(line, "h2 [", out))
634+
return 1;
635+
636+
/*
637+
* curl 8.3.0 uses:
638+
* [HTTP/2] [<stream-id>] [<header-name>: <header-val>]
639+
* where <stream-id> is numeric.
640+
*/
641+
if (skip_iprefix(line, "[HTTP/2] [", &p)) {
642+
while (isdigit(*p))
643+
p++;
644+
if (skip_prefix(p, "] [", out))
645+
return 1;
646+
}
647+
648+
return 0;
649+
}
650+
621651
/* Redact headers in info */
622652
static void redact_sensitive_info_header(struct strbuf *header)
623653
{
624654
const char *sensitive_header;
625655

626-
/*
627-
* curl's h2h3 prints headers in info, e.g.:
628-
* h2h3 [<header-name>: <header-val>]
629-
*/
630656
if (trace_curl_redact &&
631-
skip_iprefix(header->buf, "h2h3 [", &sensitive_header)) {
657+
match_curl_h2_trace(header->buf, &sensitive_header)) {
632658
if (redact_sensitive_header(header, sensitive_header - header->buf)) {
633659
/* redaction ate our closing bracket */
634660
strbuf_addch(header, ']');

0 commit comments

Comments
 (0)