3030callback_error = None
3131
3232
33+ def _sanitize_input (user_input : str ) -> str :
34+ """Sanitize user input by removing trailing/leading whitespace and Windows line endings.
35+ Args:
36+ user_input: Raw input string from user
37+ Returns:
38+ Sanitized string with whitespace and line endings removed
39+ """
40+ if not user_input :
41+ return user_input
42+ # Remove leading/trailing whitespace and various line endings
43+ # Handle Windows (\r\n), Unix (\n), and Mac (\r) line endings
44+ sanitized = user_input .strip ().rstrip ("\r \n " ).strip ()
45+ return sanitized
46+
47+
3348class CallbackHandler (http .server .BaseHTTPRequestHandler ):
3449 """HTTP request handler for OAuth callback."""
3550
@@ -361,7 +376,7 @@ def run_oauth_flow(args: OAuthSetupArgs) -> bool:
361376
362377
363378def _prompt_for_input (prompt : str , env_var : str = None , is_secret : bool = False ) -> str :
364- """Prompt the user for input."""
379+ """Prompt the user for input with sanitization for Windows line endings and whitespace ."""
365380 value = os .getenv (env_var , "" ) if env_var else ""
366381 if value :
367382 if is_secret :
@@ -373,11 +388,11 @@ def _prompt_for_input(prompt: str, env_var: str = None, is_secret: bool = False)
373388 print (f"{ prompt } [{ masked } ]: " , end = "" )
374389 else :
375390 print (f"{ prompt } [{ value } ]: " , end = "" )
376- user_input = input ()
391+ user_input = _sanitize_input ( input () )
377392 return user_input if user_input else value
378393 else :
379394 print (f"{ prompt } : " , end = "" )
380- return input ()
395+ return _sanitize_input ( input () )
381396
382397
383398def run_oauth_setup () -> int :
0 commit comments