Skip to content

fix: redact secret query values from the uvicorn access log - #232

Merged
ArthurBernard merged 2 commits into
developfrom
fix/access-log-token-redaction
Aug 2, 2026
Merged

fix: redact secret query values from the uvicorn access log#232
ArthurBernard merged 2 commits into
developfrom
fix/access-log-token-redaction

Conversation

@ArthurBernard

Copy link
Copy Markdown
Owner

Summary

  • Uvicorn's access log wrote request URLs verbatim, so the documented ?token= script auth leaked the live dashboard token into journald (observed on the 2026-08-02 systemd deploy; token rotated immediately).
  • A mutating logging.Filter (AccessLogRedactionFilter) now scrubs uvicorn.access + uvicorn.error records at all three serving commands (serve, start --serve, dashboard), reusing the transport scrubber via a public redact_url alias — same key set (token/signature/api_key/nonce), same <redacted> marker.

Why

  • Repo invariant: secrets never logged — redact keys in any log line. Logger-level placement is load-bearing (uvicorn's startup dictConfig replaces handlers but keeps logger filters; locked by a test). Rejected: forking uvicorn's log-config dict per site; duplicating the key set at the interface layer. Full ADR in doc/dev/03-decisions.md.

Changes

  • transport/http.py — public redact_url alias (no behaviour change) + a stale comment fixed (the marker percent-encodes to %3Credacted%3E on the wire).
  • application/log_setup.pyAccessLogRedactionFilter + idempotent install_access_log_redaction() (uvicorn.access + uvicorn.error).
  • interfaces/cli/main.py — install called before all three uvicorn launches.
  • Tests: 6 filter tests (incl. dictConfig-survival, idempotence, all five keys) + 3 CLI-site tests; fixtures restore the process-global uvicorn loggers.
  • Docs ceremony: CHANGELOG, ADR, status (systemd ops note), roadmap line removed (single-leaf plan tree archived).

Changelog

Fixed under [Unreleased]:

  • The access log never prints secrets — redaction filter on the uvicorn access/error loggers at all three serving commands.

Test plan

  • python -m pytest — 1522 passed, 96.34% coverage
  • ruff check trading_bot/ + ruff format --check . pass
  • mypy trading_bot/ — no issues in 60 files
  • Real-data: dashboard on :8010, probe ?token=LEAKCANARY123 → access-log line shows token=%3Credacted%3E, canary absent from the whole log; clean/benign queries byte-identical; clean SIGTERM exit
  • CI green

The documented `?token=` script auth was written verbatim by uvicorn's
access logger (observed in journald on the 2026-08-02 systemd deploy; token
rotated). A mutating logger-level filter — reusing the transport URL
scrubber via the new public `redact_url` alias — is installed at all three
uvicorn launch sites and survives uvicorn's own dictConfig.
@ArthurBernard
ArthurBernard force-pushed the fix/access-log-token-redaction branch from fb1b6a9 to fe00b66 Compare August 2, 2026 15:51
@ArthurBernard
ArthurBernard merged commit 476fb55 into develop Aug 2, 2026
@ArthurBernard
ArthurBernard deleted the fix/access-log-token-redaction branch August 2, 2026 15:51
This was referenced Aug 2, 2026
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