Find API keys leaked in your frontend (Next.js, Vite, React)
Updated November 17, 2026
Anything your frontend can read, a visitor can read. Open DevTools, search the JavaScript for sk_, and you'll find leaked keys on a surprising number of live apps. Bots do the same search automatically, all day.
How keys end up in the browser
Next.js: any variable starting with NEXT_PUBLIC_ is inlined into client bundles. NEXT_PUBLIC_OPENAI_API_KEY is a public key by definition. Plain process.env.OPENAI_API_KEY read inside a client component is either undefined or, with some setups, inlined.
Vite: only VITE_-prefixed variables reach the client, which tempts people to rename secrets to VITE_STRIPE_SECRET.
React Native / Expo: everything in the app bundle can be extracted from the installed app. There is no server side in your bundle. EXPO_PUBLIC_ variables are public.
Hard-coded: const apiKey = "sk-..." in a component, often pasted by an AI assistant to "make it work".
Check your own app
- Build for production and search the output:
npm run build
grep -rE "sk_live_|sk-[A-Za-z0-9]{20,}|service_role|AKIA[0-9A-Z]{16}" .next/static dist 2>/dev/null
- Search your git history, not just the current tree. A key deleted in a later commit is still in the repo.
Fix it
- Move the call to the server: an API route, a server action or an edge function. The browser calls your route; your route calls the provider.
- Rename the variable so it has no public prefix.
- Rotate the key. Once it shipped, assume it's been copied.
Stop it coming back
Periderm checks every file for secret-shaped variables read in client-reachable code and hard-coded keys, and knows server-only files ("use server", import "server-only", API routes) apart from client ones:
npm i -g periderm-cli
periderm scan
Add the GitHub Action and a leaked key gets flagged on the pull request, before it reaches main.