Almost every app built with an AI builder uses keys. A key is a long password your app uses to prove who it is to another service. It looks like a long random string, and the builder often asks you to paste it somewhere. The most useful single rule in app security is knowing which keys may be public and which may not. This post gives you the rule, with examples from the services founders use most.
The rule
A public key is made to be seen by everyone, and it is limited by other rules. A secret key is a master password for your account on that service. Public keys can sit in code that runs in the browser, which is the program people use to open websites, such as Chrome or Safari. In other words, they can sit in the part of your app that every visitor downloads, where they can look at it. Secret keys cannot, because anyone using the browser can read everything in it.
Supabase
Supabase is a service that keeps your app's data in a database. Its documentation lists a publishable key (the newer form of the anon key) which it says is designed to be exposed in web pages and mobile apps because Row Level Security limits what it can reach. Row Level Security, or RLS, is the database's own set of rules about who may read or change each record. The documentation also lists a secret key (the newer form of service_role) with elevated privileges that bypasses RLS. That key belongs only in backend code you control, which is the part of your app that runs on the service's computers, where visitors cannot look. Its variable (the named setting that holds it) must not carry the NEXT_PUBLIC_ prefix, because that prefix copies a setting into the code every visitor downloads. Supabase also says that if a secret key leaks, you should rotate it once the cause is fixed. To rotate is to make a new key and turn the old one off. It suggests using a separate secret key for each backend component so one leak means replacing one key.
Stripe
Stripe takes payments for your app. Its documentation says publishable keys (pk_) are safe to include in front-end code, the part visitors download. Secret keys (sk_) have unrestricted permissions on all Stripe APIs and must not be exposed. (An API is an address that programs call to get or change data.) Stripe recommends restricted keys (rk_) for server-side code, since they let you limit the damage if one leaks. A restricted key can do only the jobs you allow. Webhook signing secrets are not API keys, but they are secret too. A webhook is a message Stripe sends to your app, and the signing secret proves the message really came from Stripe.
AI providers and email services
Keys for AI models, email senders and SMS services are almost always secret keys. If the key can spend money or send messages as you, it is secret. If the browser calls these services directly with your key, anyone who opens your page can copy it and use it on your bill.
How the prefix decides
In Next.js, a popular tool for building websites, variables starting with NEXT_PUBLIC_ are built into the browser code. In Vite, another tool that builds apps (used by Lovable and Bolt), the prefix is VITE_. The Vite documentation says such variables should not contain sensitive information such as API keys. A secret key with either prefix has been published.
The reverse is also worth knowing. If a key is public by design, such as a Stripe publishable key, putting it behind a prefix is correct, and hiding it on a server would only break your checkout page. The goal is not to hide everything; it is to put each key where its own documentation says it belongs.
A quick test for any key
- Ask the service's documentation: is this key safe to expose in a browser?
- If the docs do not say it is safe, treat it as secret.
- Search your published page source for the first few characters of the key.
- Confirm .env files are not in your repository. A .env file is a settings file where an app keeps its keys, and a repository is the folder that holds your app's code and its history.
What a public key still needs
A public key is safe only because something else limits it. For Supabase, that something is your Row Level Security rules. For Stripe, it is the fact that a publishable key cannot create charges or read account data. If your rules are missing, a public key can reach more than you meant. That is why checking the rules matters as much as checking the keys.
Three short examples
Example one: a founder pastes a Stripe key starting sk_live into a Vite variable named VITE_STRIPE_KEY so the checkout button works. The key is now in every visitor's browser. The fix is a server-side function, a small piece of code that runs where visitors cannot look. It creates the checkout session, with the key stored as a server secret.
Example two: a founder puts a Supabase publishable key in the front end and turns RLS on for every table. That is the intended design.
Example three: a founder gives a Supabase secret key to the front end so a stubborn page will load data. It loads, because the key skips every rule, and so it will for everyone. The right fix is a correct policy (one database rule), not a stronger key.
Why the difference exists
Services separate these keys because a browser must be able to talk to them without handing over the keys to the kingdom. The public key lets the page say "this is app X". The service then applies the rules you configured, such as your database policies, to decide what that visitor can do. The secret key skips the visitor-level rules because a trusted server uses it for admin work. Keeping the two apart is what makes the whole design hold together.
When an AI builder mixes them up, the app usually still works, which is exactly why the mistake survives until someone else finds it.
What to do about a key that is in the wrong place
Create a replacement, move the call that uses it to server-side code, and turn the old key off. GitHub's documentation says to rotate affected credentials immediately; it also notes that scrubbing Git history (the saved record of every change to your code) is slow and often unnecessary once the credential has been revoked.
Nordik App Audit is an AI-performed audit of your app's code. It explains what it found in plain words and gives you a fix instruction for each finding. It is not a pentest (a test that tries to break into the running app), and like any review it can miss things. It supports every platform: any app can order, whatever it is built with. The current price and terms are on the Nordik home page. Misplaced keys are one of the first things it checks. The free scan accepts apps from any platform and points you at where to look first. It is a starting point, not a verdict.