Skip to content

fix(mcp): mask credentials before writing dispatch arguments to the log - #396

Merged
dan-petty merged 1 commit into
release/v0.2.22from
fix/mask-dispatcher-log-arguments
Sep 22, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.22from
fix/mask-dispatcher-log-arguments

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

CodeQL reported three high-severity py/clear-text-logging-sensitive-data alerts in the MCP dispatcher. They are what blocked #335, and the finding is real.

This dispatcher runs arbitrary devops command lines, and some carry a credential as an argument -- gh secrets set NAME <token>, a token passed as a flag. logger.debug("In-process dispatch %s finished in %.2fms", sub_args, dur_ms) wrote that argument list verbatim, so the credential landed in the log in clear text. The two handler-failure sites log exception text, which repeats an argument often enough to carry the same risk.

All four logging calls now route their values through mask_secrets, the convention the rest of the codebase already uses. The command stays readable -- configure-urls, --stack llm and the rest survive -- and only the credential is replaced.

The first version of this regressed dispatch latency, and the suite caught it: test_in_process_dispatcher_typer_dispatch went from under 500ms to 805ms. I put it down to a flaky timing assertion, then measured -- three of three runs passed without the change and one of three with it, so it was mine. Masking costs about 10 microseconds, but importing the sanitizer costs 2.9 seconds on a cold interpreter, and the lazy import sat inside the timed path. Each call is now behind a level check, so nothing is imported or masked when the record is not emitted, which is the normal case. Two tests pin both directions: no masking when the level is off, masking when it is on.

CodeQL reported three high-severity `py/clear-text-logging-sensitive-data` alerts in the MCP dispatcher, and they are what blocked #335.

The finding is real. This dispatcher runs arbitrary `devops` command lines, and some carry a credential as an argument -- `gh secrets set NAME <token>`, a token passed as a flag. `logger.debug("In-process dispatch %s finished in %.2fms", sub_args, dur_ms)` wrote that argument list verbatim, so the credential landed in the log in clear text. The handler-failure sites log exception text, which repeats an argument often enough to carry the same risk.

Masking the values first was the obvious fix and it was wrong twice over. It regressed dispatch latency, because the sanitizer costs 2.9 seconds to import on a cold interpreter and the lazy import sat inside the timed path -- the suite caught that, I put it down to a flaky timing assertion, then measured: three of three runs passed without the change and one of three with it. And it did not resolve the alerts. `mask_secrets` is not a barrier CodeQL recognises, so every masked argument became another flagged expression and three alerts became six.

Nothing derived from a dispatched command now reaches a log record. An exception's class and a duration carry the diagnostic weight -- which site failed, what kind of failure, how long it took -- without carrying anything that came from the caller. Three tests pin it: a token passed as an argument does not appear in the log, the dispatch record still reports its duration, and a handler failure still names its exception type.
@dan-petty
dan-petty force-pushed the fix/mask-dispatcher-log-arguments branch from 33e88fc to 2baf940 Compare September 22, 2026 18:44
@dan-petty
dan-petty merged commit f889de7 into release/v0.2.22 Sep 22, 2026
7 checks passed
@dan-petty
dan-petty deleted the fix/mask-dispatcher-log-arguments branch September 22, 2026 18:50
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.

2 participants