nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] config show prints secrets that are inside URLs, args, env values and headers

Open addyCooks opened this issue 2 weeks ago • 1 comments

Description

nanocoder config show hides provider apiKey values but prints other secrets in clear text: credentials in URLs and query strings, --api-key style arguments, env values such as DATABASE_URL, and headers with non-obvious names. This can leak secrets into terminals, screenshots and CI logs.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at f92cce9c)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. In an empty folder create .mcp.json:

     {"mcpServers":{"gh":{"command":"npx","args":["-y","some-mcp","--api-key","$MY_SECRET"],"env":{"DATABASE_URL":"postgres://u:$MY_SECRET@h/db"}},"remote":{"transport":"http","url":"https://mcp.example.com/mcp?api_key=${MY_SECRET}","headers":{"Ocp-Apim-Subscription-Key":"$MY_SECRET"}}}}
    
  2. Run MY_SECRET=SUPERSECRET123 NANOCODER_CONFIG_DIR=<empty dir> node dist/cli.js config show mcpServers --json

  3. Optionally set a provider baseUrl to https://x.example.com/v1?key=$MY_SECRET and run config show providers.

Expected Behavior

No real secret value appears in the output.

Actual Behavior

SUPERSECRET123 appears in args, env, url and header values, and redacted is false for both entries.

Logs/Screenshots

"args": ["-y", "some-mcp", "--api-key", "SUPERSECRET123"]
"env": {"DATABASE_URL": "postgres://u:SUPERSECRET123@h/db"}
"url": "https://mcp.example.com/mcp?api_key=SUPERSECRET123"
"headers": {"Ocp-Apim-Subscription-Key": "SUPERSECRET123"}
"redacted": false

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/config/effective-config.ts:129 (SECRET_KEY_PATTERN) and :169 (redactValue): also redact the user:password part and sensitive query parameters of URLs, the value after an argument like --api-key or --token, every env and header value written as a $VAR reference, and header names containing "key", "token", "secret" or "subscription".
  • Check the call sites at :676 and :834, and source/config/config-cli.ts:53 (formatValue).
  • Add a test for each case above.

Related: #1661 (same problem in /doctor).

addyCooks avatar Nov 14 '26 06:11 addyCooks

I will pick this up. I will extend effective-config redaction to URL credentials and sensitive query parameters, secret CLI flag values, and MCP env/header secrets, including resolved environment references. I will test both structured and rendered output using synthetic secrets.

Purv-Kabaria avatar Nov 14 '26 10:11 Purv-Kabaria