How AI-Built Next.js & Vite Apps Accidentally Leak Live Stripe, Supabase, and OpenAI Keys (And How to Audit Yours in 30 Seconds)
Over the last year, shipping a production SaaS or client web app with Cursor, Lovable, Bolt, or v0 has gone from taking three weeks to taking an afternoon. The catch: AI code generators optimize for "make the demo work
Over the last year, shipping a production SaaS or client web app with Cursor, Lovable, Bolt, or v0 has gone from taking three weeks to taking an afternoon.
The catch: AI code generators optimize for "make the demo work on the first try." And the fastest way to make a frontend prototype talk to Stripe, OpenAI, or Supabase is often putting the credential straight into a client-side file or prefixing an environment variable with NEXT_PUBLIC_ or VITE_.
Once deployed, those bundles sit on public URLs that automated scrapers scan continuously.
Here are the four most common production leaks we see when auditing externally facing web apps β and how to verify your own site in under a minute.
1. The NEXT_PUBLIC_ / VITE_ Prefix Trap
In Next.js, Vite, and Create React App, any environment variable starting with NEXT_PUBLIC_, VITE_, NUXT_PUBLIC_, or REACT_APP_ is inlined verbatim into the JavaScript shipped to every browser.
Common mistakes that survive into production:
-
NEXT_PUBLIC_STRIPE_SECRET_KEY=sk_live_...(onlypk_live_...is safe in browsers) -
VITE_OPENAI_API_KEY=sk-proj-...orNEXT_PUBLIC_ANTHROPIC_API_KEY=sk-ant-api03-... -
NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY=eyJ...(unlike theanonkey, theservice_roleJWT bypasses every Row Level Security policy in your database)
Quick check
Inspect your rendered HTML (__NEXT_DATA__, __NUXT__, inline <script> tags) and your first-party JavaScript chunks β or run a read-only external check with our free Frontend Secret Leak Checker (it inspects public HTML, hydration JSON, and first-party JS bundles across 12 live credential families, ignores safe publishable/anon keys, masks matches in memory, and stores nothing).
2. Public .js.map Source Maps in Production
Even when you think your client code is minified, a trailing //# sourceMappingURL=app.chunk.js.map comment tells anyone where to download your unminified TypeScript source, comments, internal API paths, and accidentally hardcoded test values.
Fix
Upload source maps privately to your error tracker during CI, and disable public source map serving in production:
// next.config.js
module.exports = {
productionBrowserSourceMaps: false,
};
// vite.config.ts
export default defineConfig({
build: {
sourcemap: "hidden", // generates .map for private upload, omits sourceMappingURL comment
},
});
3. Dependency Bloat & CISA KEV Advisories in Lock Files
AI editors frequently install older versions of next, axios, Django, laravel/framework, or transitive dependencies straight from their training cutoff. Running npm audit or checking a raw CVE feed often dumps 40+ noisy alerts with no clear order of action.
What actually matters first:
- Is the flaw on CISA's Known Exploited Vulnerabilities (KEV) catalog? (Actively exploited in the wild right now.)
- Which single version bump resolves all open advisories for that package at once?
We built a browser-local Lockfile & SBOM CVE Checker that parses package-lock.json, yarn.lock, composer.lock, requirements.txt, poetry.lock, uv.lock, Cargo.lock, go.mod, and CycloneDX/SPDX SBOMs locally in JavaScript (so private paths and registry URLs never leave your browser), cross-references OSV.dev and CISA KEV, and groups all advisories per package into one copyable upgrade command.
4. Missing Basic Production Hygiene (HSTS, robots.txt, SSL & Multi-Region Uptime)
Security leaks rarely happen in isolation. The same fast deploys that ship a service_role key also accidentally deploy:
-
<meta name="robots" content="noindex">copied over from staging (silently de-indexing your entire site) - Missing
Strict-Transport-Security(HSTS) andContent-Security-Policyheaders - Expiring TLS certificates or domains sitting in a forgotten registrar account
You can audit all of those in one shot with our free no-login Website Health & Security Scan, or read the full Cursor, Lovable & Bolt Production Security Checklist.
If you want those checks running automatically every day β plus two-region EU uptime monitoring and a 16-tool hosted MCP server you can connect straight to Cursor, Claude, Codex, or ChatGPT β Beamfar includes a permanent free tier for 1 site (no card required).
What is the wildest environment variable or staging artifact you've caught right before (or after) deploying an AI-assisted app? Drop it in the comments.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.