feat(auth): harden credential storage and secure tui bearer input#28
feat(auth): harden credential storage and secure tui bearer input#28alDuncanson wants to merge 4 commits intomainfrom
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019ccc01-a426-74d2-9bf8-6d6b70e5b05c Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ccc01-a426-74d2-9bf8-6d6b70e5b05c Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019cce7d-9761-750d-b95d-010833bbb254 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce200-c605-73d7-b262-257c9e3ba99f Co-authored-by: Amp <amp@ampcode.com>
| def _print(self, text: str) -> None: | ||
| """Print text to stdout.""" | ||
| print(text) | ||
| sys.stdout.write(f"{text}\n") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 23 days ago
General fix: Ensure that any user‑controlled string that can contain secrets is redacted before being written to stdout, both for plain text and for structured (JSON/NDJSON) output. The safest place is at the boundary: _print should not emit raw text that may contain secrets; instead, it should run text through _redact_text. For structured output, we already call _redact_data before serializing, so that path is safe.
Best targeted fix without changing functionality:
- Change
_printso it does not accept already‑serialized JSON/NDJSON; instead, do redaction before serialization and then call_printwith the final string. However, we already have that behavior in_emit_structured, so we only need to ensure_printis not responsible for redacting structured data. - For text output,
_emit_textalready calls_redact_text, so no change is required there. - For structured output, instead of calling
_print(json_module.dumps(...)), we can keep that as is, because_redact_datahas already processed the payload. The issue flagged is at_printwhere CodeQL sees a tainted string; we can make_printassume it may receive either already‑safe structured data or raw text and still run_redact_textover it._redact_textis written to detect and redact secrets in arbitrary strings, so passing serialized JSON through it provides an additional safety net and resolves the static analysis complaint.
Concretely, in src/a2a_handler/common/output.py:
- Modify
_printto call_redact_text(text)before writing to stdout. - Leave callers (
_emit_text,_emit_structured, etc.) unchanged; they still perform their existing redaction, but_printbecomes a final guard, ensuring that even if a future caller passes tainted data, it gets redacted.
No changes are required in src/a2a_handler/cli/auth.py because it does not log actual secret values, only identifiers, and once the output layer is hardened, any future sensitive values would still be protected.
| @@ -144,7 +144,8 @@ | ||
|
|
||
| def _print(self, text: str) -> None: | ||
| """Print text to stdout.""" | ||
| sys.stdout.write(f"{text}\n") | ||
| safe_text = _redact_text(text) | ||
| sys.stdout.write(f"{safe_text}\n") | ||
|
|
||
| def _emit_text(self, text: str, force: bool = False) -> None: | ||
| """Print plain text output with quiet-mode handling.""" |
This pull request introduces major improvements to authentication handling and credential storage security in the CLI and session management modules. The CLI now supports multiple ways to provide bearer tokens, and session credentials are securely stored using the OS keyring when available, with fallback to plaintext if not. Additionally, file and directory permissions for session storage are hardened. Comprehensive tests have been added to ensure these features work correctly.
Authentication enhancements in CLI:
--bearer-commandand--bearer-stdinoptions to thetuicommand, allowing bearer tokens to be supplied via a shell command or stdin, and enforced mutual exclusivity among bearer token sources.Credential storage security:
Session storage permissions:
Dependency updates:
keyringtopyproject.tomldependencies to enable secure credential storage.