Skip to content

Commit 970afbe

Browse files
committed
fix(cli): connect confirms a hidden key by its length alone
- On Python 3.12 and 3.13 (no masked getpass) the confirmation printed the key's last four characters, a fragment of a secret left in the terminal's scrollback. Security review note: no widening; a secret's fragment leaves the one output it reached, the length still tells a truncated paste apart.
1 parent 66fe564 commit 970afbe

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎src/agent6/ui/cli/connect.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def _prompt_api_key(name: str) -> str:
8787
except EOFError:
8888
return ""
8989
if api_key and not masked:
90-
tail = f", ending …{api_key[-4:]}" if len(api_key) >= 8 else ""
91-
print(f"Captured key: {len(api_key)} chars{tail}.")
90+
print(f"Captured key: {len(api_key)} chars.")
9291
return api_key
9392

9493

‎tests/unit/test_cli_connect_model.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def _fake_getpass(prompt: str = "", **kwargs: object) -> str:
178178
rc = main(["connect", "anthropic"])
179179
assert rc == 0
180180
out = capsys.readouterr().out
181-
assert "Captured key: 21 chars, ending …wxyz" in out
181+
assert "Captured key: 21 chars." in out
182+
assert "wxyz" not in out # no fragment of the key reaches the terminal
182183
# The key itself is never echoed in full.
183184
assert "sk-ant-0123456789wxyz" not in out
184185

0 commit comments

Comments
 (0)