Pular para o conteúdo

// Decision comparison

.env file vs secret manager

5 minUpdated July 25, 2026By Ler em português

Quick answer

A .env file is the fastest way to store a secret in dev: one line, it works. The problem is it leaks through paths nobody notices until the incident: committed by mistake, printed in an error log, or, most common in AI-built SaaS, embedded in the client bundle by a public-prefixed variable (NEXT_PUBLIC_, VITE_, REACT_APP_) the tool exposed without warning. A secret manager (Doppler, Vault, AWS Secrets Manager, Vercel’s env panel) centralizes, controls access, rotates and audits who read what.

Rule of thumb: a local .env in dev is fine, as long as it is in .gitignore and no real secret (payment key, email, database) has a public prefix. For production, use your platform’s manager. And check TODAY whether any secret key is riding in the browser bundle, because that is the quietest and most expensive leak.

What changes between them

The difference is not just "where the key lives". It is access control, rotation and an audit trail, things a .env simply does not have.

.env vs secret manager
Aspect.env fileSecret manager
Ease early onMaximumNeeds setup
Leak risk (commit/log/bundle)HighLow
Key rotationManual, forgottenCentral, sometimes automatic
Control of who readsNoneBy role/environment
Access auditingNoneRecorded
Best forLocal devProduction and teams

The silent public-prefix leak

The mistake that most catches AI-built products: a secret key placed in a public-prefixed variable. NEXT_PUBLIC_, VITE_ and REACT_APP_ ship the variable to the JavaScript that runs in every visitor’s browser, so a "NEXT_PUBLIC_STRIPE_SECRET" or "VITE_SERVICE_ROLE_KEY" is visible to the world, with no warning from the tool. A scraper finds it in hours. A secret key NEVER takes a public prefix; it lives only on the server.

  • Secrets (payment, email, database, service_role) server-only, no public prefix.
  • Public prefix (NEXT_PUBLIC_/VITE_/REACT_APP_) only for values anyone may see.
  • When in doubt, open the bundle in the browser and search for the key; if you find it, it already leaked.

How RET catches this

The RET Promptbook has a specific step to hunt exposed secrets: it guides the AI to look for public-prefixed keys, hardcoded secrets and credentials in logs. AuditMySaaS monitors continuously for the day a new deploy re-exposes a key. It is one of the fastest findings to fix and most expensive to ignore.

Want to know whether this happens in your system?

Manual pentest for web applications, APIs and apps, from R$9,500, with the Sprint run within 7 business days. We refund 50% if we find no flaw.

See price and timeline for my case

Frequently asked questions

Can I use .env in production?

It can work, but you lose rotation, access control and auditing, and raise the risk of leaking via commit or log. For production, your platform’s secret manager (or Doppler/Vault) is the standard. A .env is fine in dev, in .gitignore.

What is the most common secret mistake in AI-built SaaS?

A secret key in a public-prefixed variable (NEXT_PUBLIC_/VITE_/REACT_APP_), which ships to the browser bundle and is visible to any visitor. A scraper finds it in hours. A real secret lives only on the server.

How do I know if I leaked a key on the front-end?

Open the site, view the source/bundle in the browser and search for the key (or prefixes like sk_, service_role). If it shows up, it is already public, rotate the key immediately and move it to the server.

Does RET find exposed secrets?

Yes. The Promptbook guides that hunt (public prefix, hardcoded, credentials in logs) and AuditMySaaS monitors re-exposure on every deploy. It is a fast, high-impact fix.

Keep reading