@@ -313,6 +313,13 @@ def __init__(self, options: Optional[Dict[str, Any]] = None) -> None:
313313 if self .totp is not None :
314314 if not isinstance (self .totp , str ):
315315 raise TypeError ('The value of connection option "totp" should be a string' )
316+ # Validate TOTP format: must be 6 numeric digits, with explicit non-numeric error
317+ if not self .totp .isdigit ():
318+ self ._logger .error ('Invalid TOTP: contains non-numeric characters' )
319+ raise errors .ConnectionError ('Invalid TOTP: contains non-numeric characters' )
320+ if len (self .totp ) != 6 :
321+ self ._logger .error ('Invalid TOTP format in connection options. Must be a 6-digit number.' )
322+ raise errors .ConnectionError ('Invalid TOTP format: Must be a 6-digit number.' )
316323 self ._logger .info ('TOTP received in connection options' )
317324
318325 # OAuth authentication setup
@@ -1005,8 +1012,11 @@ def send_startup(totp_value=None):
10051012 self ._logger .error ("Invalid TOTP: Cannot be empty." )
10061013 raise errors .ConnectionError ("Invalid TOTP: Cannot be empty." )
10071014
1008- # ❌ Validate TOTP format (must be 6 digits)
1009- if not totp_input .isdigit () or len (totp_input ) != 6 :
1015+ # ❌ Validate TOTP format: explicit non-numeric error, then length check
1016+ if not totp_input .isdigit ():
1017+ self ._logger .error ("Invalid TOTP: contains non-numeric characters" )
1018+ raise errors .ConnectionError ("Invalid TOTP: contains non-numeric characters" )
1019+ if len (totp_input ) != 6 :
10101020 print ("Invalid TOTP format. Please enter a 6-digit code." )
10111021 self ._logger .error ("Invalid TOTP format entered." )
10121022 raise errors .ConnectionError ("Invalid TOTP format: Must be a 6-digit number." )
0 commit comments