The security gap in AI-generated code

AI coding tools have fundamentally changed how software gets built. What once took weeks can now be prototyped in seconds. But this speed comes with a hidden cost: the faster code is generated, the more risk is created. A recent viral app leaked 72,000 selfies and government IDs — not through sophisticated malware, but through a misconfigured Firebase bucket left publicly accessible. The code was generated, shipped, and scaled before anyone reviewed the security posture.

These incidents are not outliers. They are the predictable result of generating code optimized to run, not to be secure. When models train on public code — much of which contains outdated patterns or unsafe defaults — they reproduce those flaws at scale. Leaked secrets, exposed variables, and permissive access controls become the baseline unless something actively prevents them.

Common failure patterns in AI output

LLMs are remarkably consistent in the types of vulnerabilities they introduce. The most frequent issues include:

  • Public variable misuse: In Next.js, any environment variable prefixed with NEXT_PUBLIC_ is exposed to the browser. AI models regularly place database credentials and API keys in these variables, making them visible to anyone who inspects page source. In the past 30 days alone, over 17,000 deployments on Vercel were blocked due to exposed secrets.

  • Hardcoded secrets in source files: Credentials embedded directly in code are scraped by bots within minutes of deployment. Common leaks include Google Maps, reCAPTCHA, EmailJS, and PostHog keys. More than a thousand developers nearly exposed their Supabase backend credentials, while a similar number were ready to share keys for OpenAI, Gemini, Claude, and xAI — an easy vector for running up AI utilization costs.

  • Missing input sanitization: Unsanitized user input passed into model prompts opens the door for prompt injection attacks.

  • No environment separation: Generated code rarely distinguishes between dev and production environments, leading to misconfigured services and accidental access leaks.

  • Sensitive data in logs: Debug logs frequently include auth tokens, user IDs, and API keys without redaction or retention policies.

These are beginner mistakes, not advanced attack vectors — yet they are generated daily by tools trained on insecure code. Better prompting alone won't solve the problem.

When autonomous agents go wrong

A recent incident illustrates what happens when AI operates without clear boundaries. An AI agent, instructed not to make changes without permission, deleted an application's entire production database. It fabricated confirmation messages claiming success until the issue was discovered. This wasn't a malicious actor; it was an overly confident model without sufficient guardrails. Incidents like this are becoming more common as teams connect autonomous agents directly to production systems.

Security reviews are falling behind the volume of AI-generated code. The solution lies not in reviewing every line, but in building security checks into the tools that generate and deploy code — so safe defaults are applied automatically.

v0's approach: security at generation time

v0 takes a different approach by applying security checks both during code generation and before deployment. The platform is trained on modern best practices for frameworks like Next.js and applies automated, context-aware validation across every project. The system flags issues including:

  • Secrets exposed in client-side code or public repositories

  • Misuse of NEXT_PUBLIC_ variables that leak production credentials

  • Tokens or session data written to logs

  • Prompt injection risks from unsanitized user input

  • Misconfigured third-party API integrations

  • Unsafe defaults for authentication, routing, and database access

The results are measurable: over 100,000 insecure deployments have been blocked since launch, with more than 17,000 blocked in July alone. The most common issues are exposed API keys, NEXT_PUBLIC_ misuse, and unauthenticated API routes.

Defense in depth from prompt to production

Since v0 apps deploy on Vercel, they benefit from platform-level controls that enforce security at each layer of the deployment pipeline.

Deployment controls

  • Preview protection: Preview deployments can be locked down with password or SSO authentication

  • Opt-in sharing: Preview links remain private unless explicitly made public

  • Environment safeguards: Deployments from forks that modify environment variables are blocked without approval

  • Deploy blocks: Security vulnerabilities are flagged and require review before shipping

  • Access control: Role-based permissions define who can view, edit, and deploy

  • Audit logging: All deployments and environment changes are recorded and reviewable

These measures catch risky changes before they reach production, without requiring developers to manually review every configuration.

Secure model access

Inference calls in v0 apps are routed through Vercel AI Gateway, which centralizes authentication and prevents credentials from being exposed client-side. Provider tokens are stored securely server-side, with short-lived OIDC tokens scoped per project. Built-in rate limiting and observability prevent overuse and abuse, ensuring model access doesn't become an attack surface.

Platform-level protections

  • DDoS and firewall defense: The Vercel Firewall blocks over 4.4 billion malicious requests per month

  • Isolated function execution: Each function runs in its own secure container with controlled network access

  • Environment encryption: AES-256 encryption with a secure vault system protects stored credentials

  • Compliance: SOC 2 Type 2, ISO 27001:2022, GDPR, PCI DSS, and HIPAA certifications

Making security the default

Speed is no longer the bottleneck in software development. Security is. As thousands of apps ship each week with avoidable vulnerabilities, the question is whether the tools that accelerate development can also enforce safe practices.

Secure code generation and automatic guardrails mean developers — whether they're vibe coding a prototype or rushing toward a deadline — receive the same security analysis that would come from the most experienced engineers. With security baked into generation and deployment rather than treated as a separate review step, the future of AI-assisted development doesn't require choosing between speed and safety. The defaults, the checks, and the platform protections are all designed to make the secure path the path of least resistance.