Here is an uncomfortable fact. When security researchers at a company called Escape scanned more than 5,600 public apps built with AI app builders, they found more than 2,000 vulnerabilities, more than 400 exposed secret keys, and 175 cases of exposed personal data, including medical records and bank account numbers. Every one of them was in a live app that real people were using.
AI writes code that works. Working and safe are not the same thing. AI will happily build a feature that does exactly what you asked, and also lets a stranger read your customers' data. It will not mention it, because you did not ask.
I am not a programmer, and we fell into several of these holes ourselves while building KashBoss. This article teaches the general lessons, using only problems we found and closed.
The short answer
AI-generated apps are often insecure because security is rarely part of the request. To protect one, make sure every request answers three questions on the server: who are you, which company do you belong to, and what are you allowed to do. Put every rule in the database, make every check fail closed (missing means "no"), and prove it by attacking your own app with tests that undo themselves.
The idea: three questions and an apartment building
Every request must answer, in this order: who are you (login), which company do you belong to (separation between customers), and what are you allowed to do (permissions).
Think of an apartment building: the lobby door is login, each apartment's lock is the company, and locked rooms inside are permissions. Most holes are a door with no lock, or a sign saying "private", which is not a lock at all.
Fact one: your app is in the user's hands. The web version's code can be read by anyone, and the key it uses to talk to the database ships inside the app. Anyone who has it can talk to your database directly, without your screens. So hiding a button protects nothing. Every rule must live in the database.
Fact two: some database functions run with the owner's powers. On Supabase the app can call functions inside the database by name (called RPCs). A function marked "security definer" skips the row rules that protect your tables. Such a function must check by itself who is calling and which company they belong to, because nothing else will.
One principle runs through everything: fail closed. When anything is missing, unknown or unexpected, the answer is "no".
Hole 1: one company can see another
In a SaaS, many companies share one database. If one table forgets to check which company a row belongs to, a customer can open another customer's invoices. Separation is a rule you must state every time.
The fix: every table with customer data gets a company column and a database rule (Row Level Security) that lets a user touch only rows of their own company. Then a test proves it.
In our September 2026 audit we logged in as real users of different companies and confirmed none could read another company's rows. The tables were sound.
Hole 2: functions anyone on the internet can call
On Supabase, every new database function can be called with the public key by default, even by someone who never logged in. We thought "only for logged-in users" made it safe. It did not: that adds a door for logged-in users, it does not close the public one. Removing the permission from the anonymous role alone removes nothing, because the default goes to "everyone". We found that by re-checking after a fix.
AI never notices, because the function works perfectly when you are logged in to test it. We asked for an audit of the live database, not of our files. It found functions that ran with owner powers and contained no check of the caller at all. We wrote one small guard, "is the caller a member of this company?", put it at the top of the functions that needed it, and closed the rest to the app entirely.
Hole 3: the guard that opened the door
We had a check that said: allow if owner, or manager, or an accountant with the "employees" permission. For an accountant who had that permission unset, the database did not read it as "no". It read it as "unknown", and an unknown result made the whole check quietly step aside.
Databases have three answers, not two: yes, no and unknown. A missing value compared with anything gives "unknown". The line that says "if not allowed, refuse" acts only when "not allowed" is clearly true, so unknown slips through. Missing permissions are not rare. They are the normal state of any permission you add later, because existing employees do not have it yet.
The code passed review, and the door was open. We caught it by testing like an attacker, not by reading code. We pretended to be an accountant with no permissions, tried every action, and the test undid itself at the end so no real data changed. The first line of the results said the accountant had succeeded. Only the attempt showed the truth. The fix: read each permission with a default of "no", and ask "is this definitely allowed?" instead of "is this not refused?"
Hole 4: a lock that existed only on the screen
Owners could switch off "give discounts" for a sales rep. The switch hid the discount box in the app, but the server never checked it. We later found discounted invoices from reps whose switch was off. The AI had done what was asked: add a setting and hide the button.
A switch that does nothing is bad. One that tells the owner something is blocked when it is not is worse, because he stops watching. Every permission must be enforced inside the function that saves the data, and in every version of that function, because people on an old version of the app still call the old one.
The other three, briefly
- Hole 5, the employee who could unlock himself. Two correct features, "managers can edit employees" and "employees can be restricted", together let a restricted person lift his own restriction. Block every such path in the database.
- Hole 6, trusting IDs from the app. If the app sends product IDs, check each one belongs to the caller's company. Any ID that names a person must equal the logged-in user.
- Hole 7, secret keys in the wrong place. Public keys are meant to be seen, and are safe only because of the rules above. Secret keys live only on the server. Deleting a key from your code does not delete it from your project's history, so if one was ever uploaded, replace it.
Make it a routine
Security is never finished. Every few weeks we run a full audit with several AI agents, each attacking from a different angle, then fix what they find. Test as a real logged-in user, not only as a stranger, and verify every finding. Chapter 22 of the book walks through all seven holes with the full prompts.
Key takeaways
- Working and safe are different. AI builds what you ask for, and security is rarely in the request.
- Every rule must live in the database. Hiding a button is a sign on a door, not a lock.
- Functions that run with owner powers must check the caller themselves, and public access must be removed on purpose.
- Fail closed: missing, unknown or foreign means "no". Test the missing case explicitly.
- Prove security by attacking your own system with tests that undo themselves, then verify each finding before you act.
Frequently asked questions
Is an app built with AI safe to launch?
Not by default. AI builds the feature you describe and usually skips protections you did not mention. Before launching, ask it to prove that one company cannot see another's data, that no function can be called without a login unless meant to be public, and that every permission is enforced on the server.
What is Row Level Security in Supabase?
It is a database rule that decides which rows a user may read or change. For a multi-company SaaS, the usual rule is that a user can only touch rows whose company matches their own. It works at the database level, so it holds even if someone bypasses your screens.
How can I test security if I cannot read code?
Ask the AI to act as an attacker: a logged-out stranger, a user from another company, and an employee with no permissions. Have it try real actions inside a transaction that is canceled at the end, so no data changes, and ask it to show you which attempts succeeded.