Skip to content

fix(cli): note every project .env provider key before it is used - #8056

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-low26c-1117
Nov 17, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-low26c-1117

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

A provider key from a project .env now prints a one-line stderr note before it is first used. The note names the variable and the .env file. It covers the keys that #8004 and #8041 leave silent:

  • capture image descriptions: OPENROUTER_API_KEY, GEMINI_API_KEY, GOOGLE_API_KEY, and both Vertex parts, HYPERFRAMES_VERTEX_PROJECT_ID and HYPERFRAMES_VERTEX_SERVICE_ACCOUNT;
  • snapshot --describe: GEMINI_API_KEY or GOOGLE_API_KEY;
  • media-use Gemini speech (gemini-auth.mjs) and Lyria music (bgm.mjs): GEMINI_API_KEY or GOOGLE_API_KEY.

The existing "ignoring" notes, in the CLI and in media-use, now escape the path as well.

Why

After #8004 and #8041, a project .env key gives way when the person has a competing credential of their own. When they have none, the project key is still used. Only ElevenLabs says so today. A project's OpenRouter, Gemini, Google or Vertex credential is used silently. So captured images, snapshot frames, narration text or music prompts can go to the account behind someone else's key without the person knowing.

Related work (follows #8004)

Follows #8004 and #8041. #8004 added the received-project rule and the ElevenLabs note. #8041 extended the rule to the person's own project .env for capture vision and for media-use speech and music, and notes ElevenLabs for any project key. This PR gives the remaining provider keys the same note.

How

  • packages/cli/src/utils/dotEnv.ts adds noteProjectProviderKey(name, use). It runs only for a key that a project .env set and that survived yieldReceivedProviderKeys and yieldProjectVisionKeys. It prints once per key per process, and it escapes the path with terminalText. The origin comes from the existing untrustedEnvOrigin, read as "a received project", or "a project .env" when the file is not received. That matches the ElevenLabs note.
  • Capture (contentExtractor.ts) notes each part of the credential it picks. A new visionCredential() reads the same VISION_CREDENTIALS list that yieldProjectVisionKeys uses, so the noted keys match the ones capture uses. snapshot --describe notes the Gemini key it reads, GEMINI_API_KEY before GOOGLE_API_KEY.
  • skills/media-use/audio/scripts/lib/heygen.mjs: noteProjectElevenLabsKey now calls a shared noteProjectProviderKey, and its wording does not change. geminiAuth calls the shared note before Gemini speech. The Lyria branch of generateBgmDetached calls it with the key lyria-recipe.py reads first.
  • The skill escapes paths with skills/media-use/scripts/lib/terminal-text.mjs. It is a generated copy of the CLI's packages/cli/src/media-use/lib/terminal-text.mjs, kept in sync by generate-skill-module-copies.mjs and the media-use copy-parity check.
  • Keys from the shell or saved settings print nothing new.
  • Docs: the variable table in docs/guides/authentication.mdx and the capture section of docs/packages/cli.mdx mention the note.

No visible change

Nothing changes except a new stderr note when a provider key from a project .env is used.

Test plan

  • fails without the fix: each of these fails when the source change is reverted:

    • contentExtractor.test.ts: a received Gemini key captions with exactly one note, and a received Vertex credential captions with one note per part;
    • snapshot-contactSheet.test.ts: --describe with a project .env Gemini key prints one note;
    • dotEnv.test.ts: escaped paths, the once-per-process rule, a key from the person's own .env, silence for a shell key, and an escaped path in the "ignoring" note;
    • gemini-auth.test.mjs: Gemini speech with a received key prints one note with the path escaped;
    • bgm.test.mjs: Lyria music with a project key prints one note.
  • The tests that name a folder with a control character use a plain name on Windows, which refuses those names.

  • vitest run on dotEnv, contentExtractor, snapshot-contactSheet, cli.dotEnv, captureAttempt, media-use and resolver passes (192 tests). All 260 media-use audio script tests pass. The media-use copy-parity, terminalText parity and skill import-boundary checks pass.

  • tsc --noEmit for cli, oxlint, oxfmt, the comment ratchet and check-comment-citations pass.

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

A provider key from a project .env is still used when no own credential
competes. Capture vision (OpenRouter, Gemini, Google and both Vertex parts),
snapshot --describe, Gemini speech and Lyria music now print one note per key
before it is first used, naming the variable and the escaped .env path, as
the ElevenLabs note does. The ignoring notes escape the path too, and the
media-use skill gets a generated copy of the CLI's terminal-text helper.
@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 17, 2026, 8:12 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 90 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at caa1b64c

  • Every project .env key now gets a note before its first provider request:

    • capture vision (contentExtractor.ts:371)
    • snapshot --describe (snapshot.ts:2086)
    • Gemini speech (gemini-auth.mjs:19)
    • Lyria (bgm.mjs:140)

    Each note names the key that path actually reads.

  • A note is the right strength here. Base URLs, proxies and NODE_OPTIONS never load from a project .env, because both loaders accept only a fixed list of names (dotEnv.ts:6-24, heygen.mjs:72-80).

  • The shell still wins. A project value never overwrites an existing variable (dotEnv.ts:100), and a note fires only while the project value is the one in use. Notes print only the name and the escaped path, never the value.

  • Tests: locally, 107/107 focused vitest and 59/59 media-use and parity tests pass. Making both note helpers no-ops fails 5 CLI tests and 2 media-use tests. CI is green.

  • Nits, not blocking:

    • FIGMA_TOKEN from a project .env is still used with no note, so "every" in the title is slightly broad.
    • The two HeyGen "Using" notes (auth/resolver.ts:121, heygen.mjs:297) still print the path without terminalText.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low. The change only adds stderr output.

— Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at caa1b64c. Each project-.env provider key now prints one escaped note on stderr, naming the key and the file, before the key is used. No key value is ever printed.

Coverage. Each reader notes the key it actually uses:

  • Capture vision: visionCredential() follows the provider-pick order at contentExtractor.ts:353: OpenRouter, both Vertex parts, GEMINI, GOOGLE.
  • snapshot --describe: geminiKeyName() is GEMINI || GOOGLE.
  • Gemini speech: gemini-auth.mjs notes GEMINI first.
  • Lyria: bgm.mjs notes GOOGLE first, matching lyria-recipe.py:58.

Firing. A note fires only when projectEnvDir is set, so shell keys stay silent. The once-flag is set before the await.

#8043 findings. heygen.mjs now imports the shared skills/media-use/scripts/lib/terminal-text.mjs, and both generated copies are byte-identical.

Local verification

  • CLI vitest (dotEnv, contentExtractor, snapshot-contactSheet): 107 passed.
  • Skill node --test (gemini-auth, bgm, copy-parity): 15 passed.
  • generate-skill-module-copies.mjs --check: in sync.
  • Each of 5 mutants was caught:
    • M1, drop the once-flag: 3 failures.
    • M2, heygen.mjs path unescaped: "a received .env's Gemini key is used with one note naming the file".
    • M3, Vertex notes only its first part: "notes both parts…".
    • M4, Lyria names the wrong key: "Lyria music with a project .env's Gemini key prints one note".
    • M5, --describe names the wrong key: "notes once that --describe sends frames…".

Non-blocking. Points 1 and 2 predate this PR but are the same class of bug.

  1. packages/cli/src/utils/dotEnv.ts:251 prints ignored.join(", ") raw. Those key names come from a received .env, so an ESC sequence in a key name reaches the terminal. It's the one "ignoring" line in this file left unescaped.
  2. heygen.mjs:297 and auth/resolver.ts:121 still print join(dir, ".env") unescaped and don't use the shared helper.
  3. FIGMA_TOKEN is in PROJECT_ENV_KEYS (dotEnv.ts:10) and gets used silently (figma/tokens.ts:87 and others). The title says "every". Either note it, or narrow the title to the providers the description lists.
  4. Test gaps:
    • The escaped "ignoring" lines at dotEnv.ts:169 and heygen.mjs:210 have no test.
    • projectKeysNoted is module-level and never reset, so a future test in the same file could swallow another test's note.

Review by Rames

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 90de9b6 Nov 17, 2026
86 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-low26c-1117 branch November 17, 2026 17:14

This branch was successfully deployed

1 active deployment
staging - docs — caa1b64c Deployed Nov 17, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants