@@ -745,7 +745,7 @@ static int has_proxy_cert_password(void)
745745}
746746
747747/* Return 1 if redactions have been made, 0 otherwise. */
748- static int redact_sensitive_header (struct strbuf * header , size_t offset )
748+ static int redact_http_header (struct strbuf * header , size_t offset )
749749{
750750 int ret = 0 ;
751751 char * sensitive_header ;
@@ -842,14 +842,67 @@ static void redact_sensitive_info_header(struct strbuf *header)
842842
843843 if (trace_curl_redact &&
844844 match_curl_h2_trace (header -> buf , & sensitive_header )) {
845- if (redact_sensitive_header (header , sensitive_header - header -> buf )) {
845+ if (redact_http_header (header , sensitive_header - header -> buf )) {
846846 /* redaction ate our closing bracket */
847847 strbuf_addch (header , ']' );
848848 }
849849 }
850850}
851851
852- static void curl_dump_header (const char * text , unsigned char * ptr , size_t size , int hide_sensitive_header )
852+ static void redact_imap_header (struct strbuf * header )
853+ {
854+ const char * p ;
855+
856+ /* skip past the command tag */
857+ p = strchr (header -> buf , ' ' );
858+ if (!p )
859+ return ; /* no tag */
860+ p ++ ;
861+
862+ if (skip_prefix (p , "AUTHENTICATE " , & p )) {
863+ /* the first token is the auth type, which is OK to log */
864+ while (* p && !isspace (* p ))
865+ p ++ ;
866+ /* the rest is an opaque blob; fall through to redact */
867+ } else if (skip_prefix (p , "LOGIN " , & p )) {
868+ /* fall through to redact both login and password */
869+ } else {
870+ /* not a sensitive header */
871+ return ;
872+ }
873+
874+ strbuf_setlen (header , p - header -> buf );
875+ strbuf_addstr (header , " <redacted>" );
876+ }
877+
878+ static void redact_sensitive_header (CURL * handle , struct strbuf * header )
879+ {
880+ const char * url ;
881+ int ret ;
882+
883+ ret = curl_easy_getinfo (handle , CURLINFO_EFFECTIVE_URL , & url );
884+ if (!ret && url ) {
885+ if (starts_with (url , "http" )) {
886+ redact_http_header (header , 0 );
887+ return ;
888+ }
889+ if (starts_with (url , "imap" )) {
890+ redact_imap_header (header );
891+ return ;
892+ }
893+ }
894+
895+ /*
896+ * We weren't able to figure out the protocol. Err on the side of
897+ * redacting too much.
898+ */
899+ redact_http_header (header , 0 );
900+ redact_imap_header (header );
901+ }
902+
903+ static void curl_dump_header (CURL * handle , const char * text ,
904+ unsigned char * ptr , size_t size ,
905+ int hide_sensitive_header )
853906{
854907 struct strbuf out = STRBUF_INIT ;
855908 struct strbuf * * headers , * * header ;
@@ -863,7 +916,7 @@ static void curl_dump_header(const char *text, unsigned char *ptr, size_t size,
863916
864917 for (header = headers ; * header ; header ++ ) {
865918 if (hide_sensitive_header )
866- redact_sensitive_header (* header , 0 );
919+ redact_sensitive_header (handle , * header );
867920 strbuf_insertstr ((* header ), 0 , text );
868921 strbuf_insertstr ((* header ), strlen (text ), ": " );
869922 strbuf_rtrim ((* header ));
@@ -914,7 +967,7 @@ static void curl_dump_info(char *data, size_t size)
914967 strbuf_release (& buf );
915968}
916969
917- static int curl_trace (CURL * handle UNUSED , curl_infotype type ,
970+ static int curl_trace (CURL * handle , curl_infotype type ,
918971 char * data , size_t size ,
919972 void * userp UNUSED )
920973{
@@ -927,7 +980,7 @@ static int curl_trace(CURL *handle UNUSED, curl_infotype type,
927980 break ;
928981 case CURLINFO_HEADER_OUT :
929982 text = "=> Send header" ;
930- curl_dump_header (text , (unsigned char * )data , size , DO_FILTER );
983+ curl_dump_header (handle , text , (unsigned char * )data , size , DO_FILTER );
931984 break ;
932985 case CURLINFO_DATA_OUT :
933986 if (trace_curl_data ) {
@@ -943,7 +996,7 @@ static int curl_trace(CURL *handle UNUSED, curl_infotype type,
943996 break ;
944997 case CURLINFO_HEADER_IN :
945998 text = "<= Recv header" ;
946- curl_dump_header (text , (unsigned char * )data , size , NO_FILTER );
999+ curl_dump_header (handle , text , (unsigned char * )data , size , NO_FILTER );
9471000 break ;
9481001 case CURLINFO_DATA_IN :
9491002 if (trace_curl_data ) {
0 commit comments