An OpenAI API key is exposed in my app. How do I fix it?
Short answer: revoke the key in the OpenAI platform, review usage, and move provider calls behind an authenticated server endpoint. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.
What the exposed OpenAI API key check covers
An OpenAI API key in a public bundle can be copied and used independently of your app. The provider bills the organization or project associated with the key, subject to its current limits and permissions.
The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.
A public or redacted match is evidence to investigate, not proof of unauthorized usage. Check the exact key class without copying it into a ticket, and treat a confirmed secret as compromised.
Understand the evidence before changing code
Revoke the exposed key in the OpenAI platform, then review project usage, alerts, and available audit details from the time it first shipped. Set reasonable budgets and separate keys by environment.
Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.
Apply the narrow, safe change
Create a replacement in a server-side secret store and call OpenAI from backend code. Authenticate the caller, validate and bound the request, and apply rate limits so the endpoint cannot become an unrestricted proxy.
const key = process.env.OPENAI_API_KEY;
if (!key) throw new Error("OPENAI_API_KEY is not configured");
// Authenticate the caller, validate input, then call the provider.Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.
Verify the production result
Redeploy the app and search the served production assets for the old key pattern. Verify the new server route works for authorized users and refuses unauthenticated or oversized requests.
Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.
Keep the issue from returning
Use one key per service, restrict access to people and processes that need it, and add a CI check for provider key patterns in build output. Rotate promptly if the key appeared in public output.
Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.
Limits and next steps
A scanner cannot determine whether a key was used or recover charges. Review provider usage and contact provider support if the account shows activity you cannot explain.
Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.
A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.
Key facts
- A browser-delivered key can be used outside the application.
- Revocation prevents future calls but cannot reverse prior usage.
- A protected proxy needs authentication and rate limiting.
Questions
Can a clean exposed OpenAI API key check prove the app is secure?
What should I do first if the finding is real?
Does ProofForge change application data?
What should I do after the repair?
Official documentation referenced
Related
Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown