Vibe-coded app leaks API keys in client bundle

A non-programmer's AI-built booking app exposed Stripe, OpenAI, and Resend secrets in browser-loaded JavaScript. Automated bots probed for .env within weeks.

cpaua2 min11
Vibe-coded app leaks API keys in client bundle
Vibe-coded app leaks API keys in client bundle

According to the channel author, a widely saved Reddit post details how a non-programmer's vibe-coded application leaked three production API keys directly into client-side JavaScript. The author built a studio booking tool using Cursor and Claude with Supabase, Stripe, OpenAI, and Resend, believing that adding .env to .gitignore was sufficient protection.

Vite's VITE_ prefix pushed secrets to every browser

During development, Claude suggested calling APIs directly from the browser and prefixed every environment variable with VITE_. Vite's build process automatically includes any VITE_ variable in the client bundle, so the OpenAI key, a live Stripe secret key (sk_live_), and the Resend key were shipped to every visitor. The Stripe public key was never used correctly.

Automated scans targeted the hidden .env file

Server logs revealed that within two weeks of the obscure site going live, automated scripts attempted to fetch /.env 212 times. The .env file itself was not served — only the build directory was — but the exposure in JavaScript had already occurred. No spending limit existed on the OpenAI key.

Remediation: rotate keys, enforce hard limits, move calls server-side

The author rotated all three keys that evening, set a $20 hard limit on OpenAI that blocks requests rather than merely emailing alerts, and migrated every API call into Supabase Edge Functions so secrets never reach the browser.

Two five-minute checks before any public launch

First, after building, search the output directory for the strings sk-, sk_live_, and key. Second, in every provider dashboard enable a hard spending cap that automatically rejects requests once the threshold is hit. These steps would have caught the leak before any bot could exploit it.

Sources

reddit.com — content not available without authorization

Share

Author

cpaua

VibeCode blog admin. Writing about vibe coding, AI and open source.

Related news

Comments

To leave a comment, log in
Loading...

Weekly digest

The best of vibe coding, AI agents and open source — once a week, no spam.