1818
1919static struct trace_key trace_curl = TRACE_KEY_INIT (CURL );
2020static int trace_curl_data = 1 ;
21- static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP ;
21+ static int trace_curl_redact = 1 ;
2222#if LIBCURL_VERSION_NUM >= 0x070a08
2323long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER ;
2424#else
@@ -642,8 +642,9 @@ static void redact_sensitive_header(struct strbuf *header)
642642{
643643 const char * sensitive_header ;
644644
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 ))) {
647648 /* The first token is the type, which is OK to log */
648649 while (isspace (* sensitive_header ))
649650 sensitive_header ++ ;
@@ -652,20 +653,15 @@ static void redact_sensitive_header(struct strbuf *header)
652653 /* Everything else is opaque and possibly sensitive */
653654 strbuf_setlen (header , sensitive_header - header -> buf );
654655 strbuf_addstr (header , " <redacted>" );
655- } else if (cookies_to_redact . nr &&
656+ } else if (trace_curl_redact &&
656657 skip_prefix (header -> buf , "Cookie:" , & sensitive_header )) {
657658 struct strbuf redacted_header = STRBUF_INIT ;
658- char * cookie ;
659+ const char * cookie ;
659660
660661 while (isspace (* sensitive_header ))
661662 sensitive_header ++ ;
662663
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 ;
669665
670666 while (cookie ) {
671667 char * equals ;
@@ -678,14 +674,8 @@ static void redact_sensitive_header(struct strbuf *header)
678674 strbuf_addstr (& redacted_header , cookie );
679675 continue ;
680676 }
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>" );
689679 if (semicolon ) {
690680 /*
691681 * There are more cookies. (Or, for some
@@ -1003,11 +993,8 @@ static CURL *get_curl_handle(void)
1003993 setup_curl_trace (result );
1004994 if (getenv ("GIT_TRACE_CURL_NO_DATA" ))
1005995 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 ;
1011998
1012999 curl_easy_setopt (result , CURLOPT_USERAGENT ,
10131000 user_agent ? user_agent : git_user_agent ());
0 commit comments