Skip to content

Document VITE_* env vars must not be marked secret in Netlify - #3

Merged
borland667 merged 1 commit into
mainfrom
ops/document-vite-env-secret-foot-gun
Jun 14, 2026
Merged

Document VITE_* env vars must not be marked secret in Netlify#3
borland667 merged 1 commit into
mainfrom
ops/document-vite-env-secret-foot-gun

Conversation

@borland667

Copy link
Copy Markdown
Owner

Summary

Follow-up to PRs #1 and #2. Captures the root-cause lesson from this morning's silent analytics regression: the GH Actions deploy pipeline was correct, the Netlify env was misconfigured. All four VITE_* values (VITE_POSTHOG_KEY, VITE_ANALYTICS_ENABLED, VITE_ANALYTICS_PROVIDER, VITE_POSTHOG_HOST) had been flagged as Netlify "secret" env vars, which hides them from the build environment. Vite reads env at build time only, so the bundle shipped with empty values and PostHog analytics were silently dead in prod.

I unmarked them at the project level (netlify env:unset + netlify env:set without --secret); the latest production deploy now bakes SStrVZFix... into the bundle. This PR documents the rule so it does not regress.

What changed

  • AGENTS.md §3 — Production Deploy Pipeline: explicit split between GH repo secrets (auth-only: NETLIFY_AUTH_TOKEN, NETLIFY_SITE_ID, PRODUCTION_DATABASE_URL) and Netlify project env (everything else). New subsection forbidding the --secret flag on any VITE_* value and giving the audit command.
  • docs/ARCHITECTURE.md §15.4: same rule, captured next to the rest of the pipeline contract so on-call has a single reference.

Test plan

  • Live bundle now contains the PostHog key (verified by curl <bundle> | grep SStrVZFix)
  • netlify env:list --context production --plain | grep '^VITE_' returns unmasked values
  • Docs render correctly in GitHub preview

Made with Cursor

While verifying the new GH Actions deploy pipeline we discovered the
production bundle still shipped with empty VITE_POSTHOG_KEY,
VITE_ANALYTICS_*, and VITE_POSTHOG_HOST values. Root cause: all four
were flagged as "secret" Netlify env vars, which hides them from the
build environment (secret values only reach Functions at request
time). Vite reads env at build time only, so the bundle emitted
empty strings and silently disabled PostHog analytics in production.

Unmark the offending vars at the project level via `netlify env:unset`
+ `env:set` (no `--secret` flag). This change captures the lesson so
future agents do not flag VITE_* vars secret again:

- AGENTS.md §3: extends the deploy rules with the
  source-of-truth split between GH secrets (auth only) and Netlify
  project env (everything else), plus an explicit rule that VITE_*
  vars must be regular (non-secret) and a quick audit command.
- docs/ARCHITECTURE.md §15.4: adds the same rule and the
  netlify env:list --plain audit pattern.

No code or workflow changes; only docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@borland667
borland667 merged commit 5f7205b into main Jun 14, 2026
6 checks passed
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.

1 participant