Skip to content

Commit f93b2ad

Browse files
fix(redact): tighten sensitive-token list to stop matching LLM token-count flags (#1006)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d797629 commit f93b2ad

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/aiperf/common/redact.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,20 @@ def redact_cli_command(cmd: str) -> str:
238238
return cmd
239239

240240

241-
_CLI_COMMAND_SENSITIVE_TOKENS = ("api-key", "api_key", "authorization", "token")
241+
# Each entry must contain a `-` or `_` so it can't substring-match an innocent
242+
# plural (e.g. bare `"token"` would match `--*-tokens-mean` flags carrying LLM
243+
# token counts). Bare `--token` is intentionally not matched; add a specific
244+
# compound form (e.g. `"my-token"`) if a new auth flag needs to be covered.
245+
_CLI_COMMAND_SENSITIVE_TOKENS = (
246+
"api-key", "api_key",
247+
"api-token", "api_token",
248+
"auth-token", "auth_token",
249+
"access-token", "access_token",
250+
"bearer-token", "bearer_token",
251+
"id-token", "id_token",
252+
"refresh-token", "refresh_token",
253+
"authorization",
254+
) # fmt: skip
242255

243256

244257
def _redact_cli_args(args: list) -> list:

tests/unit/common/test_redact.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,56 @@ def test_non_sensitive_args_preserved_in_cli_command(self):
14551455
assert "http://localhost:8000" in cmd
14561456
assert "gpt2" in cmd
14571457

1458+
@pytest.mark.parametrize(
1459+
"flag, value",
1460+
[
1461+
param("--input-tokens-mean", "1024", id="input-tokens-mean"),
1462+
param("--input-tokens-stddev", "0", id="input-tokens-stddev"),
1463+
param("--output-tokens-mean", "128", id="output-tokens-mean"),
1464+
param("--output-tokens-stddev", "32", id="output-tokens-stddev"),
1465+
param(
1466+
"--synthetic-input-tokens-mean", "1024", id="synthetic-input-tokens-mean",
1467+
),
1468+
param(
1469+
"--synthetic-input-tokens-stddev",
1470+
"0",
1471+
id="synthetic-input-tokens-stddev",
1472+
),
1473+
],
1474+
) # fmt: skip
1475+
def test_token_count_flags_preserve_value_in_cli_command(self, flag, value):
1476+
"""Regression: flag names containing 'tokens' (plural — LLM token
1477+
counts) must not be redacted just because they share a substring with
1478+
auth-token flags. Reported via real-run output where every
1479+
--*-tokens-* flag value came back as '<redacted>'."""
1480+
cmd = self._build_cli_command(
1481+
["aiperf", "profile", "--model", "gpt2", flag, value]
1482+
)
1483+
assert value in cmd, f"{flag} value {value!r} should not be redacted"
1484+
assert REDACTED_VALUE not in cmd
1485+
1486+
@pytest.mark.parametrize(
1487+
"flag",
1488+
[
1489+
param("--api-token", id="api-token"),
1490+
param("--api_token", id="api_token-underscore"),
1491+
param("--auth-token", id="auth-token"),
1492+
param("--access-token", id="access-token"),
1493+
param("--bearer-token", id="bearer-token"),
1494+
param("--id-token", id="id-token"),
1495+
param("--refresh-token", id="refresh-token"),
1496+
],
1497+
) # fmt: skip
1498+
def test_auth_token_compound_flags_redacted_in_cli_command(self, flag):
1499+
"""Auth-token flag variants must still be redacted after tightening
1500+
the sensitive-token list away from the bare-'token' substring match."""
1501+
secret = "nv-secret-AUTH-TOKEN-9876543210"
1502+
cmd = self._build_cli_command(
1503+
["aiperf", "profile", "--model", "gpt2", flag, secret]
1504+
)
1505+
assert secret not in cmd
1506+
assert REDACTED_VALUE in cmd
1507+
14581508

14591509
# =============================================================================
14601510
# ErrorDetails safe repr

0 commit comments

Comments
 (0)