Skip to content

Redact secret URL parameters in every log record - #396

Merged
CodexVeritas merged 2 commits into
mainfrom
claude/redact-secret-url-params-in-logs
Nov 7, 2026
Merged

CodexVeritas merged 2 commits into
mainfrom
claude/redact-secret-url-params-in-logs

Conversation

@CodexVeritas

@CodexVeritas CodexVeritas commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

HttpApiKeyFilter only looked at records from the httpx logger, and it dropped them. Any other logger that prints a request URL still wrote API keys to the console and to CustomLogger's log files.

How this was found: a SerpApi key reached the log files through a Google Trends seed source in metaculus_ai_sdk, which logs the httpx error message (that message includes the full request URL). The SDK side is fixed in Metaculus/metac-ai-sdk#212.

What changes:

  • The filter now rewrites every record. It replaces the values of query parameters named *key, *token, *secret, *signature or password with REDACTED, in:
    • the formatted message (format arguments included);
    • exception text;
    • stack info.
  • httpx request lines are kept, with the key redacted, instead of being dropped.
  • The filter never raises. A log call with mismatched format arguments is left for emit() to report, as before. (A filter runs outside Handler.handleError, so raising there would crash the caller.)
  • Exception text is only overwritten when it actually contained a secret, so handlers with a custom formatException keep their own formatting.

Not covered (out of scope): secrets outside URL query strings, such as Authorization headers or api_key='…' in kwargs reprs.

Tests: 8 new unit tests in code_tests/unit_tests/test_util/test_custom_logger.py:

  • the SerpApi-style warning from a non-httpx logger;
  • a key passed as a format argument;
  • a key inside a logged exception's text;
  • httpx request lines;
  • ordinary URLs left unchanged;
  • token, secret and signature parameters;
  • malformed format arguments;
  • tracebacks without secrets.

Full unit suite: the same 14 failures on unmodified origin/main and on this branch, in test_run_bots and test_forecast_report. They're unrelated and pass when those files run alone.

🤖 Generated with Claude Code

CodexVeritas and others added 2 commits November 7, 2026 14:39
HttpApiKeyFilter only looked at records from the httpx logger and dropped
them. Any other logger that prints a request URL (e.g. an HTTP error
message) still wrote API keys to the console and log files: a SerpApi key
reached the log files this way through a Google Trends seed source.

The filter now rewrites every record, replacing the values of key, token,
secret, signature and password query parameters with REDACTED, in the
message, its arguments, exception text and stack info. httpx request lines
are kept, redacted, instead of dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CodexVeritas
CodexVeritas merged commit 5a66f7c into main Nov 7, 2026
2 checks passed
@CodexVeritas
CodexVeritas deleted the claude/redact-secret-url-params-in-logs branch November 7, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant