My repo is private. How did my secret key end up in the browser?
Last reviewed
Imagine your private repo contains no keys, but the caption generator you just shipped sends its paid AI key to every visitor. That can happen when the build copies a public environment setting into browser JavaScript. The copy travels with the page, regardless of who can open the repo.
See what ships in 30 seconds
Use a harmless marker such as peach-demo-417 in your own preview. Have a small client component display that marker from a public environment setting, build the preview, then open the page. In browser developer tools, open Sources and use the search across loaded files. Finding the marker in a JavaScript file shows exactly what the browser received. Searching this way covers the files that page loaded.
In a Vite-based Lovable project, look for VITE_ settings referenced by the client. Next.js uses NEXT_PUBLIC_ for values intentionally bundled for the browser. Reserve those settings for values intended to be public. Sources: Vite environment variables · Next.js environment variables
Give the browser a smaller job
For the caption generator, the browser sends the user’s caption request to your server. The server checks who may use the feature and how much they may use, then calls the provider with a secret held in a server-only setting. It returns the caption. This also gives you a place to stop unauthorized requests before they consume paid usage.
Some keys really are designed to ship. Supabase, for example, has publishable keys for client apps. Database grants and access policies still control what users can read or change. Supabase secret and service-role keys have elevated privileges and belong in trusted server components. Check the provider’s description of a key before deciding where it goes. Source: Supabase API keys
If a real secret already shipped
Treat the old key as exposed. Use the provider’s recovery process to revoke it promptly, replace it with a server-only credential, and deploy the corrected app. If the provider supports overlap and continuity matters, prepare the replacement so you can retire the old key without delay. Check provider activity for unexpected use during the exposure. Removing the value from Git or publishing a clean build cannot call back copies already downloaded. The decisive check is whether the provider still accepts the old credential. Source: OWASP secrets management
If the exposed key pays for AI requests, check for charges incurred outside your app. What to do about a stolen AI key and its bill.
Review environment-variable names and client imports in my project. Trace the caption request from the browser to the provider. Tell me which settings reach the browser and where the private provider call belongs. Show names and file paths only. Use a dummy marker if you need an example.
Check which services your preview can reach.
Review where else a secret could ship with Jungle’s prelaunch security guide.
Get early access to Jungle Security
Explore the proposed plans and join the waitlist for your app.