Description
Surviving finding from the CodeRabbit review of #1058 (review 5789566267). Two of that review's three findings were already fixed at the reviewed head (550ceb8) and are not filed here — see "Already fixed" below.
Problem
A SECRET that contains # is accepted from the environment, then written to .env unquoted, where Node's loader truncates it at the #. The secret the relay derives from changes between setup --start and the next start.
src/cli/commands/setup.ts at f335613:
resolveSecret(line ~91) returns an inheritedprocess.env.SECRETthroughstripQuoteswith no#check. The#validator at line ~119 guards only the interactive prompt.upsertSecret(line ~140) writesSECRET=${secret}with no quoting or escaping.deriveFromSecret(src/utils/secret.ts) HMACs the rawprocess.env.SECRET, so a different value means different derived signatures.
Measured
Node 24.22.1, the loader the CLI itself uses (node --env-file-if-exists=.env):
$ printf 'SECRET=my-secret#suffix\n' > t.env
$ node --env-file=t.env -e 'console.log(JSON.stringify(process.env.SECRET))'
"my-secret"
$ printf 'SECRET="my-secret#suffix"\n' > t2.env
$ node --env-file=t2.env -e 'console.log(JSON.stringify(process.env.SECRET))'
"my-secret#suffix"
runCommand spreads process.env into the child (src/cli/utils/process.ts:21-23), so setup --start uses the full value while every later start uses the truncated one.
Fix
Make accepted secrets round-trip. Either is sound:
- Reject values that cannot be written safely — apply the prompt validator's checks (
#, newlines, unterminated quotes) to the inherited value inresolveSecret, and to whateverupsertSecretis handed. - Serialize instead of rejecting — quote or escape on write so
parseEnvValueand Node's loader both recover the exact value.
Option 2 plus a round-trip assertion in the setup tests is the safer read, since a hex secret is only the recommended shape, not an enforced one.
Acceptance
- An inherited
SECRETcontaining#, a newline, or an unbalanced quote either fails setup with a clear message or is written in a form bothparseEnvValueandnode --env-fileread back unchanged. - A test asserts that the value written by
upsertSecretreads back identically throughreadEnvSecretand through Node's loader.
Already fixed (do not re-file)
- Quotes defeat the placeholder check (
setup.ts:39-40) —readEnvSecretalready returnsparseEnvValue(raw)andneedsSecretReplacementalready callsstripQuotesat the reviewed head.SECRET="change_me_to_something_long_and_random"is recognised as the placeholder. - An inherited placeholder survives when
.envholds a valid secret (setup.ts:136-137) — the early return at lines 182-188 already assignsprocess.env.SECRET = envFileSecretwhen the inherited value needs replacement. That was the point of fix(cli): reject placeholder secret inherited from env or prompt in setup (#1018) #1058.
Activity