Skip to content

fix(mcp): redact route tokens and tenant keys from HTTP request logs#73

Merged
electather merged 1 commit intomainfrom
fix/mcp-log-redaction
Mar 16, 2026
Merged

fix(mcp): redact route tokens and tenant keys from HTTP request logs#73
electather merged 1 commit intomainfrom
fix/mcp-log-redaction

Conversation

@electather
Copy link
Owner

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

  • Add SafeLogPath(path, routeToken string, multiTenant bool) string — a pure, exported helper that applies redaction rules:
    • Route-token mode: /<token>/mcp/{redacted}/mcp
    • Multi-tenant mode: /<api-key>/mcp/{tenant}/mcp
    • Plain /mcp paths returned unchanged
  • Update httpLoggingMiddleware to accept routeToken and multiTenant parameters and route the logged path through SafeLogPath
  • Update the call site in runServe to pass both values

Test plan

  • go test -v ./... passes
  • go fmt ./... produces no diff
  • go build succeeds

Table-driven tests in tests/mcp_logger_test.go cover 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

  • New tests added for new behaviour
  • Documentation updated (README, command --help, comments)
  • No unrelated changes included

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
@electather electather merged commit 94bc484 into main Mar 16, 2026
2 checks passed
@electather electather deleted the fix/mcp-log-redaction branch March 16, 2026 11:58
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.

security: Redact route tokens and tenant API keys from MCP HTTP request logs

1 participant