OpenAI or Anthropic API key exposed in the browser
An AI client created with dangerouslyAllowBrowser, or a key behind a VITE_ or NEXT_PUBLIC_ prefix, puts your API key in the page, where anyone can copy it and spend on your account. What you see The OpenAI or Anthropic client is created in a component, with dangerouslyAllowBrowser: true , or the key is read from VITE_OPENAI_API_KEY or NEXT_PUBLIC_… . Why it happens Anything the browser runs,…
An AI application was discovered to have inadvertently exposed its API key in the browser. This occurred when the application was created using dangerouslyAllowBrowser: true, or when the key was stored with a prefix such as VITE_ or NEXT_PUBLIC_. Once the browser runs the application, anyone viewing the page can easily copy the API key and use it to make unauthorized requests, potentially incurring costs on the original account.
The issue arises because any code executed by the browser is accessible to all visitors. Since the key has public prefixes, it becomes bundled within the JavaScript that everyone downloads. To rectify this situation, the API key should be immediately revoked from the provider's dashboard, as it has already been distributed.
A recommended solution is to retrieve the AI key from a server-side route that has been configured with a new key lacking the public prefix. The browser should then make calls to this server route. Additionally, implementing a per-user rate limit can help prevent abuse. Alternatively, the application developer could request the AI tool itself to address the issue.
This vulnerability was discovered by Launchpad, a free launch check service offered by Axonscape. Launchpad reviews applications built with AI tools, identifying potential launch issues from a public GitHub repository or a .zip file containing the code, while ensuring no sensitive data is shared. The complete page, including a ready-to-copy request, can be found at launchpad.axonscape.com/fix/ai-api-key-exposed-in-browser.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.