Security post-mortem & suggestion: agent embedded an API key in the frontend (Vite `define`) without warning

TL;DR: I had explicitly configured the agent as a security guardrail, yet it silently generated a frontend-exposed Gemini API key (Vite define) with no warning. The key was scraped and abused → ~USD 6,700 in unauthorized charges. Posting as a post-mortem + preventive suggestions.

:puzzle_piece: The setup

While building CortexScope (a medical app), I explicitly configured Antigravity as my technical translator and security guardrail — I’m a physician and product manager, not a professional developer. The agent confirmed in writing that it had assimilated directives to:

  • :white_check_mark: Flag unsafe practices
  • :white_check_mark: Propose safer alternatives
  • :white_check_mark: Avoid “blind obedience”
  • :white_check_mark: Never close a task without real QA

:warning: What happened

Despite those directives, the workflow produced a config that exposed a Gemini API key in the frontend, baking it into the public Vite bundle — with no warning about the security or billing risk:

// vite.config.ts — representative of the exposed pattern
define: {
  'process.env.GEMINI_API_KEY': JSON.stringify(process.env.GEMINI_API_KEY)
}

The key shipped in publicly readable client code, was later exploited, and generated ~USD 6,700 in unauthorized charges. :money_with_wings:

:bullseye: Why I’m posting this — not assigning blame

I executed and deployed the system, and I own that part. I’m sharing it as a post-mortem + preventive-improvement suggestion, especially for non-technical users who rely on the agent as a guardrail.

:shield: Suggestions

  1. :magnifying_glass_tilted_left: Client-side secret detection — auto-scan for credentials embedded in the bundle (keys via define, client-unsafe vars, secrets in config), with a hard stop when the agent operates under a stated security directive.
  2. :construction: Risk-proportional warnings whenever deployment configs that can expose credentials are generated.
  3. :fire_extinguisher: “Blast-radius” mitigation for beginners — proactively suggest moving the key to a backend/proxy, restricting the API key, and setting billing caps + alerts, so a leak can’t bankrupt someone.

:paperclip: Documentation

Happy to share the incident docs (including the governance-prompt logs where the agent assimilates the security directive) if useful — compromised key already revoked, no patient data included. :folded_hands: