Guide
OpenAI API key exposed in the frontend: check your own app
Published November 25, 2026 · Guides
Which keys are meant to be public, why a NEXT_PUBLIC_ or VITE_ prefix ships the others, and what to do on your own app if a secret key is in the bundle or the git history.
This guide is for people who built an app with Cursor, Bolt, Lovable, Replit, or v0 and called OpenAI, Anthropic, Stripe, Supabase, or Firebase from that app. It explains which keys those vendors say are safe in a browser, which keys are not, and a check you can run on a project you own. It does not name any app.
Run the checks only on a repository and a deployed site you own or are allowed to administer. Do not point them at someone else's URL, repository, or key. If a search shows a live key, do not paste it into chat, a ticket, or another website.
What shipping a secret key does
A client-side bundle is the JavaScript the browser downloads. Next.js says that to make an environment variable accessible in the browser, it inlines the value at build time into the JavaScript sent to the client, replacing process.env.NEXT_PUBLIC_... with a hard-coded value. After the build, the app no longer responds to changes of those variables. Vite says variables prefixed with VITE_ are exposed in client-side source after bundling, and that the values are bundled into the source at build time. The same page says VITE_* variables should not contain sensitive information such as API keys, and that production secrets belong in a backend server or a serverless or edge function.
OpenAI's API key safety page says never to deploy a key in a browser or a mobile app, because someone can take that key and make requests on your behalf, which may lead to unexpected charges or compromise of certain account data. Requests should go through your own backend. The same page says never to commit the key. Anthropic's authentication page says to call the Claude API from your own backend, not from code that runs in your users' browsers, because anyone who uses a webpage can read an API key in that page's code. Stripe's API keys page says only publishable keys are safe to expose outside the application's backend, and that you are responsible for protecting the other keys, including restricted keys. Supabase's API keys guide says a secret key bypasses every Row Level Security policy and must never go in a browser, a shipped application, or source control.
This guide does not have a count of how often Cursor, Bolt, Lovable, Replit, or v0 emit a secret in client code. No study with a stated method was used for that. The sections below stay with what the vendor docs say.
Which keys are meant to be public
Three of these products publish a key that is supposed to be in the client. The name "API key" is not what makes it public. The vendor page is.
Supabase's API keys guide says a publishable key, sb_publishable_..., is safe to expose in a web page, a mobile or desktop app, a CLI, or source code, because anyone can read it and it only reaches what Row Level Security allows. The legacy anon key is the older form of that. The securing-your-data guide says to treat the anon key like a publishable key: it can identify the project, it is not a secret, and it has to be paired with row level security and least-privilege grants. A secret key, sb_secret_..., and the legacy service_role key are the other pair. They bypass row level security. The Supabase data guide is the check for the publishable key. The service role card is the short version of a secret key in the bundle.
Firebase's API keys page says API keys for Firebase services are public by design. They identify the project and the app. Authorization is handled through Google Cloud IAM, Security Rules, and App Check. If the setup follows that page's guidelines, keys restricted to Firebase services do not need to be treated as secrets, and it is safe to include them in code or configuration files. A web app shows that key in the config object's apiKey field. The same page says the key used for the Gemini Developer API must never be included in code or configuration files, and that a publicly accessible Firebase key must not list the Generative Language API. The Firebase rules guide is the data check. The Gemini key card is the billable-key case. Finding apiKey in the page does not, by itself, mean a secret leaked.
Stripe's keys page says a publishable key, pk_..., is for Stripe.js, Elements, and mobile SDKs. It can identify the account and create tokens or PaymentMethods. It cannot create charges or read account data. You can include it in front-end code or applications you distribute. Sandbox publishable keys start with pk_test_. Live publishable keys start with pk_live_. The page says it is safe to embed the live publishable key in code or apps. A publishable key cannot be expired.
Which keys are secret
Stripe's keys page says a secret key, sk_..., has unrestricted permissions on all Stripe APIs. Sandbox secret keys start with sk_test_. Live secret keys start with sk_live_. Restricted keys start with rk_test_ and rk_live_. An organization key starts with sk_org_.... The page says restricted keys are the ones to use for most server cases, because a secret key cannot have its permissions limited. It also says a fraudulent actor who obtains a secret key can harm the business. Webhook signing secrets are copied from the Webhooks section of the Dashboard and stay on the server. None of those are the publishable key.
Anthropic's authentication page describes an API key as a static sk-ant-api... secret sent as a bearer token. One example on that page is export ANTHROPIC_API_KEY=sk-ant-api03-.... The TypeScript SDK page says browser use is disabled by default. Setting dangerouslyAllowBrowser to true exposes the secret in client-side code. Any user with access to the browser can potentially inspect, extract, and misuse it. That page also names two cases where the risk can be lower: an internal tool whose users are trusted, and a temporary development key that is short-lived, not used in production, or rotated often. The authentication page says a direct browser call is accepted only when the request includes anthropic-dangerous-direct-browser-access: true, which is the header that option sends. Organizations with zero data retention cannot call the API from a browser at all.
OpenAI's incorrect-key page prints an example error that begins Incorrect API key provided: sk-. That is the prefix in the example. The page does not describe every current key shape, so a search for sk- can match an OpenAI key and can also match other strings, including an Anthropic key. The safety page says to store the key in an environment variable named OPENAI_API_KEY. The name is not what keeps it off the client. Next.js and Vite still inline it if the code reads NEXT_PUBLIC_OPENAI_API_KEY or VITE_OPENAI_API_KEY.
Supabase's guide says publishable and secret keys are short strings, not JWTs. If a tool, tutorial, or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys. Both the legacy anon key and the legacy service_role key are JWTs, so eyJ alone does not tell them apart. Compare the value with the keys in your own project's Settings, then API Keys. Do not paste it into a decoder website. Secret keys add a check the old service_role key does not have in that description: a secret key does not work in a browser. Supabase matches on the User-Agent header and returns HTTP 401. The same page says the browser block does not stop someone from using the key in other tools. Creating a publishable or secret key does not revoke the legacy keys. They keep working until you disable them.
# Safe to expose to the browser. Prefix per your framework.
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
# Server-only. Never prefix these, or your bundler will ship the key.
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SECRET_KEY=sb_secret_...Why a generated app still puts the key in the client
The browser can only see a value the bundler is documented to copy in. Next.js copies NEXT_PUBLIC_. Vite copies VITE_. Vite's envPrefix option says variables starting with that prefix are exposed to client source through import.meta.env. The default is VITE_. Setting the prefix to an empty string would expose every variable. Vite throws if it detects that. The same option says an unprefixed variable can still be exposed with define. A chat feature that calls OpenAI, Anthropic, or Stripe directly from the page needs a key in that copied slot, or a key written into the source. That is the path these framework pages describe. It is not a measurement of any coding tool.
Lovable's secrets page separates the two stores. Secrets are encrypted, injected into Edge Functions, and never included in frontend code. OPENAI_API_KEY and STRIPE_SECRET_KEY are the examples it gives for that store. Anything prefixed with VITE_ is a build-time, browser-exposed value and belongs in .env, not in Secrets. The examples of values that are safe to be public are VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY. Lovable rejects a VITE_ name in Secrets. The same page says not to add .env to .gitignore, because Lovable needs that file committed so the public VITE_* values are available for previews and published builds. That warning is about the public values. It is not a reason to commit a secret in the same file.
Lovable's security best practices say all frontend code runs in the user's browser and can be inspected. Secrets stored in frontend code are visible to users and should be considered compromised. The wrong example on that page is a constant API_KEY set to a string beginning sk-, and a constant STRIPE_SECRET set to a string beginning sk_live_. Those are Lovable's placeholders, not a catalog of live keys. The page also says a function running on the server is still callable by a client, so moving the key to an Edge Function does not by itself decide who may call it. If the Security view labels that exposed key Critical and the workspace setting Block publishing with critical issues is on, publish stays blocked until the finding is resolved or ignored. The publish-block guide is that screen. The check of the bundle is still this page.
Bolt's secrets page says secrets are read only by server functions, and that Bolt does not write a secret into project files, into code that runs in the browser, or into the published site. Environment variables are different. Bolt stores them in .env, which is part of the project's code. If the code reads a value from the browser, that value ends up in what is sent to anyone visiting the published site. Editors and co-owners can see the .env file. Bolt says it fills in the web address and the public database key there, and locks those values. The page's examples of secrets are a payment provider's secret key and an email service's API key.
Replit's security checklist says to use Replit Secrets for API keys, and not to pass secrets to client-side JavaScript, local storage, or session storage. The checklist line is "Never expose API keys in frontend." The Secrets tool page says hard-coding a secret can expose it through a public Replit project, a public repository, or a screen share. Configurations are the non-sensitive store. The page says not to store API keys, passwords, or authentication tokens as configurations. Secrets are not available for Static Deployments. The same page says organization members who cannot view a secret value can still access it by printing the environment variables. The checklist is a separate instruction: do not put those values in client-side JavaScript.
This guide did not find a Cursor or v0 page that counts how often a generated app puts a secret behind NEXT_PUBLIC_ or VITE_. If the project is Next.js, the Next.js rule above is the one that applies. If it is Vite, the Vite rule applies. The NEXT_PUBLIC_ card and the VITE_ card are the short versions. The client-component card covers a Client Component that reads a server environment variable.
Check your own app
Use your own repository and your own deployed site. The order is the names in the source, then the built JavaScript, then git history, then GitHub. A match on a publishable key, a Firebase apiKey, or a Stripe pk_ key is not the failure. A match on a secret prefix is.
1. Search the source for names and prefixes
Next.js says non-NEXT_PUBLIC_ variables are only available in the Node.js environment and are not accessible to the browser. The same page says a dynamic lookup is not inlined, such as process.env[varName] or env.NEXT_PUBLIC_... when env is process.env. That exception means the build did not substitute the value. It does not say the value is then a secret. Read the file that uses it. Vite says a variable without the VITE_ prefix is not exposed on import.meta.env. The envPrefix option says a custom prefix exposes the variables that start with it, and that define can expose one variable that has no prefix.
grep -R -n -E 'NEXT_PUBLIC_|VITE_|service_role|sb_secret_|SUPABASE_SERVICE_ROLE|OPENAI_API_KEY|ANTHROPIC_API_KEY|STRIPE_SECRET|sk_live_|sk_test_|rk_live_|rk_test_|sk_org_|sk-ant-api' \
--exclude-dir=node_modules --exclude-dir=.git .Read each hit. NEXT_PUBLIC_ and VITE_ are failures when the value is a secret from the list above. They are expected for a Supabase URL, a publishable key, or a Stripe publishable key. service_role as a variable name is a lead. The text service_role inside a legacy JWT is not guaranteed to appear as those characters, because this guide did not find a Supabase sentence that says the JWT payload is stored in the bundle as plain text. Compare a long eyJ value with your own dashboard instead of decoding it on a website.
2. Search the JavaScript the browser actually loads
The source check misses a value that was inlined and then the name was minified away. Next.js says the public value is inlined into any JavaScript sent to the browser. Vite says the VITE_ value is bundled into the source at build time. On your own deployed site, open DevTools, open Sources, and search the loaded scripts for sk_live_, sk_test_, rk_live_, rk_test_, sk_org_, sk-ant-api, sb_secret_, and service_role. Also search for sk-, and treat a hit as an OpenAI key only when the surrounding code is an OpenAI call. An Anthropic key matches sk- too.
A pk_live_ or pk_test_ hit is the publishable key Stripe says you can embed. An sb_publishable_ hit is the key Supabase says is safe to expose. A Firebase apiKey is the public identifier, unless the Google Cloud credentials page shows the Generative Language API on that key. Do not call the provider with a string you found, to see if it still works. That spends the account's quota if the key is live, and it is not the check.
3. Search git history on your own clone
Deleting the line in the latest commit leaves it in older commits. GitHub's remediation tutorial says to use git log -S to find who committed the secret. Run it in your own clone, for a prefix rather than the whole key, for example git log -S 'sk_live_' --oneline. The patch view of that history can print the value. Do not copy it, and do not add the value to the command, because the command then lands in your shell history.
4. Read GitHub secret scanning, and know what it does not scan
GitHub's secret scanning page says secret scanning scans the entire Git history on all branches for hardcoded credentials, and also scans issues, pull requests, discussions, wikis, and secret gists. On a public repository it runs automatically and is free. The remediation tutorial says secret scanning is free for public repositories and is part of GitHub Secret Protection for private repositories on GitHub Team and GitHub Enterprise Cloud. The scan is of the repository. That page does not say GitHub fetches the JavaScript bundle of a deployed website. A key that was never committed, and exists only in the built file on the host, is not a hit this scan describes.
The supported patterns page lists separate columns for partner, user alert, push protection, and validity check. In the table this guide read, OpenAI API Key (openai_api_key), Anthropic API Key (anthropic_api_key), and Stripe API Key (stripe_api_key) have partner, user alert, push protection, and validity check. Supabase Secret Key (supabase_secret_key) has partner, user alert, and push protection, and does not have a validity check. Stripe Legacy API Key has a partner mark and does not have a user alert or push protection. Stripe Webhook Signing Secret has a user alert and does not have push protection. The page does not print the regular expressions. It also does not list a row named service_role. This guide does not claim a legacy eyJ service_role token matches supabase_secret_key.
Partner alerts go to the provider and are not shown in the repository's Security and quality tab. User alerts are the ones shown on that tab. The patterns page says whether a capability is available also depends on your plan and the repository's settings. Validity checks, where the column says they exist, may contact the issuing service to see if the credential is still active. The remediation tutorial says the secret provider is always the most reliable source of truth for whether a secret is still valid. GitHub's push protection page says push protection for users is on by default on GitHub.com and stops you from pushing secrets to public repositories. It does not generate an alert when you bypass it, unless push protection is also enabled on the repository. Push protection for repositories requires GitHub Secret Protection and is disabled by default. Anyone with write access can bypass it unless you turn on delegated bypass. The patterns page says push protection only supports the most recent token versions secret scanning can identify with confidence, because legacy tokens produce more false positives. A push that succeeds is not proof the file is clean.
If a secret key leaked
GitHub's remediation tutorial says to consider any leaked secret immediately compromised. Removing it from the codebase, pushing a new commit, or deleting and recreating the repository does not prevent the secret from being exploited. The most important step is revoking it with the provider. For a secret that is still active, in a public repository, or a production credential, that page says to revoke immediately. If downtime is the concern, it says you may first generate a new secret, make the application use the new one, and then revoke the old one. The same page says automated scanners can locate publicly exposed secrets in minutes and that they can be exploited within hours. That is GitHub's description of the risk. It is not a count of coding-tool apps.
Do the provider step before a history rewrite. GitHub's removing-sensitive-data page says the first step for a password, token, or credential is to revoke or rotate it. Once it is revoked or rotated, it can no longer be used for access, and that may be sufficient. Rewriting history may not be warranted.
Revoke or rotate at the provider
OpenAI's account security page says that if you think an API key has been compromised, delete it on the API key dashboard, review API usage for unexpected activity, and contact OpenAI Support. The same page says that when OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the key is disabled immediately. That sentence does not say OpenAI scans private repositories, or every deployed site, or that you can leave a key you found yourself. The safety page says a compromised key can use your quota without your consent, and that usage is tracked on the Usage page.
Anthropic's authentication page says to disable or delete any key you suspect has leaked. On the API keys page in the Claude Console, Disable is reversible. Delete is permanent: the key is archived. Set an expiration when you create the replacement if you want a leaked key to stop working on a date. The page says expiration is not a substitute for deleting a key you already suspect.
Stripe's keys page says to rotate a secret or restricted key when it is compromised, so the old key stops accepting requests. Rotating revokes the key and generates a replacement. In the Dashboard the old and new keys both work for up to 7 days, so you can migrate without downtime. Choosing Now deletes the old key. If you need more than 7 days, create a new key, migrate, then expire the old one. Before the old key expires, the page says to check its request logs and expire it only after request volume has been at zero for a few hours or days. The overflow menu on a key has View request logs. The keys page does not describe a spend cap that stops a secret key. A restricted key with only the permissions the server needs is the damage limit that page does describe.
Supabase's rotate-a-leaked-key guide says to fix the cause of the leak before you rotate, or the new key can leak the same way. It also says that if someone is actively using the leaked key, retire it right away, even though components that still use it stop working until you replace it. The dashboard path is Settings, then API Keys: create a new secret key, replace the old value everywhere the server reads it, then delete the secret key or deactivate the legacy keys. If the leaked key is a legacy service_role key, retiring it deactivates both legacy keys, so the browser client has to move to a publishable key first. The leaked JWT was signed by the legacy JWT secret, so the guide says to revoke that secret too, or anything that still trusts it can accept the leaked key. Do not re-enable the legacy keys after that. Re-enabling restores the compromised key. This guide does not repeat the Management API command on that page, because the page says that command prints the new key.
Check usage, then set the limit the vendor actually offers
OpenAI's safety page says to set monthly spend limits for the organization or the project, and to enable hard enforcement. Spend alerts alone do not stop API traffic. Hard enforcement can block legitimate requests, and spend may slightly exceed the limit because enforcement is not instantaneous. The projects page puts the organization control on Limits, under Spend, and the project control on that project's Limits page: Monthly spend limit, an alert threshold, and Enforce a hard limit. The usage page says to review Spend in Analytics for the current project, and Organization analytics for the whole organization. Review the date range before you compare it with anything else.
Anthropic's workspaces page says you can cap monthly spending for a workspace under Spend limits in the Claude Console. A workspace limit can keep that workspace below the organization's limits and cannot raise them. If a workspace limit is not set, it matches the organization's limits. A spend limit on the Default Workspace might not count or stop some usage there, including the Claude Console playground, Claude Managed Agents sessions, and Claude Code or Claude Desktop when a member signs in with a Claude Console account and uses the Default Workspace. The organization's spend limit still applies to that usage. The page points at the Usage and Cost Analytics API for usage and cost by workspace. A separate Spend Limits API sets per-member limits and is available to Claude Enterprise organizations only. It is not the Console workspace control.
A limit does not un-leak a key. OpenAI's safety page still says to rotate a key you believe has leaked. Anthropic's page still says to disable or delete it. Stripe's page still says to rotate a compromised secret or restricted key. The limit is the control those pages describe for the next request, not a replacement for revocation.
Purge history only after the key is dead
GitHub's secret scanning page says that removing a secret from Git history is time-intensive and often unnecessary if you have already revoked the credential. The removing-sensitive-data page says a rewrite uses git-filter-repo with the --sensitive-data-removal flag, which means at least version 2.47. One form deletes a file from history with --invert-paths --path. Another replaces text listed in a file with --replace-text. The page then says to force-push with git push --force --mirror. Follow that page on your own repository. A shortened command is not the whole procedure.
The same page lists what a rewrite does not do. Another developer's clone can push the secret back. Forks keep the commit. Cached views on GitHub can still serve the commit by its hash until you ask GitHub Support, and Support will only help remove sensitive data when rotating the credential is not enough. Commit hashes change, signatures are dropped, and open pull request diffs break. The remediation tutorial puts this cleanup after revocation, after the new secret is in the services, and after you have checked the provider for unauthorized use.
Put the call on the server
The fix the vendor pages describe is the same shape. The browser calls your server. The server reads the secret and calls the provider. Next.js's environment variables page shows a Route Handler reading process.env for values that are not prefixed NEXT_PUBLIC_. Vite's page says production secrets belong in a backend or an edge function. Supabase's guide shows the browser client taking the publishable key from NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, and a server client taking SUPABASE_SECRET_KEY with no public prefix. Lovable reads OPENAI_API_KEY from Secrets inside an Edge Function. Bolt reads a payment secret from Secrets inside a server function. Replit reads an API key from the Secrets tool, which exposes it to the project as an environment variable, and the checklist says that value still must not be passed to client-side JavaScript.
A server route is still a URL. Lovable's best-practices page says server-side execution alone does not make the operation private. The route that spends money or reads private rows has to check the caller. That check is not part of the key prefix. The edge-function auth card is the case where the platform check was turned off.
After the code change, rebuild and repeat the DevTools search. Next.js says NEXT_PUBLIC_ values are frozen at build time, so changing the dashboard without a rebuild leaves the old value in the existing bundle. Vite bundles the VITE_ value at build time for the same reason. Removing the variable from the host does not edit a bundle that was already built.
Paste this into the coding tool
The prompt is for the tool that has your own project open. It tells that tool to stay on this project and not to print a key. You still rotate the key yourself in the vendor dashboard.
In this project only. Do not open any other app, repository, or vendor account. Do not print secret values, tokens, or customer data.
1. List every environment variable whose name starts with NEXT_PUBLIC_ or VITE_, and every hardcoded string that looks like a credential. A public value is one of these, and only when the vendor's docs say so:
- a Supabase publishable key (sb_publishable_) or the legacy anon key
- a Firebase API key that is restricted to Firebase APIs and does not allow the Generative Language API
- a Stripe publishable key (pk_test_ or pk_live_)
Anything else is a secret. That includes OpenAI keys, Anthropic keys (sk-ant-api), Stripe secret keys (sk_test_, sk_live_, sk_org_), Stripe restricted keys (rk_test_, rk_live_), Stripe webhook signing secrets, and Supabase secret keys (sb_secret_) or the legacy service_role key.
2. Remove every secret from client code, from NEXT_PUBLIC_ and VITE_ variables, and from any Vite define or envPrefix that copies it into the bundle. Read secrets only in a Route Handler, other server code that is not sent to the browser, or an edge function, from a variable with no public prefix. The browser calls that route. It does not call the provider with the secret.
3. Leave the public prefix only on values from step 1. For Supabase, the browser client uses the publishable key. The secret key stays on the server. A secret key in the browser is still a leak even though Supabase returns HTTP 401 for a browser User-Agent: other tools can still use it. The legacy service_role key does not have that browser check.
4. Do not commit the secret. Next.js's create-next-app template gitignores .env files. Vite tells you to gitignore *.local files. A Lovable project is the exception documented by Lovable: .env stays committed because VITE_ values are build-time public values, and private keys belong in Lovable Secrets, not in that file. Do not move a secret into a committed .env to satisfy that warning.
5. If a secret was ever in a commit or in a deployed bundle, stop and tell me to rotate it myself in the vendor dashboard before any history rewrite. Do not call the provider to test whether the old key still works. Do not put the new key in the client.
6. After the move, tell me the files you changed. I will rebuild and search the JavaScript myself. Do not print the key to prove it is gone.
Do not edit unrelated files.What a passing check does not mean
No match in the current bundle does not prove an older deploy, an old commit, or a fork is clean. No GitHub alert does not prove the deployed JavaScript is clean, because secret scanning is described as a scan of the repository, not of a website. A push that push protection allowed does not prove a legacy token was checked. OpenAI's sentence about disabling a key found on the public internet does not prove your key was found.
A publishable Supabase key, a Firebase apiKey, and a Stripe pk_ key are supposed to be in the client. They are not a passing grade for the data behind them. Row level security and Firebase Security Rules are the other guides. A server route that holds the secret and does not check the caller is a different hole.
Common questions
Is a NEXT_PUBLIC_ environment variable safe?
Next.js says only variables prefixed with NEXT_PUBLIC_ are inlined into the JavaScript sent to the browser, at build time, as a hard-coded value. A variable without that prefix stays in the Node.js environment. The prefix is safe when the value is one the vendor says to publish: a Supabase publishable or anon key, a Stripe pk_ key, or a Firebase API key restricted to Firebase services. The same prefix is not safe for an OpenAI key, an Anthropic key, a Stripe secret or restricted key, or a Supabase secret or service_role key. OpenAI's advice to use an environment variable named OPENAI_API_KEY does not keep the value off the client if the code reads NEXT_PUBLIC_OPENAI_API_KEY. A dynamic lookup such as process.env[varName] is not inlined. That is not the same as the value being secret.
Are Vite environment variables exposed?
Vite says variables prefixed with VITE_ are exposed in client source after bundling, and that those values are bundled in at build time. VITE_* variables should not contain API keys. A variable without that prefix is not exposed on import.meta.env. The envPrefix option exposes whatever prefix you set, and an empty prefix is rejected because it would expose every variable. The same option says define can still expose one unprefixed variable. Lovable uses this split: VITE_ values are browser-exposed and live in .env, and OPENAI_API_KEY is a backend secret.
Is a Supabase service role key leaked if it is in the browser?
Supabase says the secret key and the legacy service_role key bypass Row Level Security and must never go in a browser, a shipped app, or source control. The publishable key and the legacy anon key are the ones that are safe to expose, and only together with row level security. A current secret key does not work in a browser: Supabase matches the User-Agent and returns HTTP 401. The same page says other tools can still use that key. The legacy service_role key is the older JWT, and the browser check is described as something the newer secret key adds. Both legacy keys are long JWTs beginning with eyJ, so that prefix alone does not tell them apart. Compare the value with your own project's API keys page, and do not paste it into a website.
How do I check if my API key is exposed?
On a project you own, search the source for NEXT_PUBLIC_, VITE_, service_role, sb_secret_, sk_live_, sk_test_, rk_live_, rk_test_, sk_org_, and sk-ant-api. Then open your own deployed site, and in DevTools Sources search the loaded scripts for the same prefixes. Also search sk-, and treat it as an OpenAI key only when the surrounding code is an OpenAI call, because Anthropic keys start with sk-ant-api and OpenAI's own error example starts with sk-. Then run git log -S on your own clone for a prefix, not the whole key. On GitHub, secret scanning reads the repository history. It is not described as a scan of a deployed website. A pk_ key, an sb_publishable_ key, and a Firebase apiKey are supposed to be in the client. Do not call the provider with a string you found.
I found a key in the bundle or in git history. What do I do first?
GitHub says to treat a leaked secret as compromised, and that deleting it from the latest commit does not stop it being used. Revoke or rotate it with the provider first. If you need the app to stay up, GitHub says you may create the replacement, point the app at it, and then revoke the old key. Supabase adds that you should fix the leak path before you rotate, unless someone is already using the key, in which case you retire it immediately. Then review that provider's usage or request logs. Rewriting git history comes after the key is dead, and GitHub says it may not be warranted once the key is revoked. A rewrite does not clear forks or other people's clones.
Does GitHub secret scanning see a key that is only in the deployed JavaScript?
GitHub says secret scanning scans the Git history on all branches, plus issues, pull requests, discussions, wikis, and secret gists. On a public repository that scan runs automatically and is free. The page does not say GitHub downloads a deployed site's JavaScript. A key that was never committed, and exists only in the built bundle, is outside that description. Push protection for users is on by default and blocks pushes of supported secrets to public repositories. It can be bypassed, and it only covers the latest token versions GitHub is confident about. A push that succeeds is not proof the file is clean. Partner alerts go to the provider and are not shown on the repository's Security and quality tab.
The daily card
One break a day: the symptom, the cause, a prompt for your own project, and a short check. The address is not on the list until you confirm it.
Sources
- OpenAI: Best practices for API key safety
- OpenAI: Keeping your OpenAI account secure
- OpenAI: Incorrect API key provided
- OpenAI: Managing projects in the API platform
- OpenAI: Reviewing API usage and costs
- Anthropic: Authentication
- Anthropic: TypeScript SDK (browser usage)
- Anthropic: Workspaces
- Anthropic: Spend Limits API
- Stripe: API keys
- Supabase: API keys
- Supabase: Securing your data
- Supabase: Rotate a leaked API key
- Firebase: Learn about and manage API keys
- Next.js: Environment variables
- Vite: Env Variables and Modes
- Vite: envPrefix
- Lovable: Secrets
- Lovable: Security best practices
- Bolt: Secrets
- Replit: Security checklist
- Replit: Secrets
- GitHub: Secret scanning
- GitHub: Supported secret scanning patterns
- GitHub: Push protection
- GitHub: Remediating a leaked secret
- GitHub: Removing sensitive data from a repository
Related cards
- The service role key is in the browser bundle
- A VITE_ variable bundles a secret into the client
- NEXT_PUBLIC_ inlines a secret at build time
- A Client Component reads a server environment variable
- A Gemini key ships in the browser bundle and someone else runs up the bill
- An Edge Function turns auth off and never checks the caller