We UC
Back to blog
·6 min read·We UC Team

Which API keys in my AI-built app are safe to be public, and which must stay secret?

A Supabase publishable key and a Stripe publishable key can sit in your app's front end. A Supabase secret key and a Stripe secret key can't. Here is how to tell them apart and what to do if one has leaked.

Which API keys in my AI-built app are safe to be public, and which must stay secret?

The key that is safe to be public is the one the provider calls "publishable". Supabase's publishable key (the older one is called anon) and Stripe's publishable key (it starts pk_) are meant to sit in the code your visitors' browsers download. The keys that must stay on a server are Supabase's secret key (older name service_role) and Stripe's secret and restricted keys (sk_ and rk_). If one of those has ever appeared in a browser, a chat or a repository, replace it.

How do I tell a public key from a secret one?

Read the name the provider gives it, because the names are the safety label. A publishable key identifies your project and can only do what the rules on your data allow. A secret key acts as you, with the rights of the account owner or close to them. AI coding tools sometimes paste whichever key makes the error go away, so it is worth checking by name rather than assuming.

ServiceSafe in the browserKeep on the server
SupabasePublishable key (older name: anon)Secret key (older name: service_role)
StripePublishable key, starts pk_test_ or pk_live_Secret key sk_, restricted key rk_
Stripe webhooksNothingThe webhook signing secret, which is a separate thing from the API keys

Why is the Supabase publishable key fine to expose?

It is fine because it opens only what your row-level security rules allow. Supabase's API keys documentation says the publishable key is "safe to expose online: web page, mobile or desktop app, GitHub actions, CLIs, source code", and that anyone can read it, so it only reaches what Row Level Security allows. Row-level security is the per-row rule that says which customer can see which record.

That makes the key only as safe as those rules. If a table has no rules, the public key opens it. Our piece on whether a vibe-coded app is secure covers how to ask for the rules to be checked.

What can someone do with a Supabase secret key?

They can read and change everything in the project's data, because the key skips the rules. The same documentation says a secret key provides "full access to your project's data, bypassing Row Level Security", and that you should never put one in a browser, a shipped application or source control. It also says a secret key doesn't work in a browser at all, so if one is sitting in front-end code, it was either put there by mistake or it is leaking.

One date worth knowing: Supabase says it is deprecating the anon and service_role keys in early 2027, in favour of the publishable and secret keys. An app that still uses the old names will need the new ones, and that is a reasonable moment to check where each is kept.

And on Stripe?

Stripe's publishable key can go in front-end code, and nothing else can. Stripe's API keys guide says a publishable key "can't perform sensitive operations such as creating charges or reading account data", and that only publishable keys are safe to expose outside your application's back end. A secret key has unrestricted permissions on all of Stripe's APIs, and Stripe recommends restricted keys, which carry only the permissions you grant, for server code.

Stripe keeps the webhook signing secret separate from the API keys. It is the value your server uses to check that a payment message really came from Stripe, so it follows the same rule: server only.

Where should the secret ones live?

In your host's secret settings, or in environment variables on the server, and not in the code. Stripe's guide says to store sensitive keys in a secrets vault provided by your hosting platform, to use environment variables if you can't, and not to put keys in source code or configuration files checked into version control. It also says not to share them over email or chat.

A key committed to a repository stays in the history even after the file is changed, so removing it from the current code doesn't make it private again.

What do I do if a secret key has leaked?

Replace it first and investigate second. GitHub's secret scanning documentation says that when you receive an alert you should rotate the affected credential immediately, and that scrubbing it from Git history is slow and often unnecessary once the credential is revoked. Supabase's guidance is to rotate a leaked key as soon as you fix the cause of the leak, because an attacker can still use the key from other tools until you do.

On Stripe, rotating a key in the Dashboard revokes it and creates a replacement, and both keys keep working for up to 7 days if you choose a grace period, so the app doesn't go down while the new key is added. Stripe's request logs for each key let you see what the old one was used for. If customer data was reachable, our piece on what to do after an AI-built app leaks data covers the next steps.

Common questions

Is a key in my Lovable or Bolt project always a problem?

No. A publishable key in the front end is normal. The question is which kind each key is, so list them and check the names against the table above.

Can I just ask the AI tool to hide my keys?

You can ask, and it is worth asking, but check the result: open the live site, view the page source or the browser's network tab, and look for the secret key names above. Someone should confirm it, because a tool that moved a key into a settings file may still have left a copy in the history.

Does GitHub warn me about a leaked key?

For public repositories, secret scanning runs automatically and for free. For private repositories owned by an organisation it needs GitHub Secret Protection, which is a paid feature on GitHub Team or Enterprise Cloud, so check your plan rather than assuming you'd be warned.

Is this something a Rescue audit covers?

Yes. Where keys are kept is part of the security review, which sits alongside data, hosting, code, payments and integrations. We need read access to the code and hosting, nothing is changed during the audit, and the report is yours either way.

Where do I start?

Make a list of every key your app uses and where each one is stored. If you'd like us to check it, the Rescue audit is a fixed £2,500 + VAT, deducted from the first phase if you go ahead with us on the fix. Or tell us about the app and we'll say whether an audit is the right first step.