@@ -403,6 +403,7 @@ def __init__(self,
403403 self ._output_is_tty = False
404404 self ._input_is_tty = False
405405 self ._exit_buffer = SetBufferIO ()
406+ self ._error_buffer = SetBufferIO ()
406407 self .set_input_stream (input_stream )
407408 self .set_output_stream (output_stream )
408409
@@ -551,6 +552,11 @@ def get_exit_buffer(self):
551552 return self ._root_io .get_exit_buffer ()
552553 return self ._exit_buffer
553554
555+ def get_error_buffer (self ):
556+ if self ._root_io :
557+ return self ._root_io .get_error_buffer ()
558+ return self ._error_buffer
559+
554560 def _start_buffer_io (self ):
555561 if self ._root_io :
556562 return False
@@ -811,6 +817,9 @@ def warn(self, msg, *args, **kwargs):
811817 self ._print (MsgLevel .WARN , msg , prev_msg = self .WARNING_PREV .format (self .isatty ()), * args , ** kwargs )
812818
813819 def error (self , msg , * args , ** kwargs ):
820+ error_buffer = self .get_error_buffer ()
821+ error_msg = self .log_masking (str (msg ), ip_masking = True )
822+ error_buffer .write (error_msg )
814823 self ._print (MsgLevel .ERROR , msg , prev_msg = self .ERROR_PREV .format (self .isatty ()), * args , ** kwargs )
815824
816825 def critical (self , msg , * args , ** kwargs ):
@@ -824,18 +833,18 @@ def critical(self, msg, *args, **kwargs):
824833 self .exit (code )
825834
826835 def contains_keys (self , msg ):
827- keywords = ["IDENTIFIED" , "PASSWORD" , "CONNECT" , "EXECUTER" , "CLIENT" , "PASSWD" , "_PASSKEY" , "SUDO" , "ACCESS_" ]
836+ keywords = ["IDENTIFIED" , "PASSWORD" , "CONNECT" , "EXECUTER" , "CLIENT" , "PASSWD" , "_PASSKEY" , "SUDO" , "ACCESS_" , "HOST INIT" , "CHPASSWD" ]
828837 return any (keyword in msg .upper () for keyword in keywords )
829838
830839 def table_log_masking (self , msg ):
831- regex = r' (\|\s*( http://[^\s]+) \s*\|\s*admin\ s*\|\s*)(\S+)( \s*\|\s*active\s*\|)'
840+ regex = r" (\|\s*http://[^\s]+\s*\|\s*\S+\ s*\|\s*')([^']*)(' \s*\|\s*active\s*\|)"
832841 pattern = re .compile (regex )
833842 str_msg = str (msg )
834843 if 'active' in str_msg :
835844 match = re .search (pattern , str_msg )
836845 if match :
837- masked_password = "*" * len (match .group (3 ))
838- str_msg = pattern .sub (rf"\1{ masked_password } \4 " , str_msg )
846+ masked_password = "*" * len (match .group (2 ))
847+ str_msg = pattern .sub (rf"\1{ masked_password } \3 " , str_msg )
839848 elif 'access_' in str_msg :
840849 access_regex = r"(access_id=)[^&]*|(access_key=)[^&,| ]*"
841850 access_pattern = re .compile (access_regex )
@@ -853,7 +862,7 @@ def replace_with_stars(match):
853862 def log_masking_static (msg ):
854863 def contains_keys (msg ):
855864 keywords = ["IDENTIFIED" , "PASSWORD" , "CONNECT" , "EXECUTER" , "CLIENT" , "PASSWD" , "_PASSKEY" , "SUDO" ,
856- "ACCESS_" ]
865+ "ACCESS_" , "HOST INIT" , "CHPASSWD" ]
857866 return any (keyword in msg .upper () for keyword in keywords )
858867
859868 log_regex = [
@@ -891,6 +900,18 @@ def contains_keys(msg):
891900 if "IDENTIFIED BY" in msg :
892901 return desensitize_sql_pwd (msg )
893902
903+ if "host init" in msg :
904+ host_reg = r'(obd host init\s+.*?)(-p\s+)([^\s\'\"\`]+)'
905+ host_pattern = re .compile (host_reg )
906+ if host_pattern .search (msg ):
907+ return host_pattern .sub (r'\1\2******' , msg )
908+
909+ if "chpasswd" in msg :
910+ chpasswd_reg = r'(echo\s*"[^:]+:)([^"]+)(".*chpasswd)'
911+ chpasswd_pattern = re .compile (chpasswd_reg )
912+ if chpasswd_pattern .search (msg ):
913+ return chpasswd_pattern .sub (r'\1******\3' , msg )
914+
894915 pwd_args_regex = r"(_password \S+.*args:\s*\[['\"]?)([^\s'\"']+)(['\"]*)"
895916 arg_pattern = re .compile (pwd_args_regex )
896917 if arg_pattern .search (msg ):
@@ -910,9 +931,15 @@ def contains_keys(msg):
910931 pwd_pattern = re .compile (echo_pwd_regex )
911932 if pwd_pattern .search (msg ):
912933 return pwd_pattern .sub (r"\1******\3" , msg )
934+
935+ opts_regex = r'(\'password\':\s*\')([^\']+)(\')'
936+ opts_pattern = re .compile (opts_regex )
937+ if opts_pattern .search (msg ):
938+ return opts_pattern .sub (r"\1******\3" , msg )
939+
913940 return msg
914941
915- def log_masking (self , msg ):
942+ def log_masking (self , msg , ip_masking = False ):
916943 log_regex = [
917944 r"((-P\s*\S+\s+.*?)-p\s*['\"]?)([^\s'\"']+)(['\"]*)" ,
918945 r"(_PASSWORD\s*(=|to)\s*['\"]*)([^\s'\"']+)(['\"]*)" ,
@@ -947,7 +974,20 @@ def log_masking(self, msg):
947974
948975 if "IDENTIFIED BY" in msg :
949976 return desensitize_sql_pwd (msg )
950-
977+
978+ if "host init" in msg :
979+ host_reg = r'(obd host init\s+.*?)(-p\s+)([^\s\'\"\`]+)'
980+ host_pattern = re .compile (host_reg )
981+ if host_pattern .search (msg ):
982+ return host_pattern .sub (r'\1\2******' , msg )
983+
984+ if "chpasswd" in msg :
985+ chpasswd_reg = r'(echo\s*"[^:]+:)([^"]+)(".*chpasswd)'
986+ chpasswd_pattern = re .compile (chpasswd_reg )
987+ if chpasswd_pattern .search (msg ):
988+ return chpasswd_pattern .sub (r'\1******\3' , msg )
989+
990+
951991 pwd_args_regex = r"(_password \S+.*args:\s*\[['\"]?)([^\s'\"']+)(['\"]*)"
952992 arg_pattern = re .compile (pwd_args_regex )
953993 if arg_pattern .search (msg ):
@@ -967,6 +1007,16 @@ def log_masking(self, msg):
9671007 pwd_pattern = re .compile (echo_pwd_regex )
9681008 if pwd_pattern .search (msg ):
9691009 return pwd_pattern .sub (r"\1******\3" , msg )
1010+
1011+ opts_regex = r'(\'password\':\s*\')([^\']+)(\')'
1012+ opts_pattern = re .compile (opts_regex )
1013+ if opts_pattern .search (msg ):
1014+ return opts_pattern .sub (r"\1******\3" , msg )
1015+
1016+ if ip_masking :
1017+ ipv4_pattern = r'\b(?:\d{1,3}\.){2}\d{1,3}\.\d{1,3}\b'
1018+ msg = re .sub (ipv4_pattern , "***.***.***.***" , msg )
1019+
9701020 return msg
9711021
9721022 def verbose (self , msg , * args , ** kwargs ):
0 commit comments