@@ -723,7 +723,7 @@ static int has_proxy_cert_password(void)
723723}
724724
725725/* Return 1 if redactions have been made, 0 otherwise. */
726- static int redact_sensitive_header (struct strbuf * header , size_t offset )
726+ static int redact_http_header (struct strbuf * header , size_t offset )
727727{
728728 int ret = 0 ;
729729 const char * sensitive_header ;
@@ -820,14 +820,67 @@ static void redact_sensitive_info_header(struct strbuf *header)
820820
821821 if (trace_curl_redact &&
822822 match_curl_h2_trace (header -> buf , & sensitive_header )) {
823- if (redact_sensitive_header (header , sensitive_header - header -> buf )) {
823+ if (redact_http_header (header , sensitive_header - header -> buf )) {
824824 /* redaction ate our closing bracket */
825825 strbuf_addch (header , ']' );
826826 }
827827 }
828828}
829829
830- static void curl_dump_header (const char * text , unsigned char * ptr , size_t size , int hide_sensitive_header )
830+ static void redact_imap_header (struct strbuf * header )
831+ {
832+ const char * p ;
833+
834+ /* skip past the command tag */
835+ p = strchr (header -> buf , ' ' );
836+ if (!p )
837+ return ; /* no tag */
838+ p ++ ;
839+
840+ if (skip_prefix (p , "AUTHENTICATE " , & p )) {
841+ /* the first token is the auth type, which is OK to log */
842+ while (* p && !isspace (* p ))
843+ p ++ ;
844+ /* the rest is an opaque blob; fall through to redact */
845+ } else if (skip_prefix (p , "LOGIN " , & p )) {
846+ /* fall through to redact both login and password */
847+ } else {
848+ /* not a sensitive header */
849+ return ;
850+ }
851+
852+ strbuf_setlen (header , p - header -> buf );
853+ strbuf_addstr (header , " <redacted>" );
854+ }
855+
856+ static void redact_sensitive_header (CURL * handle , struct strbuf * header )
857+ {
858+ const char * url ;
859+ int ret ;
860+
861+ ret = curl_easy_getinfo (handle , CURLINFO_EFFECTIVE_URL , & url );
862+ if (!ret && url ) {
863+ if (starts_with (url , "http" )) {
864+ redact_http_header (header , 0 );
865+ return ;
866+ }
867+ if (starts_with (url , "imap" )) {
868+ redact_imap_header (header );
869+ return ;
870+ }
871+ }
872+
873+ /*
874+ * We weren't able to figure out the protocol. Err on the side of
875+ * redacting too much.
876+ */
877+ redact_http_header (header , 0 );
878+ redact_imap_header (header );
879+ }
880+
881+ static void curl_dump_header (CURL * handle , const char * text ,
882+ unsigned char * ptr , size_t size ,
883+ int hide_sensitive_header )
831884{
832885 struct strbuf out = STRBUF_INIT ;
833886 struct strbuf * * headers , * * header ;
@@ -841,7 +894,7 @@ static void curl_dump_header(const char *text, unsigned char *ptr, size_t size,
841894
842895 for (header = headers ; * header ; header ++ ) {
843896 if (hide_sensitive_header )
844- redact_sensitive_header (* header , 0 );
897+ redact_sensitive_header (handle , * header );
845898 strbuf_insertstr ((* header ), 0 , text );
846899 strbuf_insertstr ((* header ), strlen (text ), ": " );
847900 strbuf_rtrim ((* header ));
@@ -892,7 +945,7 @@ static void curl_dump_info(char *data, size_t size)
892945 strbuf_release (& buf );
893946}
894947
895- static int curl_trace (CURL * handle UNUSED , curl_infotype type ,
948+ static int curl_trace (CURL * handle , curl_infotype type ,
896949 char * data , size_t size ,
897950 void * userp UNUSED )
898951{
@@ -905,7 +958,7 @@ static int curl_trace(CURL *handle UNUSED, curl_infotype type,
905958 break ;
906959 case CURLINFO_HEADER_OUT :
907960 text = "=> Send header" ;
908- curl_dump_header (text , (unsigned char * )data , size , DO_FILTER );
961+ curl_dump_header (handle , text , (unsigned char * )data , size , DO_FILTER );
909962 break ;
910963 case CURLINFO_DATA_OUT :
911964 if (trace_curl_data ) {
@@ -921,7 +974,7 @@ static int curl_trace(CURL *handle UNUSED, curl_infotype type,
921974 break ;
922975 case CURLINFO_HEADER_IN :
923976 text = "<= Recv header" ;
924- curl_dump_header (text , (unsigned char * )data , size , NO_FILTER );
977+ curl_dump_header (handle , text , (unsigned char * )data , size , NO_FILTER );
925978 break ;
926979 case CURLINFO_DATA_IN :
927980 if (trace_curl_data ) {
0 commit comments