Skip to content
Exposed keys

VITE_ vs NEXT_PUBLIC_: what gets exposed?

VITE_ variables in Vite and NEXT_PUBLIC_ variables in Next.js are intended for client code. Do not put private credentials in them, and remember that build-time replacement can leave a value in already-generated public assets.

Check your app free, first fix free
By Brennan ZamboUpdated
In short

An environment variable is not automatically private. Its framework prefix, consumer and serialization path decide whether visitors can receive it. Keep private provider operations on a trusted server, rebuild after configuration changes and inspect the deployed output. Check public identifiers separately so that expected client configuration is not reported as a secret leak.

Understand what the prefix promises

Vite exposes its public-prefixed configuration through import.meta.env for client code. Next.js uses NEXT_PUBLIC_ for values intended to be included in browser code. These are conveniences for publishing configuration, not encryption mechanisms.

A variable without a public prefix can still leak if server code returns it in a response. Conversely, a client-safe analytics identifier or public project key is not a private credential just because it came from an environment file. Review the value's authority as well as its variable name.

Match the consumer to the framework

Do not copy a variable-access expression between frameworks without checking the runtime. A Vite browser module and a Next.js server module have different configuration behavior. A process.env expression in source does not, by itself, prove that the value remains on a server.

javascript
// Vite client: expected to be visible in the browser.
const apiBase = import.meta.env.VITE_PUBLIC_API_BASE;

// Next.js client: also public, not a private provider credential.
const publicSite = process.env.NEXT_PUBLIC_SITE_URL;

// Private provider calls belong in a trusted server module,
// with authorization, and must not return their credential.

The examples deliberately contain public addresses rather than private keys. Do not infer that adding the word PUBLIC to an arbitrary variable changes its treatment in every framework; the supported prefix and build configuration matter.

Rebuild when a build-time value changes

A deployed asset can retain the value that existed when the bundle was generated. Changing a dashboard setting does not necessarily rewrite an existing JavaScript file. Rebuild and redeploy the intended version, then inspect the actual assets referenced by the live HTML.

Compare preview and production separately. A preview can succeed with one backend URL while the published app still uses another. Record the environment and release you tested so that a passing local result does not become unsupported production evidence.

Repair the operation that needed the secret

If the browser needed a private key to call a provider directly, move that operation behind a trusted server endpoint. Validate callers, inputs and allowed actions. Do not create a route that returns the replacement key or accepts arbitrary provider requests without authorization.

Rotate any genuine credential already published, then inspect built assets, responses and relevant history for copies. A new variable name cannot revoke the old value. Keep debugging output masked so the repair process does not distribute the replacement.

Review configuration as part of a release

Separate public values, required server secrets and optional settings in your deployment checklist. Fail explicitly when a required server setting is missing instead of silently using a sample value or another project's credential. Then check normal and unauthorized user behavior after deployment.

Turn the check into a release decision

Keep a small record of the production URL, the time you checked it, the exact finding and the action you took. A local preview and a deployed application can have different environment variables, response headers and database projects. After a repair, deploy the intended version and check the public address again. Do not assume that changing a repository file changed the live system.

Read coverage as carefully as the score. A timed-out asset, an ambiguous backend configuration or a request that could not safely establish access should remain unknown. It should not disappear from your release notes merely because there is no red finding. If a check was not completed, decide who will review it and what additional evidence is needed.

ProofForge's free report includes the first fix. The $9 Fix Report unlocks all findings' available repair guidance and builder prompts, with a PDF and private report link. Fix + Guard costs $29 once and adds builder rules, on-demand deploy-hook scans for 30 days and four weekly rechecks you start yourself. These are different deliverables, not different promises that an application is completely secure.

Keep private report URLs out of public issues and commits. If you need shareable evidence, use the owner-verification and publication flow for an eligible receipt. A signature protects the recorded assessment against undetected changes; it does not make the assessment exhaustive, prove a business outcome, or show that a later deployment still matches an earlier result.

Questions builders ask

Does a .env file guarantee privacy?
No. The build or server can still publish its values. Review the framework and code paths that consume them.
Will changing a setting update existing JavaScript?
Not necessarily. Build-time values require a new build, and old downloaded assets can retain the previous value.
Is removing the prefix enough to repair a leak?
No. The private operation must run on a trusted server, and any already-exposed credential must be revoked or rotated.

Continue with a related guide

Sources

Read-only, about a minute

Scan your app free

See what your live app ships to every visitor, with the first fix free. A clean scan is not a full audit. Run it only on an app you own or have permission to test.

Scan your app free
All guides