Skip to content

fix(cli): a project .env key is used only when nothing is saved - #7848

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-project-env-key-1115
Nov 15, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-project-env-key-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

A HeyGen key from a project .env is now the last credential the CLI and the media-use skill consider. It is used only when the person has no saved login, no saved API key and no key exported in the shell. When it is used, the CLI and the skill print one stderr line that names the .env file.

This builds on #7808 and #7837. Those PRs applied the same rule to a .env that came in with a received project, which is a folder that a .hyperframes/received-files.json record lists. This PR applies the rule to every project .env, including folders that have no record, such as a git clone, an unzipped archive or a copied template.

Why

Every CLI run loads HEYGEN_API_KEY and HYPERFRAMES_API_KEY from the .env in the working directory. A folder without a received-files record looked like the person's own, so its key behaved like a shell-exported key:

  • It was used ahead of the API key the person saved with auth login --api-key, without any notice.
  • When the saved login had expired, belonged to another OAuth client, could not be read, or HeyGen refused to refresh it, the CLI switched to that key instead of asking the person to sign in again.

In both cases, uploads, renders and generated media could go to an account that the folder's author chose, not the person running the command.

Related work

Refs #7808 and #7837.

How

The resolution order is now:

  1. HEYGEN_ACCESS_TOKEN from the host app.
  2. The saved login, fresh or refreshable.
  3. HEYGEN_API_KEY, then HYPERFRAMES_API_KEY, when the shell or the launching app set them.
  4. The API key saved with auth login --api-key.
  5. A key from a project .env, only when nothing is saved and the shell sets none.

Details:

  • packages/cli/src/auth/resolver.ts splits env keys into shell keys and project keys, using the origin map that dotEnv.ts already keeps. The resolver no longer needs the received-files lookup, because the received case is now a subset of the project case.
  • An expired, foreign-client, unreadable or refused login never falls back to a project key. It raises the existing login error. A shell key can still replace a refused login, as before.
  • afterRefreshFailure falls back only to a shell key.
  • The stderr notice now covers any project key and includes the file path.
  • withMediaAuthEnvironment also drops HYPERFRAMES_API_KEY from the child environment when it passes an API key, so a helper sees only the selected key.
  • The media-use skill's heygen.mjs applies the same order and prints its own notice with the path. Its received-files walk is removed for the same reason.
  • HEYGEN_ACCESS_TOKEN and the host gateway path keep their current behaviour. A .env never overrides a variable that is already set, so a key that HyperFrames Desktop or another host app sets in the environment still counts as a shell key.
  • Docs, skill references and the auth help text now state the new order.

Test plan

  • 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

  • bunx vitest run src/auth/resolver.test.ts src/auth/media-environment.test.ts in packages/cli.

  • node --test skills/media-use/audio/scripts/lib/heygen.test.mjs.

  • tsc --noEmit in packages/cli.

  • New tests cover a folder with no received-files record and a received folder:

    • A saved API key wins over the project key, in the resolver, the media environment and the skill.
    • With nothing saved, the project key is used and the file path is printed once.
    • An expired login, a login from another OAuth client, an unreadable credentials file, or a refused refresh raises the login error, and no request is made with the project key.
  • Guard tests: a shell key keeps its place, a key the launching app set is not replaced by the .env, the gateway path is unchanged, and the received-files tests from fix(cli): benchmark keeps received files' rule; a received .env key never replaces a login #7837 still pass.

A HEYGEN_API_KEY or HYPERFRAMES_API_KEY that a project .env sets now comes
after every credential the person saved or exported. The CLI resolver, the
media environment and the media-use skill use it only when there is no saved
login, no saved API key and no key in the shell. When one is used, a single
stderr line names the .env file.

An expired, foreign-client, unreadable or refused login now raises the login
error instead of switching to a project .env key, whether or not the folder
has a received-files record. A key exported in the shell, or set by the app
that launched the CLI, keeps its current place, and the host gateway path is
unchanged.
@mintlify

mintlify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

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

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 15, 2026, 5:42 PM

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

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 101 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)

Unstable (1)

  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@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.

Reviewed at 44935b7422d0ee93b97c8f512621399185ae0ba6.

For HeyGen's API, a project-loaded key now follows the saved login, shell keys and saved API key; a failed/expired/foreign login or unreadable/JSON-syntax-invalid credential file does not select that project key. afterRefreshFailure only considers shell keys. The media wrapper removes the unselected alias before spawning a helper.

Need: yes · Size: ok · Reuse: existing dotenv-origin map and credential store · Simpler: removes the received-files walk · Structure: fine (checked CLI resolver against the existing standalone skill resolver; no new abstraction)
Risk: medium — credential selection controls the account receiving work and paying for it.

The skill duplicates the resolver; it does not call the CLI implementation. Its standalone Node requirement explains that existing split. I checked the two public-API precedence paths, the cloud refresh/401 handoff, and the media child environment. The skill cannot refresh a login itself: it emits a refresh/sign-in instruction. The CLI refreshes where possible; refused refreshes retain the auth error/hint. The media wrapper can still run anonymous/local providers after a nonrefreshable expired login, with all HeyGen credential variables removed; it does not silently send the project key.

Verification: bun run build, CLI bun run typecheck, and gen:skills-manifest --check pass. CLI auth/cloud-auth/dotenv tests plus four reviewer child-process cases: 257 passed. The child loads the actual standalone skill against fresh login, saved API key, expired login and no-store fixtures. Skill credential/TTS/voice suites: 51 passed. Keeping the new tests but reverting resolver, media-environment and skill production code gives 14 CLI failures (48 pass) and 6 skill failures (30 pass); restoration gives 62 CLI / 36 skill passes. Both #7808 and #7837 merge commits are ancestors of this head. These use synthetic credentials and local fixtures/mocked refresh responses, not live paid requests.

Nit — qualify the docs' absolute rule (docs/guides/authentication.mdx:64, docs/packages/cli.mdx:2595): the deliberately retained host-gateway branch still permits a project key ahead of saved credentials when the host set a non-HeyGen API base and supplied no key. The CLI test explicitly pins this exception. In the standalone skill that early gateway path also bypasses the new project-key notice. A project .env cannot itself set the gateway through either allowlisted loader. State that the new last-resort/notice guarantee applies to normal HeyGen resolution, with the host-gateway exception, instead of “never” universally. This exception is existing behavior expressly retained in the PR’s scope, not a new ability for a project to choose the destination host. Existing standalone semantic store-parser leniency and lack of refresh are also not closed by this change.

Current-main trial merge is clean. No new account-switching defect found in the changed normal API paths.

Verdict: APPROVE
Reasoning: The change removes project-key precedence for cloned/unrecorded projects while preserving explicit host/shell behavior, and expired/refused login paths in normal HeyGen resolution do not adopt the project wallet.

— cutroom-review

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit de1ce68 Nov 15, 2026
139 of 141 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-project-env-key-1115 branch November 15, 2026 18:20
daedal-ping Bot pushed a commit to DaedalGames/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.54

* chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849

* chore: release v0.9.54 notes include heygen-com#7853

* chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855

This branch was successfully deployed

1 active deployment
staging - docs — 44935b74 Deployed Nov 15, 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