Skip to content

Commit 5090e91

Browse files
committed
Merge PR sooperset#728: fix(oauth_setup): sanitize user input for interactive prompts
2 parents 92755a5 + 7f41b33 commit 5090e91

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/mcp_atlassian/utils/oauth_setup.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
callback_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+
3348
class 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

363378
def _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

383398
def run_oauth_setup() -> int:

0 commit comments

Comments
 (0)