You found an OpenAI, Claude, Gemini, or Supabase secret key in a React component, a committed .env file, a GitHub repo, or a VITE_ variable. Taking the line out of the file is not the fix. Treat that value as already in someone else’s hands, revoke it with the service that issued it, and put the replacement only where server-side code can read it.
This guide is the incident order: revoke, limit the damage, replace and redeploy, then decide whether a history rewrite is warranted, and turn on secret scanning and push protection. Related pages: Lovable and Supabase. For a prevention pass, see the pre-launch tests. If Lovable’s Deep scan flagged secrets in source or the repo, do the revoke steps here first, then use the scan findings write-up for the rest of that report.
Treat the key as already compromised
GitHub’s tutorial on remediating a leaked secret tells you to treat a secret that has appeared in a repository as compromised straight away. Taking the string out of the current files, pushing a follow-up commit, or deleting the repository and opening a new one does not stop someone who already copied it. The value can still sit in git history, forks, local clones, and GitHub’s cached views of older commits, as GitHub’s page on removing sensitive data describes.
The first useful action is to revoke or rotate the key with the service that issued it. Cleaning the repo comes after that.
Step 1: Revoke or rotate it with the issuer
Work in the dashboard of the service that issued the key. Follow that provider’s own order: leaving a leaked key active leaves a window for abuse, and deleting it before you have a working replacement will break any feature that still points at the old value.
OpenAI
When a key may be compromised, OpenAI’s account security guidance is: remove the affected key from the API key dashboard, inspect usage for activity you did not perform and keep a record of it, then write to OpenAI Support. OpenAI’s API key safety article also tells you to rotate the key at once from the API Keys page and, for an app already in production, to update the key values your app uses.
Supabase secret or service_role key
A leaked secret key (sb_secret_...) or legacy service_role key skips Row Level Security entirely. Supabase’s guide to rotating a leaked key tells you to fix whatever caused the leak before you issue a replacement, so the new value does not escape the same way. The exception: if the leaked key is already being used against your project, retire it immediately, even though anything still pointing at it will fail until you install a new key.
Then:
- Create a new secret key under Settings → API Keys in the Dashboard.
- Put that new value in every server, Edge Function, cron job, or webhook that used the old one. Edge Functions that use
withSupabase({ auth: 'secret' })only accept the secret nameddefault. Point that option at the new key’s name, such asauth: 'secret:rotated_secret_key'. Webhooks andpg_netcalls that still pass a legacyservice_rolevalue asAuthorization: Bearershould pass the new secret onapikeyinstead. - Confirm every component is on the new key.
- Retire the compromised key: delete a secret key (this cannot be undone), or deactivate the legacy keys if the leak was
anonorservice_role.
When the leaked value is a legacy service_role credential, move browser and mobile clients off the legacy anon key onto a publishable key as well. Deactivating the legacy keys turns both of them off. The rotation guide also tells you to revoke the legacy JWT secret. Legacy anon and service_role values are JWTs signed with that secret, so a caller that still validates against it can accept the leaked key.
A secret key that shows up in frontend code is still a leak. Supabase can reject that key from a browser (HTTP 401), but the same value still works from other tools.
Claude (Anthropic)
Anthropic’s guidance for a compromised key is to revoke it immediately: in the Claude Console, open the API keys page, open the menu beside the key, and choose Delete API key. Create a replacement with Create key, store it in a secrets manager (not in version control), and contact Support if suspicious API activity continues.
Gemini (Google)
Google’s Gemini API key docs give this order: mint a new key in Google AI Studio or the Cloud console, ship the app with that value, and only then disable or remove the leaked one, after you have confirmed the replacement works. Wait until the replacement is live before you delete the previous value. Afterwards, inspect Cloud billing and usage records for traffic you did not make.
Authorization keys, the type Google AI Studio now creates, are documented as having leaked-key enforcement that stops use of keys their systems detect. Still rotate the key yourself. Detection is not something to wait for.
Stripe secret or restricted keys
If a Stripe secret or restricted key (sk_... or rk_...) appeared in your client or repo, Stripe’s guidance on secret keys says to rotate it at once, whether or not you know that someone saw it. Publishable keys (pk_...) are the ones Stripe marks as safe to include in front-end code. For how those keys should be wired in Lovable or Bolt, see the Stripe error checklist.
Lovable’s own API key
Lovable’s Secrets list includes LOVABLE_API_KEY, the credential for built-in AI. That row has a Rotate control (Lovable: Secrets). If you believe this value leaked, use Rotate. Lovable generates a replacement and refreshes the environment your Edge Functions read. That action needs editor access or above. It does not rotate OpenAI, Claude, Gemini, Stripe, or Supabase keys; those still have to be rotated at their own providers.
Step 2: Limit the damage
Revoking stops new use of the old key. It does not undo use that already happened, and it does not cap a replacement key if you put that one in the same unsafe place.
OpenAI. On the Usage page, compare traffic with your own work, including the window when the key was exposed, and keep a record of it. OpenAI’s key safety article and spend limits docs tell you to set monthly spend limits for the organization, or for an individual project, and turn on hard enforcement. Spend alerts notify you but do not stop API traffic. With hard enforcement on, affected requests return a 429, with the code organization_spend_limit_exceeded at org scope or project_spend_limit_exceeded at project scope. The cap does not apply at the exact second it is reached, so tracked spend can go a little past the figure you chose, and a hard limit can also block your own legitimate requests.
Claude. Review the Logs page and the Usage page in the Claude Console, as Anthropic’s key safety article recommends. For organizations on custom rate limits, that article documents spend limits on the Billing page and workspace rate limits, which limit surprise usage if a key leaks. For organizations on standard rate limits, auto-reload limits on the Billing page are the corresponding control; set them with care, because they both keep the API running and cap unexpected high usage.
Gemini. After you rotate the key, inspect Cloud billing and usage records for traffic you did not make, and turn on billing alerts so a later spike is visible (Gemini API keys).
Supabase. Finish the rotation so the compromised key no longer appears under Settings → API Keys. Then review the project for unexpected data changes or traffic in the window after the leak. A retired secret key is the control that stops further access.
Step 3: Put the new key in server-side secrets and redeploy
A new key in the same client file, or in a VITE_ variable, will leak again.
Vite’s env documentation is explicit: any env var whose name begins with VITE_ is written into the browser bundle at build time. Those values must not be secrets. A name without that prefix stays off the client unless you expose it some other way.
In Lovable, store private credentials in Secrets (More → Settings → Secrets). Lovable encrypts them and injects them into Edge Functions at runtime; they are not sent to the browser. Names such as OPENAI_API_KEY and STRIPE_SECRET_KEY belong there. A name that starts with VITE_ is rejected from Secrets; it belongs in .env instead.
Lovable lists the project URL and the publishable key as public VITE_ entries in .env. In a Lovable project you should not add .env to .gitignore, because the preview and published builds need those public VITE_ values. Put only values that are safe to ship in that file.
On Lovable apps created from 13 May 2026 that use TanStack Start, server functions and API routes inside the app can hold private credentials too, not only Edge Functions.
After the new key is in Secrets, or in your host’s server-only environment, move the API call into that server-side code, have the frontend call your function, and republish. Then search the published JavaScript for the old value, and for prefixes such as sk-, sk-ant-, AIza, sb_secret_, sk_live_, and rk_live_, to confirm the leaked string is gone.
Step 4: Decide whether to rewrite git history, then turn on secret scanning and push protection
Revoking is what actually stops the old key. The string can still sit in git history. GitHub’s guide to removing sensitive data says that after you have revoked or rotated the credential, a history rewrite is not always necessary. If you still need the string gone, that process is destructive: commit hashes change, a force-push is required, collaborators’ clones and forks can reintroduce the old history, and diffs on closed pull requests can break.
If you go ahead, GitHub’s documented path is: rewrite a fresh clone with git-filter-repo and the --sensitive-data-removal flag, force-push the rewritten history, ask every collaborator and fork owner to clean their copies (if someone with an old clone later pulls and then pushes, the secret can re-enter the repo), and contact GitHub Support to clear cached views and pull request references. GitHub Support will only help with sensitive data when they determine that rotating the credentials is not enough to mitigate the risk.
Then stop the next commit from landing:
- Secret scanning watches the repository, and also issues, pull requests, discussions, wikis, and gists, for known secret types. It runs automatically and is free for public repositories. For organization-owned private repositories it is part of GitHub Secret Protection, which is offered on Team and Enterprise Cloud plans.
- Push protection rejects a
git pushwhen it spots a recognized secret, so the value never arrives on the remote. Push protection for your personal account is on by default and stops you pushing supported secrets to public repositories. Repository-level push protection is part of GitHub Secret Protection and is off by default.
GitHub also reports some partner-pattern secrets leaked in a public repository to the provider, who may revoke them, and a GitHub personal access token that lands in a public repo is revoked by GitHub automatically. That is not a substitute for revoking the key yourself.
Which keys are meant to be public
| Key | Safe in the frontend? | Why |
|---|---|---|
Supabase publishable key (sb_publishable_...) or legacy anon | Yes, if RLS is on | Supabase intends this credential to ship in a web page or a mobile app. Access is limited to what your policies allow for anon and for authenticated. Turn RLS on for each table and check those policies. A publishable key does not protect against someone copying it from the page source or the Network inspector. |
Stripe publishable key (pk_test_ / pk_live_) | Yes | Stripe marks this type as safe to include in front-end code. It cannot create charges or read account data, which Stripe lists as sensitive operations. |
| OpenAI, Claude, and Gemini API keys | No | Each provider documents these as credentials that can run billable requests on your account. They belong only in server-side code. |
Supabase secret key (sb_secret_...) or legacy service_role | No | It skips RLS entirely, and it has no place in a browser, a shipped app, or source control. The dashboard’s browser block is not enough: the key still works from other tools. |
Stripe secret or restricted key (sk_..., rk_...) and webhook signing secrets | No | Stripe documents these as unsafe to expose. Rotate any of those that showed up in browser code or in a git commit. |
For tests you can run on a bundle you own, including how to tell a publishable Supabase key from a secret one, use the pre-launch tests.
How these keys end up in an AI-built app
Documented paths that put a secret where a visitor or a git clone can read it:
- The key is pasted into a component, or into the project chat and then into frontend code. Lovable’s security overview says it detects API keys pasted into project chat and guides you to store them in Secrets rather than hardcoding them in source. When it recognizes the tool, it also offers to set up a connector. If a key still appears in a component, treat it as compromised. Lovable’s security best practices state that frontend code runs in the user’s browser and can be inspected, and that secrets stored there should be considered compromised.
- A secret is committed in
.envor another config file. GitHub’s secret leakage article lists.envfiles and other configuration files among the ways secrets enter repositories. In a Lovable project the.envfile is supposed to hold only publicVITE_values and should stay in the repository so previews and published builds can read them. A secret does not belong in that file; it belongs in Secrets. - The key is stored in a
VITE_variable. Vite includes those values in the client bundle, so the prefix itself is a signal that the value will be public.
Keep secrets in server-only storage, keep the API calls in Edge Functions or server routes, and use the pre-launch tests before you publish. If Lovable’s Deep scan reports Leaked secrets & credentials, revoke the key first, then go back to the scan findings write-up to clear the finding.
When to get help
Get a human review when the leaked key could reach customer data or payments: a Supabase secret/service_role credential, a Stripe restricted or secret key, or any key that sat in a production client or a public repo long enough that someone could have used it. A senior engineer who has been vetted can review what was exposed and move every remaining secret into server-side storage. Fixed price, agreed upfront.
Related pages: Lovable, Supabase, Bolt, ChatGPT, or something else.
FAQ
I deleted the key from my code. Am I safe?
No. Taking the string out of the current files, pushing another commit, or deleting the repo and starting a new one does not stop someone who already has the value, and it does not erase it from git history. GitHub’s remediation tutorial treats the secret as compromised until you revoke it with the provider. Do that first, then decide whether history also needs to be rewritten.
Does OpenAI disable leaked keys automatically?
OpenAI’s account security article says it disables an API key immediately in two situations it names: the key is found on the public internet, or the key has leaked from inside an application published in an app store. Do not rely on that. A key in a private repo, a preview, a chat log, or a bundle that has not been found may still be active. Delete the key yourself. Anthropic documents a similar partner-program path: when GitHub finds a Claude key in a public repo, it alerts Anthropic, and Anthropic turns that key off. That path is also limited to keys GitHub finds in public repos.
Is the Supabase anon or publishable key safe in the frontend?
Yes. The publishable key (sb_publishable_...) and the legacy anon key are the credentials Supabase designs to appear in a web page or a mobile app. What actually guards the rows is RLS, together with the table grants in front of it. Turn RLS on for each table and check the policies attached to anon and to authenticated. If your app still uses the legacy anon and service_role keys, the legacy API keys migration guide covers swapping them for publishable and secret keys. A service_role or secret key must never go in the frontend.
Can I hide an API key in a React or Vite app?
No, not in the client. Anything you put in frontend code, or in a VITE_ variable, is visible in the shipped JavaScript. Move the call to a server-side function or an Edge Function, and keep the key in Secrets or a host environment variable that never ships to the browser.
How do I check whether someone used my key?
For OpenAI, inspect usage on the Usage page, keep a record of it, and write to Support. For Claude, review the Logs and Usage pages in the Claude Console, and contact Support if suspicious activity continues. For Gemini, inspect Cloud billing and usage records. For Stripe, review API request logs and rotate any exposed secret or restricted key. For a Supabase secret or service_role key, there is no separate “key usage” dashboard in the rotation guide: confirm the compromised key has been retired, and review the project for unexpected data changes or traffic after the leak.
Comments