VBS-2026-0005CRITICALCVSS 8.6CWE-798

OpenAI / Anthropic API key hardcoded in Next.js client component

AI-generated code frequently calls the OpenAI or Anthropic API directly from client-side React components or includes the key in NEXT_PUBLIC_ env variables. This exposes the key to all users, enabling API abuse, cost manipulation, and data extraction from the LLM context.

Published
2026-02-01
Discovered By
PolyDefender Research
CVSS Score
8.6 / 10
Affected AI Platforms
LovableBolt.newChatGPTGitHub Copilot
Affected Tech Stack
Next.jsReactViteCreate React App
Proof of Conceptpoc.ts
// app/chat/page.tsx (client component - bundles to browser):
export const openai = new OpenAI({
  apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY,  // ← exposed
  dangerouslyAllowBrowser: true,                    // ← AI added this flag
})
Remediation

All LLM API calls must go through a server-side API route. Remove NEXT_PUBLIC_ prefix from AI keys. Delete dangerouslyAllowBrowser: true.

#credentials#openai#anthropic#next.js#ai-generated
Check if your app is vulnerable to VBS-2026-0005

PolyDefender detects this and dozens of other AI-specific vulnerability patterns.

FAQ
Q

How do I check if my Next.js + React app is affected by openAI / Anthropic API key hardcoded in Next.js client component?

A

AI-generated code frequently calls the OpenAI or Anthropic API directly from client-side React components or includes the key in NEXT_PUBLIC_ env variables. Search your codebase for Next.js, React, Vite, Create React App patterns and verify the remediation has been applied.

Q

Why does Lovable and Bolt.new generate code with CWE-798 (critical severity)?

A

AI-generated code frequently calls the OpenAI or Anthropic API directly from client-side React components or includes the key in NEXT_PUBLIC_ env variables. This exposes the key to all users, enabling API abuse, cost manipulation, and data extraction from the LLM context.

Q

How do I fix openAI / Anthropic API key hardcoded in Next.js client component?

A

All LLM API calls must go through a server-side API route. Remove NEXT_PUBLIC_ prefix from AI keys. Delete dangerouslyAllowBrowser: true.

Q

What can an attacker do if my app contains VBS-2026-0005?

A

With CVSS 8.6 (critical), this vulnerability is high risk — significant data or functionality can be compromised. This exposes the key to all users, enabling API abuse, cost manipulation, and data extraction from the LLM context..