Skip to content

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

fix(security): hide setup credentials

Pnantdba11dff0c18
diff --git a/agent_reach/cli.py b/agent_reach/cli.py
index d7d082e9..fb691124 100644
--- a/agent_reach/cli.py
+++ b/agent_reach/cli.py
@@ -1979,6 +1979,8 @@ def _cmd_doctor(args=None):
def _cmd_setup():
+ import getpass
+
from agent_reach.config import Config
config = Config()
@@ -2051,7 +2053,7 @@ def _cmd_setup():
if current:
print(" 当前状态: ✅ 已配置")
else:
- key = input(" GITHUB_TOKEN (回车跳过): ").strip()
+ key = getpass.getpass(" GITHUB_TOKEN (回车跳过): ").strip()
if key:
config.set("github_token", key)
print(" ✅ GitHub API 已提升至 5000 次/小时!")
@@ -2072,7 +2074,7 @@ def _cmd_setup():
if current:
print(" 当前状态: ✅ 已配置")
else:
- key = input(" GROQ_API_KEY (回车跳过): ").strip()
+ key = getpass.getpass(" GROQ_API_KEY (回车跳过): ").strip()
if key:
config.set("groq_api_key", key)
print(" ✅ 语音转文字已开启!")
diff --git a/tests/test_p0_cli.py b/tests/test_p0_cli.py
index d55770cc..783ebd91 100644
--- a/tests/test_p0_cli.py
+++ b/tests/test_p0_cli.py
@@ -82,6 +82,42 @@ def test_configure_uses_hidden_prompt_when_no_value_is_given(
assert secret not in output.err
+def test_setup_uses_hidden_prompts_for_secrets(monkeypatch, capsys):
+ import getpass
+ import shutil
+
+ import agent_reach.config as config_module
+
+ github_secret = "ghp-secret-from-setup"
+ groq_secret = "gsk-secret-from-setup"
+ secrets = iter([github_secret, groq_secret])
+ prompts = []
+ config = _MemoryConfig()
+ config.config_path = Path("/tmp/agent-reach-test-config.yaml")
+
+ monkeypatch.setattr(config_module, "Config", lambda: config)
+ monkeypatch.setattr(shutil, "which", lambda _name: None)
+ monkeypatch.setattr(
+ getpass,
+ "getpass",
+ lambda prompt: prompts.append(prompt) or next(secrets),
+ )
+
+ cli._cmd_setup()
+
+ assert config.data["github_token"] == github_secret
+ assert config.data["groq_api_key"] == groq_secret
+ assert prompts == [
+ " GITHUB_TOKEN (回车跳过): ",
+ " GROQ_API_KEY (回车跳过): ",
+ ]
+ output = capsys.readouterr()
+ assert github_secret not in output.out
+ assert github_secret not in output.err
+ assert groq_secret not in output.out
+ assert groq_secret not in output.err
+
+
def test_configure_positional_secret_warns_to_use_safe_input(
monkeypatch, capsys
):