Why Your Frontend AI-Generated Code Is Secretly Leaking Your Runtime Assets

By Katia Kupidonova 8 min read

If you’ve built a modern web app recently, you’re probably using LLM tools to ship JavaScript faster and add features like real-time user recommendations. You’re not alone.

Anything that ships in a client-side bundle, including API keys, system prompts, and internal endpoints, can be read by anyone who loads the page. Minification doesn’t change that. Keep credentials and guardrails on the server, and protect the application logic that has to run in the browser. 

If you’ve built a modern web app recently, you’re probably using LLM tools to ship JavaScript faster and add features like real-time user recommendations. You’re not alone: 84% of respondents to Stack Overflow’s 2025 Developer Survey said they use or plan to use AI tools in their development process.

AI coding assistants (like GitHub Copilot, ChatGPT, or Claude) write frontend code in record time. But in the rush to push features, a dangerous habit has crept into modern builds: shipping sensitive runtime logic, system prompts, and hardcoded secrets directly into client-side bundles.

Let’s take a look at how this happens under the hood, why minification won’t save you, and how to stop treating the browser runtime like a secure vault.

The Myth of the “Hidden” Frontend Asset

When you run npm run build or let Webpack/Vite bundle your application, it minifies variable names, strips whitespace, and concatenates your modules into neat .js chunks.

It feels compiled. It looks messy. But minification is not encryption.

From a developer’s perspective, the browser is an open book:

  1. Developer tools (F12): anyone can open the Network tab, inspect active WebSocket connections, or set breakpoints in your sources.
  2. DOM and state inspection: global variables, reactive stores (like Pinia or Redux), and DOM elements can be read and changed from the DevTools console.
  3. Source maps and AST tools: if source maps ship to production, your original source is one download away. When Apple launched its redesigned App Store website in November 2025 with source maps enabled in production, its front-end code was downloaded and mirrored to GitHub within hours. Without source maps, AST (Abstract Syntax Tree) tools still reformat minified bundles in seconds, and academic deobfuscators keep improving. The same research finds that layered, commercial-grade obfuscation remains the hardest to undo.

If your React, Vue, or Svelte component initializes an AI helper by grabbing an API token, parsing a system prompt template, or passing internal endpoint structures, that data appears as plain text in the user’s browser process.

How AI Runtime Secrets Slip Into Client Bundles

Here are the three most common ways AI-generated code inadvertently exposes sensitive AI assets, and why AI-assisted coding is making it worse:

1. AI coding assistants autocompleting hardcoded secrets

When developers use LLM tools to generate front-end code, the AI often suggests quick boilerplate for calling external APIs or initializing client SDKs. Sometimes those suggestions contain real credentials: university researchers extracted 2,702 valid hard-coded secrets from GitHub Copilot suggestions, memorized from public code.

More often, the assistant writes the API call inline, and the developer pastes in a key to make it “just work.” GitGuardian found that public repositories using Copilot leaked secrets at a 6.4% rate, about 40% higher than the average across all public repositories. Its 2026 report found commits co-authored by Claude Code leaked secrets at roughly twice the baseline rate (3.2% vs. 1.5%).

Moving keys into .env files doesn’t solve it on its own. Front-end frameworks inline any variable with a public prefix, like Next.js NEXT_PUBLIC_ or Vite VITE_, straight into static JavaScript at build time, as the Next.js and Vite docs explain. Vite’s guide says plainly that these variables “should not contain sensitive information such as API keys.”

The result is visible on the open web. A Stanford-led study of 10 million webpages found 1,748 verified API credentials exposed on 9,804 sites, 84% of them in JavaScript files. Cyble identified about 3,000 public websites exposing ChatGPT API keys in client-side code.

2. System prompts and core business logic as frontend state

Your system prompts are your intellectual property. They define guardrails, proprietary formatting rules, and internal business logic. When AI assistants generate client-side prompt-builder logic, they assemble or modify prompts in browser state before sending them to an API.

