nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] `validateProjectConfigSecurity` never runs, hardcoded-credential scanner is dead code

Open addyCooks opened this issue 2 months ago • 1 comments

Description

validateMCPConfigSecurity is the app's only defense-in-depth signal for "you committed a hardcoded credential into a project-level MCP config." It is only invoked, via validateProjectConfigSecurity, on servers whose .source === 'project'. But the object type that field lives on (MCPServerWithSource) is stripped down to the plain MCPServerConfig (which never had that field) before it reaches this call, so the filter is always empty and the check never fires in the shipped app.

Root cause is an integration break between two refactors: mcp-config-loader.ts tracks provenance on a wrapper type for its own merge logic, but the consumer (config/index.ts) unwraps to the inner type before handing it to the validator, silently discarding the field the validator's filter depends on.

The unit test for this validator (validation.spec.ts) passes only because it hand-constructs an object with .source set directly on the inner type a shape that never occurs in the real data flow which is exactly why this break went unnoticed.

Location

  • source/config/mcp-config-loader.ts:47-63 (mapServerConfig never copies .source onto the returned MCPServerConfig)
  • source/config/index.ts:704-705 (loadAllMCPConfigs().map(item => item.server) strips the wrapper's .source field)
  • source/hooks/useAppInitialization.tsx:210 (validateProjectConfigSecurity(config.mcpServers) called on the already-stripped array)
  • source/config/validation.ts:58-60 (filters server.source === 'project', always undefined on real objects)

Environment

  • OS: Any
  • Node version: v22.22.3
  • Nanocoder version: 1.30.0
  • Provider: N/A
  • Model: N/A

Steps to Reproduce

  1. Add an MCP server entry to a project's agents.config.json with a hardcoded-looking secret, e.g. "env": {"API_KEY": "sk-abc123..."}.
  2. Start nanocoder in that project.
  3. Observe that no warning is logged, even though validateMCPConfigSecurity is designed to detect exactly this pattern.

Alternatively, add a console.log (or breakpoint) inside validateMCPConfigSecurity and confirm it is never reached for a real project config, because the array passed to validateProjectConfigSecurity contains objects with source: undefined.

Expected Behavior

A project-level MCP server config containing an apparent hardcoded credential should trigger validateMCPConfigSecurity's warning.

Actual Behavior

The warning never fires for any real config, project-level or otherwise, because the .source field its filter depends on is stripped before the validator ever sees the data.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently (established via code read mapServerConfig and the .map(item => item.server) unwrap are directly verifiable as never setting/preserving .source)
  • [x] This issue occurs with the latest version of nanocoder

Suggested fix: preserve .source through the unwrap in config/index.ts (don't discard the wrapper before validation), or have validateProjectConfigSecurity accept the MCPServerWithSource[] array directly instead of the stripped MCPServerConfig[].

addyCooks avatar Sep 09 '26 15:09 addyCooks

Hey @akramcodez, almost done with the fix.. could you assign this to me ?

addyCooks avatar Sep 10 '26 06:09 addyCooks