85 security fixes in Lovable apps: what was actually wrong
When Lovable's agent fixes a security problem in an app, the fix is a commit. If the repository is public, anyone can read it: what the code looked like before, and what changed.
I searched GitHub for such commits and read about 300 of them. Most were package updates, new features, or tightening where nothing was shown to be open. I kept 85, one per project, where the commit closed something that a stranger or another user could really have used. For each one I wrote down what was open before the fix.
Two things to know before the numbers. I found the commits by searching for words such as "Fix security", "privilege escalation" and "XSS", so the mix below is shaped by the words I searched for. Read the counts as examples, not as rates. And every one of these was fixed. The question for you is whether your app has the same thing, and nobody has asked for the fix yet. I name no project here.
In an earlier post I read the code of six apps. This is the same question on a larger pile.
About half of them were in the database rules
43 of the 85 were in the rules of the database itself: the policies on the tables, and the SQL functions. Not in the pages, and not in the server code. (A few of the 43 are told further down, where they fit better.)
A helper that tells anyone who the admins are (9 of 85)
Many of these apps have this function:
create function public.has_role(_user_id uuid, _role app_role) returns boolean language sql security definer as $$ select exists (select 1 from user_roles where user_id = _user_id and role = _role) $$; The policies call it with the caller's own id, which is fine. But a function in the public schema can also be called from the browser by name, with any id. So anyone can ask it about any user and learn who the admins are.
Most of the fixes did one of two things. Some moved the helper to a schema the browser cannot reach. Others made it answer only about the caller.
Rank or money that a user gives themselves (11 of 85)
Seven of these were the same shape: a policy that lets a user update their own row.
create policy "Users update own profile" on profiles for update using (auth.uid() = id); A row policy covers the whole row. If the row holds is_pro, credits, a commission rate or a staff flag, the user can change that too, straight from the browser.
Two details from the fixes are worth knowing. A trigger that puts a list of columns back to their old values protects only the columns on the list. In one project the list did not hold the staff flag. And in PostgreSQL, taking away the right to update one column does nothing while the right on the whole table stands. The fixes that hold take the right on the table away first, and then give it back for the columns a user may change.
Three more were the sign-up trigger. It copied a role from what the new user sent about themselves at sign-up into the table of roles. Whoever signs up with role: admin in that data is an admin. And one was a server function that marked its caller as a paying user, with no proof of payment.
A row of your own, in a group you picked (6 of 85 were policies that let too many add rows)
create policy "Members can join" on team_members for insert with check (user_id = auth.uid()); This says whose row it is. It says nothing about which team the row joins, or what role it holds. A signed-in user can add themselves to any team, as an admin. The fix in one project was a few words more in the policy: and role = 'member'.
Another project had a policy that was named for what it forbids. It refused one kind of user and asked nothing of anybody else, so every other signed-in user could add rows under any id.
Tables that more people could read than was meant (11 of 85)
Six could be read by anyone. Two could be read by every signed-in user, and one of those held the app's settings. That sounds narrow, but in an app where anyone can sign up, "signed in" means everyone. Three more showed credentials, keys or files to more people than they should.
The server code: nobody asked who is calling
12 of the 85 were functions that never checked their caller. Four were SQL functions that run with their owner's rights and that any visitor could run. Seven were server functions that worked for callers who were not signed in: calls to a paid AI service on the owner's key, an export of logs, a lookup that told whether an email is registered. One of them took the public key, which every browser holds, as proof that a timer was calling. And one function read the caller's role out of a token by hand, without checking the signature. Anyone can write a token that says service_role.
One detail from the SQL ones. In one project a first fix took the function away from public, and a later fix had to come back for it. In Supabase the two roles a browser acts as hold their own grant, so the fix that holds names them: revoke execute on function ... from public, anon, authenticated.
13 more trusted something the caller sent. Six took an id or a storage path from the request and reached a row or a file without asking whose it is. Five built a file path from what was sent. One fetched any address it was handed, and one sent the visitor on to an address taken from the link.
The page: text from the database shown as HTML
15 of the 85. The page took text that a user had typed, a name or a note, and put it into HTML as it was.
React escapes text for you, so most of these were in the places where the code builds HTML by hand: a print view that writes a new window with document.write, the popup of a map, a page that shows stored HTML with dangerouslySetInnerHTML. Two were links: a saved address that starts with javascript: runs when another user clicks it. Three were spreadsheet exports. A cell that starts with = is run as a formula by the program that opens the file.
One thing I did not expect: two folders of migrations
27 of the 85 projects keep their database changes in two folders: supabase/migrations, named by date, and a newer drizzle/migrations, numbered from 0000. In 9 of them the older folder was still getting new files after the newer one began.
This matters if you, a reviewer, or an AI assistant read "the migrations" to learn what your rules are today. Both folders have to be read, in the order the changes were made. My own checker read them in the wrong order until a few days ago, and reported holes that a later migration had already closed. If a tool tells you a policy is open and you remember fixing it, look for a second folder.
What reading the code does not find
8 of the 85 were things that no list of patterns covers, and most of them were rules that only the app knows. Which students a teacher may see. What a refund takes back. A plan limit that only the browser kept. Somebody has to know what the app is meant to allow.
And a few of the 85 were about things that were made in the live database and are in no file of the repository. Reading code cannot see those either.
If you want this checked on your app
I do this as a fixed-price check on my Upwork listing. You give read access to the repository. You get a report with the file and line of each finding, sorted into fix now, check and information, and every row is read by hand before you see it. $149 is an opening price for the first five clients, then $249. Fixing what it found is a separate order: up to three findings for $300, each with proof that it shut what was open and opened nothing new. Nothing is run against your live app, and no key is ever tried. An empty report does not mean your app is secure.
原文:https://www.a8q9.cn/en/article/85-security-fixes-in-lovable-apps-what-was-actually-wrong-fbbdf4.html