# Are secrets in VITE_ or NEXT_PUBLIC_ variables exposed?

> Short answer: rotate any private value that shipped, rename it to a server-only variable, and move provider calls behind a protected endpoint. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.

## What the secrets in VITE_ or NEXT_PUBLIC_ variables check covers

Vite replaces referenced VITE_ variables at build time, while Next.js exposes NEXT_PUBLIC_ variables to browser code. A local env file is a storage location, not a protection against client bundling.

The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.

Not every public environment value is a secret. A public API identifier or publishable key may be expected; a provider secret, service role, signing key, or unrestricted token must stay on a trusted server.

## Understand the evidence before changing code

Search the production bundle and source for the variable name, determine whether the value was a credential, and rotate it if public. Renaming the source variable does not revoke copies already downloaded.

Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.

## Apply the narrow, safe change

Move the provider call into a server route or function, store the key without a public prefix, and expose only the narrow operation the browser needs. Add authentication and rate limits where the action has cost or privilege.

Server-only environment variable:

```ts
const providerKey = process.env.PROVIDER_API_KEY;
// Use this only in a server route or server function.
```

Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.

## Verify the production result

Rebuild from a clean deployment, inspect the generated assets, and test the server endpoint. Confirm the new secret is available in the production environment but absent from browser responses.

Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.

## Keep the issue from returning

Add a CI rule that scans built assets for secret-like patterns and tell coding agents that public prefixes are not secret storage. Keep separate values for development, preview, and production.

Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.

## Limits and next steps

The scan cannot know whether a public value is intentionally publishable without provider context. Verify the credential's role with the provider and rotate it if its permissions are private.

Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.

A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.

## FAQ

**Can a clean secrets in VITE_ or NEXT_PUBLIC_ variables check prove the app is secure?**

No. It is evidence about the advertised public surface only. Only private credentials are a problem; public identifiers and publishable keys may be intentional.

**What should I do first if the finding is real?**

Rotate any private value that shipped and move the call to server-side code.

**Does ProofForge change application data?**

No. The scan is read-only and does not sign in, write records, or use a discovered secret. You make and review any remediation in your own project.

**What should I do after the repair?**

Inspect a fresh production build and test the protected endpoint.

## Key facts

- Vite's default public prefix is VITE_.
- Next.js uses NEXT_PUBLIC_ for values exposed to browser code.
- Changing a variable name does not invalidate a credential already shipped.

## Sources

- [vite.dev](https://vite.dev/guide/env-and-mode)
- [nextjs.org](https://nextjs.org/docs/app/guides/environment-variables)

## Related

- https://proofforge.live/fix
- https://proofforge.live/tools
- https://proofforge.live/check
- https://proofforge.live/methodology

---
Last updated 2026-11-25 · Reviewed by ProofForge. Methodology: https://proofforge.live/methodology. Scan your app: https://proofforge.live/
