The mistake
Putting a secret key in a variable with a public prefix: NEXT_PUBLIC_, VITE_, REACT_APP_, EXPO_PUBLIC_, PUBLIC_ or NUXT_PUBLIC_. Also: keys hard-coded in source, keys inside built JavaScript, and real-looking keys in .env.example.
Why it is dangerous
Bundlers copy every variable with a public prefix into the JavaScript sent to every visitor. A secret key there is public the moment you deploy: anyone can open DevTools, copy it and spend your credits or read your data. Bots scan deployed bundles for exactly these keys. Files in dist/, build/, out/ and .next/static are exactly what your host serves, and shipped .map files let anyone rebuild your original source.
How to fix it
- Rotate the key now. Every build made with the old value contains it, and old deploys and CDN caches keep serving it.
- Rename it without the public prefix so the bundler never inlines it, e.g.
NEXT_PUBLIC_OPENAI_API_KEY→OPENAI_API_KEY, set in.env.local(git-ignored) and in your host's environment settings. - Use it only in server code, and let the browser call your own endpoint instead.
What this checker looks for
This page runs key-leak-check, which reads
.env files, frontend source and build output (dist/, build/, .next/static). The rules most relevant to this page:
| Rule | What it finds |
|---|---|
KLC001 | Secret in a browser-exposed env var |
KLC002 | Client code reads a secret through a public env var |
KLC004 | API key hard-coded in source |
KLC005 | API key inside built JavaScript bundle |
KLC006 | Source maps shipped with the build |
KLC008 | Real-looking key in an env example/template |
Every finding has a rule id, a severity, file:line, the offending line (secrets masked),
why it matters and how to fix it. Run key-leak-check rules for the full list.