Modern web applications built with Next.js, React, Vue, or Vite compile client-side modules into static JavaScript chunks served directly to every visitor's browser. One of the most common high-severity findings in automated web assessments is a private backend API key, webhook signing secret, or cloud storage credential accidentally bundled into those public `.js` or `.js.map` files during build time.
Three ways private secrets end up in public browser assets
Build bundlers inline environment variables and imported JSON files at compile time. When the boundary between server-only code and client-rendered components blurs, credentials leak through three predictable paths:
- Public environment variable prefixes: prefixing a private key with `NEXT_PUBLIC_`, `VITE_`, or `REACT_APP_` instructs the bundler to replace every reference with the literal secret string inside the public client bundle.
- Exposed production source maps: deploying `.js.map` files to production CDN storage allows anyone to reconstruct the original unminified TypeScript source, developer comments, internal staging URLs, and helper modules.
- Shared utility modules imported by client components: placing server constants, payment gateway keys, or privileged database helpers in a shared `config.ts` file that gets imported by even a single `'use client'` component.
How to prevent and detect client-side secret exposure
Keep all private API keys, LLM tokens, database URLs, and signing secrets in server-only environment variables without public prefixes, and use framework guards (such as the `server-only` package in Next.js) on modules that read privileged configuration so any accidental client import fails the build immediately.
Disable public browser source maps in production builds (or upload them privately to your error-tracking provider without serving `.map` files publicly), and run MyPentest against your deployed domain to crawl JavaScript bundles and check for exposed credentials, source maps, and `.env` files.
If a key grants write access, paid API usage, or private data reads, it must stay in server-only code and never carry a NEXT_PUBLIC_ or VITE_ prefix.