18
18
19
19
static struct trace_key trace_curl = TRACE_KEY_INIT (CURL );
20
20
static int trace_curl_data = 1 ;
21
- static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP ;
21
+ static int trace_curl_redact = 1 ;
22
22
#if LIBCURL_VERSION_NUM >= 0x070a08
23
23
long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER ;
24
24
#else
@@ -642,8 +642,9 @@ static void redact_sensitive_header(struct strbuf *header)
642
642
{
643
643
const char * sensitive_header ;
644
644
645
- if (skip_prefix (header -> buf , "Authorization:" , & sensitive_header ) ||
646
- skip_prefix (header -> buf , "Proxy-Authorization:" , & sensitive_header )) {
645
+ if (trace_curl_redact &&
646
+ (skip_prefix (header -> buf , "Authorization:" , & sensitive_header ) ||
647
+ skip_prefix (header -> buf , "Proxy-Authorization:" , & sensitive_header ))) {
647
648
/* The first token is the type, which is OK to log */
648
649
while (isspace (* sensitive_header ))
649
650
sensitive_header ++ ;
@@ -652,20 +653,15 @@ static void redact_sensitive_header(struct strbuf *header)
652
653
/* Everything else is opaque and possibly sensitive */
653
654
strbuf_setlen (header , sensitive_header - header -> buf );
654
655
strbuf_addstr (header , " <redacted>" );
655
- } else if (cookies_to_redact . nr &&
656
+ } else if (trace_curl_redact &&
656
657
skip_prefix (header -> buf , "Cookie:" , & sensitive_header )) {
657
658
struct strbuf redacted_header = STRBUF_INIT ;
658
- char * cookie ;
659
+ const char * cookie ;
659
660
660
661
while (isspace (* sensitive_header ))
661
662
sensitive_header ++ ;
662
663
663
- /*
664
- * The contents of header starting from sensitive_header will
665
- * subsequently be overridden, so it is fine to mutate this
666
- * string (hence the assignment to "char *").
667
- */
668
- cookie = (char * ) sensitive_header ;
664
+ cookie = sensitive_header ;
669
665
670
666
while (cookie ) {
671
667
char * equals ;
@@ -678,14 +674,8 @@ static void redact_sensitive_header(struct strbuf *header)
678
674
strbuf_addstr (& redacted_header , cookie );
679
675
continue ;
680
676
}
681
- * equals = 0 ; /* temporarily set to NUL for lookup */
682
- if (string_list_lookup (& cookies_to_redact , cookie )) {
683
- strbuf_addstr (& redacted_header , cookie );
684
- strbuf_addstr (& redacted_header , "=<redacted>" );
685
- } else {
686
- * equals = '=' ;
687
- strbuf_addstr (& redacted_header , cookie );
688
- }
677
+ strbuf_add (& redacted_header , cookie , equals - cookie );
678
+ strbuf_addstr (& redacted_header , "=<redacted>" );
689
679
if (semicolon ) {
690
680
/*
691
681
* There are more cookies. (Or, for some
@@ -1003,11 +993,8 @@ static CURL *get_curl_handle(void)
1003
993
setup_curl_trace (result );
1004
994
if (getenv ("GIT_TRACE_CURL_NO_DATA" ))
1005
995
trace_curl_data = 0 ;
1006
- if (getenv ("GIT_REDACT_COOKIES" )) {
1007
- string_list_split (& cookies_to_redact ,
1008
- getenv ("GIT_REDACT_COOKIES" ), ',' , -1 );
1009
- string_list_sort (& cookies_to_redact );
1010
- }
996
+ if (!git_env_bool ("GIT_TRACE_REDACT" , 1 ))
997
+ trace_curl_redact = 0 ;
1011
998
1012
999
curl_easy_setopt (result , CURLOPT_USERAGENT ,
1013
1000
user_agent ? user_agent : git_user_agent ());
0 commit comments