Skip to content

docs: correct AGENTS.md secrets guidance to match #2140 - #2549

Merged
ascorbic merged 1 commit into
mainfrom
docs/agents-md-secrets-pattern
Aug 19, 2026
Merged

ascorbic merged 1 commit into
mainfrom
docs/agents-md-secrets-pattern

Conversation

@ascorbic

Copy link
Copy Markdown
Member

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 from process.env only — Vite statically inlines import.meta.env at build time, which bakes build-machine secrets into the shipped bundle and shadows runtime values set via wrangler secret put (see #2139 and the readDefaultEnv doc comment in packages/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

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes — n/a, docs-only change (no source touched)
  • pnpm lint passes — n/a, docs-only change
  • pnpm test passes (or targeted tests for my change) — n/a, docs-only change
  • pnpm format has been run — n/a, markdown edit only
  • I have added/updated tests for my changes (if applicable) — n/a
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — n/a
  • I have added a changeset (if this PR changes a published package) — n/a, no published package changed
  • New features link to an approved Discussion — n/a

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Fable 5 (autonomous docs fix)

Screenshots / test output

n/a

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.
Copilot AI lite review requested due to automatic review settings August 19, 2026 01:24
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7bfc496

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added size/XS review/awaiting-author Reviewed; waiting on the author to respond labels Aug 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2549

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2549

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2549

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2549

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2549

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2549

emdash

npm i https://pkg.pr.new/emdash@2549

create-emdash

npm i https://pkg.pr.new/create-emdash@2549

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2549

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2549

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2549

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2549

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2549

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2549

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2549

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2549

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2549

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2549

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2549

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2549

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2549

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2549

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2549

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2549

commit: 7bfc496

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:21

    This function resolves the Turnstile secret from import.meta.env.EMDASH_TURNSTILE_SECRET_KEY at request time. Vite statically replaces import.meta.env with 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) for ipSalt; the Turnstile secret should use process.env too.

    	return process.env.EMDASH_TURNSTILE_SECRET_KEY || process.env.TURNSTILE_SECRET_KEY || "";
    
  • [needs fixing] packages/auth/src/index.ts:17

    This @example shows reading the auth signing secret via import.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 use process.env.

     *         secret: process.env.EMDASH_AUTH_SECRET,
    
  • [needs fixing] packages/cloudflare/src/db/do-preview.ts:18

    This @example configures the preview middleware with a secret read from import.meta.env.PREVIEW_SECRET, which contradicts the new AGENTS.md rule. The preview secret is a cryptographic secret; runtime values must come from process.env.

     *   secret: process.env.PREVIEW_SECRET,
    
  • [needs fixing] packages/cloudflare/src/db/do-preview-sign.ts:48

    This @example passes the preview signing secret from import.meta.env.PREVIEW_SECRET, contradicting the new AGENTS.md guidance. Update the example to use process.env so operators do not embed runtime secrets in the bundle.

     *   process.env.PREVIEW_SECRET,
    
  • [needs fixing] packages/core/src/preview/index.ts:19

    This @example reads the preview secret from import.meta.env.PREVIEW_SECRET, which the updated AGENTS.md explicitly forbids for secrets. Use process.env in the example.

     *     secret: process.env.PREVIEW_SECRET,
    
  • [needs fixing] packages/core/src/preview/tokens.ts:184

    This verifyPreviewToken @example reads the preview secret from import.meta.env.PREVIEW_SECRET (the second example on line 190 has the same issue). That contradicts the new AGENTS.md rule. Update both examples to process.env.PREVIEW_SECRET.

     *   secret: process.env.PREVIEW_SECRET,
    

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do 7bfc496 Aug 19 2026, 01:30 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅

View logs ↗
7bfc496 2026-08-19T01:30:18.932Z Visit the dashboard ↗

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 7bfc496 Aug 19 2026, 01:30 AM

@ascorbic
ascorbic merged commit b05834e into main Aug 19, 2026
49 checks passed
@ascorbic
ascorbic deleted the docs/agents-md-secrets-pattern branch August 19, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/awaiting-author Reviewed; waiting on the author to respond size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants