fix(mcp): redact route tokens and tenant keys from HTTP request logs#73
Merged
electather merged 1 commit intomainfrom Mar 16, 2026
Merged
fix(mcp): redact route tokens and tenant keys from HTTP request logs#73electather merged 1 commit intomainfrom
electather merged 1 commit intomainfrom
Conversation
Add SafeLogPath helper that replaces the route-token prefix with
{redacted} and the multi-tenant API key segment with {tenant} before
the path is written to the log. httpLoggingMiddleware now accepts
routeToken and multiTenant so it can call SafeLogPath instead of
logging r.URL.Path directly.
Closes #63
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.
Summary
Prevents route tokens and per-user tenant API keys from appearing in MCP HTTP server request logs. Both values are secrets embedded in URL paths, so logging them raw would expose them to anyone with log access.
Closes #63
Changes
SafeLogPath(path, routeToken string, multiTenant bool) string— a pure, exported helper that applies redaction rules:/<token>/mcp→/{redacted}/mcp/<api-key>/mcp→/{tenant}/mcp/mcppaths returned unchangedhttpLoggingMiddlewareto acceptrouteTokenandmultiTenantparameters and route the logged path throughSafeLogPathrunServeto pass both valuesTest plan
go test -v ./...passesgo fmt ./...produces no diffgo buildsucceedsTable-driven tests in
tests/mcp_logger_test.gocover plain paths, route-token prefix, route-token SSE path, exact route-token match, unrelated paths, multi-tenant key, multi-tenant SSE path, root path, single-segment path, and the no-token/no-tenant case. Each route-token test also asserts the raw token string is absent from the output.Checklist
--help, comments)