Anyone with DevTools open can read, copy, or edit those prompt strings in the Network tab before they’re sent, stripping out guardrails or cloning your features. Worse, if your backend accepts whatever prompt the browser sends, your AI endpoint becomes a general-purpose LLM on your bill.

Attackers already profit from stolen LLM access. In the first reported “LLMjacking” campaign, Sysdig estimated victims could face over $46,000 a day in model costs. The OWASP Top 10 for LLM Applications is blunt about the lesson: the system prompt “should not be considered a secret, nor should it be used as a security control.”

3. Exposed internal endpoints and “convenience” scaffolding

AI-driven code needs to know which backend services to call. But when LLM tools scaffold client-side API callers and backend handlers, they tend to prioritize working code over security guardrails:

  • Missing checks and permissive defaults: to make generated code “just work” without runtime errors, AI-generated code can omit authorization checks or skip token verification. Veracode’s 2025 GenAI Code Security Report found that AI-generated code introduced security flaws in 45% of tested tasks across more than 100 LLMs. Apiiro’s analysis of enterprise repositories found privilege escalation paths jumped 322% in AI-assisted code.
  • Exposed routes and parameters: scaffolding can wire client components directly to backend routes, internal query parameters, and staging endpoints, because that’s the fastest path to working code. When Wiz examined the AI app builder Base44, the app ID visible in each app’s URL and manifest.json was enough to reach undocumented registration endpoints and bypass authentication on private apps (fixed within 24 hours).

Developers may not notice. In a Stanford study, participants with an AI assistant wrote significantly less secure code than those without, and were more likely to believe it was secure.

Once client bundles expose route structures, they give attackers a roadmap to query backend APIs directly and exploit any missing server-side access controls. When Escape scanned 5,600 publicly available vibe-coded apps, it found more than 2,000 vulnerabilities and over 400 exposed secrets, with Supabase service keys often “trivially retrievable from frontend bundles.”

Why Server-Side Perimeter Rules Can’t Help You Here

As engineers, we often think: “We have a Web Application Firewall (WAF) and strict CORS policies, so we’re safe.”

Here’s the issue. A WAF filters malicious traffic to your servers. CORS is enforced by browsers and only controls which other origins may read your API responses; it does nothing against a direct request from curl or a script. Neither can protect assets you willingly bundle and ship to a user’s browser. Once your code loads on the user’s machine, it executes locally, and your server-side controls can’t see what happens there.

How to Lock Down Frontend AI Assets

Fixing this doesn’t mean abandoning client-side performance or tearing down your SPA architecture. It takes a two-part approach:

  1. Keep credentials and guardrails server-side. Don’t accept AI tool output blindly. Keep master API keys and primary system prompts out of front-end code. Use serverless proxy functions or a Backend-for-Frontend (BFF) layer for token exchange and prompt assembly. Enforce authorization and prompt guardrails on the server, scope any client token narrowly and keep it short-lived, rate-limit the proxy, and add secret scanning to CI so a key an assistant suggests never reaches a build.
  2. Protect the application logic that must run in the browser. Modern SPAs still need substantial business logic and UI controls on the client, and minification offers no meaningful protection for them. Polymorphic obfuscation and runtime integrity checks add a crucial layer of defense. One caveat: obfuscation protects logic, not secrets. Any key or token the browser sends is visible in the Network tab, so credentials belong in step 1.

Protecting strings and literals, flattening control flow, and adding anti-debugging and anti-tampering checks make reverse engineering and automated scraping much harder and more expensive. Because every protected build differs from the last, the work an attacker, or an LLM, puts into one release doesn’t carry over to the next. That’s the idea behind Jscrambler’s LLM-Resilient Code Protection.

Bottom line for developers

The browser runtime is an untrusted environment by default. Whether written by hand or autocompleted by an LLM, if a variable, prompt fragment, or endpoint exists in your client-side JavaScript, assume it can be inspected. By keeping backend credentials on the server and applying strong runtime protection to your client-side code, you can build fast, AI-rich web apps without exposing your frontend logic.