Sanitize environment variables in Docker args logging#908
Merged
Conversation
…logging Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Enhanced SanitizeArgs to use smart detection that: - Detects secrets by variable name (token, secret, key, password, etc.) - Detects secrets by value patterns (GitHub PATs, JWT, API keys, etc.) - Leaves non-sensitive config values unchanged (NO_COLOR=1, TERM=dumb, etc.) - Only truncates values that actually look like secrets This provides better debugging visibility while still protecting sensitive data. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Security-first approach: ALL environment variable values in Docker args are now truncated to prevent ANY secrets from being exposed in logs. Rationale: - Trying to selectively identify secrets is less secure - Detection logic can miss secrets or evolve over time - Better to sacrifice some debugging convenience than risk secret exposure - Truncation shows first 4 chars (e.g., ghs_...) for basic debugging This approach follows the principle of "secure by default" rather than "convenient but potentially insecure". Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Sanitize GITHUB_PERSONAL_ACCESS_TOKEN in MCP connection logs
Sanitize environment variables in Docker args logging
Feb 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents secret exposure in debug/error logs by sanitizing Docker -e VAR=VALUE arguments before they are logged during MCP backend server launch/connection workflows.
Changes:
- Apply
sanitize.SanitizeArgs()to Docker argument logging in MCP connection startup and launcher error diagnostics. - Clarify
SanitizeArgsdocumentation to reflect that it truncates all env var values (not just suspected secrets). - Update
SanitizeArgstest coverage to include non-sensitive configs containing=in values.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/mcp/connection.go | Sanitizes logged Docker args (expanded args + started message) to avoid plaintext env values in logs. |
| internal/launcher/log_helpers.go | Sanitizes logged args in launch error diagnostics to prevent leaking secrets during failures. |
| internal/logger/sanitize/sanitize.go | Documents the “truncate all env values” behavior for SanitizeArgs. |
| internal/logger/sanitize/sanitize_test.go | Updates test case to validate truncation when env values contain additional = characters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| log.Printf("Started MCP server: %s %v", command, args) | ||
| log.Printf("Started MCP server: %s %v", command, sanitize.SanitizeArgs(args)) |
There was a problem hiding this comment.
Started MCP server logs args, but the command actually executes expandedArgs (after expandDockerEnvArgs). For consistency with earlier logs (and to better reflect what was launched), consider logging sanitize.SanitizeArgs(expandedArgs) here instead.
Suggested change
| log.Printf("Started MCP server: %s %v", command, sanitize.SanitizeArgs(args)) | |
| log.Printf("Started MCP server: %s %v", command, sanitize.SanitizeArgs(expandedArgs)) |
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.
Environment variables containing secrets (
GITHUB_PERSONAL_ACCESS_TOKEN,API_KEY, etc.) were logged in plaintext when launching MCP backend servers, exposing credentials in debug logs and error diagnostics.Changes
Sanitization applied to all Docker
-eflag logging:internal/mcp/connection.go: Line 185 (expanded args debug log), line 282 (connection success log)internal/launcher/log_helpers.go: Line 75 (error diagnostics)Conservative approach: ALL environment variable values are truncated, not just suspected secrets. This eliminates false negatives at the cost of reduced debugging visibility for non-sensitive config values.
Before/After
All
-e VAR=VALUEpatterns now showVAR=first4chars...regardless of content (NO_COLOR=...,TERM=...,TOKEN=ghs_...).Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build1817774744/b275/launcher.test /tmp/go-build1817774744/b275/launcher.test -test.testlogfile=/tmp/go-build1817774744/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-errorsas DD8Ln2EKo 64/pkg/tool/linu-nilfunc user.name(dns block)/tmp/go-build1058771203/b275/launcher.test /tmp/go-build1058771203/b275/launcher.test -test.testlogfile=/tmp/go-build1058771203/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)Enhanced Saniti-ifaceassert` (dns block)
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.c--norc ndor/bin/bash by/b1c3827c31b54sh user.name .12/x64/bin/as /opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/compile` (dns block)
Enhanced Saniti-ifaceassert` (dns block)
Enhanced Saniti-ifaceassert` (dns block)
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.