Repository navigation
docs: correct AGENTS.md secrets guidance to match #2140 - #2549
Conversation
The Environment section still taught the import.meta.env fallback chain as the 'secrets pattern'. Since #2140, secrets are read from process.env only — import.meta.env is statically inlined at build time, which bakes build-machine values into the bundle and shadows runtime secrets. The fallback chain remains correct for public build-time config, so the line is split rather than removed.
|
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
The change is the right one. Relabeling the old fallback chain as public build-time config and adding a hard rule that secrets read process.env only matches the implementation in packages/core/src/config/secrets.ts and fixes the real issue described in #2139/#2140: Vite replaces bare import.meta.env expressions with an object literal built from build-time env, so using them for secrets bakes build-machine values into the bundle and shadows runtime secrets set via wrangler secret put.
I checked the diff, the full AGENTS.md, packages/core/src/config/secrets.ts (its readDefaultEnv reads only process.env and the long docstring explains the inlining risk), and searched the tree for remaining import.meta.env reads of secret-shaped variables.
The AGENTS.md edit is consistent and well-scoped, but it is contradicted by shipped code and by JSDoc examples across the tree. The most serious contradiction is in packages/core/src/comments/turnstile.ts, which reads EMDASH_TURNSTILE_SECRET_KEY from import.meta.env on the logged-out public comment-submission route. Because Vite statically replaces that reference with the build-time value, a runtime secret set on the deployment platform is ignored; if the build machine has no such secret, Turnstile enforcement silently falls back to "" and spam protection is disabled.
Less severe but still wrong, several @example blocks show import.meta.env.EMDASH_AUTH_SECRET and import.meta.env.PREVIEW_SECRET for secrets. Any reader who copies those examples will end up with the same build-time-inlining problem.
Suggested resolution: update turnstile.ts to read from process.env, and update the JSDoc examples to match. If you want to keep this PR strictly docs-only, the Turnstile fix at minimum needs to land immediately after (or before), because leaving it in place makes the new AGENTS.md guidance factually false for the codebase.
No test/build/lint issues to report — those are n/a for this docs change.
Findings
-
[needs fixing]
packages/core/src/comments/turnstile.ts:21This function resolves the Turnstile secret from
import.meta.env.EMDASH_TURNSTILE_SECRET_KEYat request time. Vite statically replacesimport.meta.envwith an object literal built from env values present at build time, so the runtime secret set on the deployment platform is ignored. In production this can silently disable Turnstile enforcement (the""fallback) and allow spam through the logged-out comment route. This is the exact bug the updated AGENTS.md rule warns about.The comment route already uses
process.env-based resolution (resolveSecretsCached) foripSalt; the Turnstile secret should useprocess.envtoo.return process.env.EMDASH_TURNSTILE_SECRET_KEY || process.env.TURNSTILE_SECRET_KEY || ""; -
[needs fixing]
packages/auth/src/index.ts:17This
@exampleshows reading the auth signing secret viaimport.meta.env.EMDASH_AUTH_SECRET, which contradicts the new AGENTS.md rule. Anyone copying this example will bake their secret into the build bundle. Update it to useprocess.env.* secret: process.env.EMDASH_AUTH_SECRET, -
[needs fixing]
packages/cloudflare/src/db/do-preview.ts:18This
@exampleconfigures the preview middleware with a secret read fromimport.meta.env.PREVIEW_SECRET, which contradicts the new AGENTS.md rule. The preview secret is a cryptographic secret; runtime values must come fromprocess.env.* secret: process.env.PREVIEW_SECRET, -
[needs fixing]
packages/cloudflare/src/db/do-preview-sign.ts:48This
@examplepasses the preview signing secret fromimport.meta.env.PREVIEW_SECRET, contradicting the new AGENTS.md guidance. Update the example to useprocess.envso operators do not embed runtime secrets in the bundle.* process.env.PREVIEW_SECRET, -
[needs fixing]
packages/core/src/preview/index.ts:19This
@examplereads the preview secret fromimport.meta.env.PREVIEW_SECRET, which the updated AGENTS.md explicitly forbids for secrets. Useprocess.envin the example.* secret: process.env.PREVIEW_SECRET, -
[needs fixing]
packages/core/src/preview/tokens.ts:184This
verifyPreviewToken@examplereads the preview secret fromimport.meta.env.PREVIEW_SECRET(the second example on line 190 has the same issue). That contradicts the new AGENTS.md rule. Update both examples toprocess.env.PREVIEW_SECRET.* secret: process.env.PREVIEW_SECRET,
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 7bfc496 | Aug 19 2026, 01:30 AM |
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 7bfc496 | Aug 19 2026, 01:30 AM |
What does this PR do?
Fixes stale agent guidance in AGENTS.md: the Environment section still taught
import.meta.env.EMDASH_X || import.meta.env.X || ""as the "Secrets pattern". Since #2140 secrets are read fromprocess.envonly — Vite statically inlinesimport.meta.envat build time, which bakes build-machine secrets into the shipped bundle and shadows runtime values set viawrangler secret put(see #2139 and thereadDefaultEnvdoc comment inpackages/core/src/config/secrets.ts).The fallback chain is still the documented convention for public build-time config, so the line is relabeled and a secrets rule added alongside it, rather than removed.
Type of change
Checklist
pnpm typecheckpasses — n/a, docs-only change (no source touched)pnpm lintpasses — n/a, docs-only changepnpm testpasses (or targeted tests for my change) — n/a, docs-only changepnpm formathas been run — n/a, markdown edit onlyAI-generated code disclosure
Screenshots / test output
n/a