nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Config values cannot contain a literal $NAME: it is silently replaced with an empty string

Open akramcodez opened this issue 3 weeks ago • 2 comments

Description

Every string in the config goes through $VAR / ${VAR} expansion, and there is no way to write a literal $NAME. A value that happens to contain $ followed by capital letters is silently changed, and a secret can end up shortened or empty.

Environment

  • OS: macOS 27.2
  • Node version: v22.23.4
  • Nanocoder version: 1.32.0 (main at daa0ad9b)
  • Provider: any provider with an apiKey, or an MCP server with headers, env or args
  • Model: not model specific

Steps to Reproduce

  1. Put a value containing $ and capitals into agents.config.json, for example "apiKey": "sk-$ECRET-key" or an MCP args entry such as "price $USD".
  2. Start nanocoder (or run nanocoder config show).

I ran substituteEnvVars from source/config/env-substitution.ts on some inputs:

"pa$WORD"       => "pa"
"sk-$ECRET-key" => "sk--key"
"price $USD 5"  => "price  5"
"$$HOME_DIR"    => "$/home/me"      (no $$ escape)
"\\$HOME_DIR"   => "\\/home/me"     (no backslash escape)

Expected Behavior

Some way to keep the text as is, such as $$ for a literal dollar sign, which is the convention in docker-compose and many other tools that use this syntax.

Actual Behavior

The text is replaced with an empty string and the only trace is a line from logError ("Environment variable WORD not found in config, using empty string"), which is easy to miss. The request then goes out with a wrong key and the user sees an auth error that points at the provider rather than the config.

Logs/Screenshots

LOG: Environment variable ECRET not found in config, using empty string
"sk-$ECRET-key" => "sk--key"

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

Suggested change: treat $$ as an escape that yields one $ and is never expanded, and mention it in the config docs next to the ${VAR:-default} syntax. Optionally the "not found" message could say which config key it came from. Separately, substituteEnvVars copies keys with result[key] = ..., so a JSON file with an own "__proto__" key sets the prototype of the result instead of creating a key; using Object.defineProperty or skipping that key would avoid it.

akramcodez avatar Nov 06 '26 09:11 akramcodez

Hi @ravithemore, thanks for your work on this! Could you please leave a quick comment on this issue so I can assign it to you? Going forward, please comment on an issue first and wait to be assigned before you start working on it. That way we avoid duplicate work and keep things fair for everyone.

Thanks for contributing!

addyCooks avatar Nov 07 '26 08:11 addyCooks

Hi @addyCooks, thanks for the guidance! Understood, and I'll make sure to comment and wait for assignment first on future contributions.

I would love to be assigned to this issue. I've already opened PR #1986 with the fix, documentation update, changeset, and comprehensive unit tests. Looking forward to your review!

ravithemore avatar Nov 07 '26 09:11 ravithemore