# VITE_ variables are public: check your .env

> In a Laravel app with Vite, every VITE_ variable is built into the JavaScript you send to browsers. How to check yours and fix a leak.

Published 2026-12-01, by Lockhound. Source: https://lockhound.app/blog/vite-env-variables-leak-secrets

Laravel uses Vite for the frontend, and Vite has one rule worth knowing by heart: any variable that starts with `VITE_` is handed to your frontend code, and wherever that code reads it, its value is written into the JavaScript bundle at build time.

That's how `import.meta.env.VITE_APP_NAME` works. It's also how secrets end up on the public internet.

## How it goes wrong

You need to call an API from React or Vue. It needs a key. The frontend can't read `STRIPE_SECRET`, so you add:

```env
VITE_STRIPE_SECRET="${STRIPE_SECRET}"
```

Your component reads `import.meta.env.VITE_STRIPE_SECRET`, and it works. Now the secret key is in a `.js` file under `public/build`, served to every visitor. Minifying doesn't hide it: anyone can open the file and search for `sk_live`.

## Check your app

Look at what you're exposing:

```bash
grep -hE '^VITE_' .env .env.local .env.production .env.production.local 2>/dev/null
grep -rn 'import.meta.env' resources/js
```

The first shows what your env files offer to the browser, the second where your code reads it. Vite also uses `VITE_` variables set in the environment the build runs in, such as CI or server settings, and those win over the files, so look there too. Treat each of those values as public. Publishable keys meant for browsers (a Stripe `pk_` key, a Pusher or Reverb app key) are fine. Anything called secret, token, password or private is not.

Then check the built files, since that's what browsers actually get:

```bash
npm run build
grep -rE 'sk_live|sk_test|secret|password' public/build
```

That search is a quick look, not a scan: it only finds the patterns you typed. Add the prefixes of the keys you actually use.

## Fix it

1. Remove the `VITE_` variable and rebuild.
2. **Rotate the key.** It has been public since the first deploy that included it, and old bundles may still be cached by browsers and CDNs.
3. Move the call to your backend: a Laravel route that calls the API with the secret and returns only what the frontend needs.

## What a repository scanner won't see

This leak happens at build time, so it is often not in your repository at all. If `VITE_STRIPE_SECRET` is only set in the server's `.env` and your deploy script runs `npm run build` there, nothing is ever committed for a scanner to find: the secret appears in `public/build` on the server.

Lockhound's [secret check](https://lockhound.app/solutions/leaked-secret-detection) reads committed files. It will report a real key hard-coded in your JavaScript or a real value in a committed `.env`. It does not read built bundles. Nothing that only reads the repository can find a secret that exists only in the build, so search the built files, as above, in your deploy script or CI.

## The prefix is not the only way in

`define` in `vite.config.js` replaces a name in your code with a value at build time, so what you pass it ends up in the bundle wherever that name is used. A config that loads the env file with `loadEnv(mode, process.cwd(), '')` and passes `env.STRIPE_SECRET` to `define` publishes that secret with no `VITE_` anywhere. The `envPrefix` option changes which variables are handed to the frontend, so if someone has set it, check it is not broader than you think.

## The same rule elsewhere

Every frontend toolchain has a version of this: `NEXT_PUBLIC_` in Next.js, `REACT_APP_` in Create React App, `PUBLIC_` in SvelteKit and Astro. The prefix means "send this to the browser". Treat it that way.
