Code you did not write, and secrets you should not ship · mid
Secrets in frontend bundles and source maps
Everything shipped to the browser or an app binary is public, so only publishable keys (restricted by domain, app id or scope) may be in client code, environment variables with public prefixes are inlined into the bundle, and real secrets stay on a server.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Build tools inline public env vars into JS at build time: NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_*. Anyone can read them in the bundle or the app package.
- Safe in the client: publishable keys designed for it (Stripe pk_, Google Maps key restricted by HTTP referrer or app id, Firebase config protected by security rules). Never: secret API keys, database URLs, signing secrets, admin tokens.
- Server-only code: in Next.js, keep secrets in Server Components, Route Handlers and Server Actions; use import 'server-only' so importing them from a client file fails the build. Don't pass secrets as props to Client Components.
- Source maps in production expose your original code (not secrets by themselves, but comments and logic); upload them to your error tool (hidden source maps) instead of serving them publicly if that matters.
- Obfuscation (minify, Hermes bytecode, ProGuard/R8) slows readers down; it does not hide secrets.
- If a secret leaked: rotate it first, then remove it from git history; scanning tools (GitHub secret scanning, gitleaks) catch many leaks before release.
The red pen
Common traps: mistake → fix
Mistake: "It's in an env variable, so it's secret"
Fix: public-prefixed env vars are copied into the bundle.
Mistake: "Minified code hides our API key"
Fix: a search in DevTools finds it in seconds.
Mistake: "Deleting the commit removes the leak"
Fix: assume it was copied; rotate the key.
Easy to hard
Questions interviewers ask, easy to hard
- Can you put an API key in a React app? Which keys are fine?
- How do env variables like NEXT_PUBLIC_ or VITE_ work?
- A pentest found a third-party secret key in your APK. How did it get there and what do you do?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.