~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

Logs mask percent-encoded secrets, and read off the async workers

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:logs/review-fixes

The review of the telemetry pull (at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/hud/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n2myf3tv2put) found two things worth fixing. A secret's value could reach the kept logs when its name was percent-encoded, and an operator's read did SQLite work on an async worker, out of order with the flusher.

Claude Opus 5.5 · low

What changes

Secrets masked whatever their spelling. telemetry::query reads each parameter's name as a query is read (url::form_urlencoded) before matching it against SECRETS, so %63ode=… and acc%65ss_token=… log as =_. The name stays as it was written.

The operator's read off the async workers. Hud::read_logs is async: its flush and query run in spawn_blocking. Logs::flush takes the database lock before it takes the pending lines, so two flushes, the read's and the flusher's, write their batches in the order they were logged. write is a free function given the connection that is held.

Why

Everything outside /oauth is logged, and with HUD_LOGS=on kept for 30 days, so a percent-encoded code or token was a secret kept on disk. The flush took its batch, then waited for the database: a flush that took an earlier batch could write after one that took a later batch, so the ids came out of order. The review's third note was dropped, not fixed: lines logged while a streamed body is polled may miss the trace. The event stream logs little of its own, and a missing trace costs only grouping.

How it was checked

queries_leave_secrets_out covers encoded names, including + and an empty pair. just check passed, with lines and functions at 100%. One just check and one just cov before it exited 101 without the failing test being captured. Four more just cov runs and six cargo test --workspace runs all passed, so a timing-sensitive test is flaky under instrumentation; it didn't reproduce.

Shortcomings

No test pins the flush order: the race needs two flushes interleaved by the scheduler. The flake above is unexplained.

Approved

This pull makes telemetry::query read each parameter's name as a query is read before matching it against SECRETS. It moves the operator's log read onto spawn_blocking. It also makes flush take the database lock before the pending lines.

I found nothing that must change.

  • Masking: %63ode and acc%65ss_token now match, and the name is kept as written. An empty pair gives None and stays unmasked, which is correct. refresh+token decodes to refresh token, so it isn't masked, and the test says so.
  • Flush order: the lock order is safe. keep takes only the pending-lines lock and never the database lock, so flush holding the database lock while it takes the pending lines can't deadlock. Taking the database lock first does serialize batches in the order they were logged.
  • read_logs: the .await is added at both callers, xrpc.rs and the tool. The expect on the join only fires if the blocking task panicked, and the message says so.

As the body says, no test pins the flush order. That is a fair gap for a scheduler race.

Merged as 067cb6d