Repository navigation
fix(mcp): mask credentials before writing dispatch arguments to the log - #396
Merged
Merged
Conversation
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
force-pushed
the
fix/mask-dispatcher-log-arguments
branch
from
September 22, 2026 18:44
33e88fc to
2baf940
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodeQL reported three high-severity
py/clear-text-logging-sensitive-dataalerts in the MCP dispatcher. They are what blocked #335, and the finding is real.This dispatcher runs arbitrary
devopscommand 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 llmand 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_dispatchwent 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.