Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/rafter_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
help="Rafter CLI — the default security agent for AI workflows. Free for individuals and open source. No account required.",
add_completion=True,
no_args_is_help=True,
# Never render frame locals in tracebacks: they hold the API key.
pretty_exceptions_show_locals=False,
)


Expand Down
45 changes: 45 additions & 0 deletions python/tests/test_traceback_no_locals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""An unhandled exception must not print the API key.

Typer's pretty tracebacks render every frame's local variables by default,
and the request helpers hold the key in ``api_key`` / ``headers`` locals.
A plain transport failure (here: an unreachable proxy) is enough to raise
out of a command, so the key would land on stderr, which in CI is the
build log.
"""
from __future__ import annotations

import os
import subprocess
import sys

SENTINEL = "RAFTER_TEST_SENTINEL_KEY_9f3c1a"


def test_unhandled_exception_does_not_print_api_key(tmp_path):
env = os.environ.copy()
env.pop("_TYPER_STANDARD_TRACEBACK", None)
env.update(
{
"HOME": str(tmp_path),
"RAFTER_API_KEY": SENTINEL,
"HTTPS_PROXY": "http://127.0.0.1:1",
"https_proxy": "http://127.0.0.1:1",
"NO_PROXY": "",
"no_proxy": "",
}
)
result = subprocess.run(
[sys.executable, "-m", "rafter_cli", "usage"],
capture_output=True,
text=True,
cwd=tmp_path,
env=env,
timeout=60,
)

assert result.returncode != 0
# Positive control: the command did fail with a traceback, so the
# assertion below is about its content rather than its absence.
assert "Traceback" in result.stderr or "Error" in result.stderr
assert SENTINEL not in result.stderr
assert SENTINEL not in result.stdout
Loading