Direct answer
Because the generated code usually asks the browser who the user is. A request carries a user ID, a role or a record ID, and the server believes it. Sometimes the auth check exists in the codebase but is never attached to the routes. Sometimes it confirms the caller is logged in but never checks that the record belongs to them. The fix is to derive identity from a verified token on the server, and check ownership on every record read or written.
Why AI-generated code trusts the client
A prototype is tested by one person with one account. Sending userId in the request body works perfectly there, because the ID is always correct. It only fails when someone edits the request, and nobody in a demo does that.
In the production issues we reviewed across about 25 projects in October, this was the most common pattern, tied with silent failure: identity trusted from the client, auth defined but not enforced, or records reachable by changing an ID showed up in nine projects. The silent failure write-up covers the other half of that tie.
The risk has a name. OWASP’s API Security Top 10 lists Broken Object Level Authorization as API1:2023, the top entry, and describes the attack as manipulating the ID of an object sent within the request. It rates exploitability as easy.
Four cases we fixed
- A booking marketplace for creative freelancers had about eighteen backend functions that took the client, creator, admin, sender or reviewer ID from the request body. Each one checked that the ID had the right role, but never that the request came from that person, so anyone could act as anyone. Identity now comes from the caller’s verified auth token, and the frontend no longer sends identity fields at all.
- A fitness coaching marketplace let mobile users sign in with Apple by posting their Apple user ID. The server never verified Apple’s signed identity token, then issued a live session for whatever ID it received. Anyone who knew an ID could take over the account. The endpoint now verifies the token’s signature, issuer, audience and expiry against Apple’s public keys and takes the identity from the token.
- The same marketplace had a messages endpoint where leaving out the coach filter dropped the database filter entirely, returning every message on the platform. Coaching notes had no authentication. Shared authorization helpers now pin coaches to their own verified ID, a missing filter narrows the scope, and seeing a student’s data requires a real booking or conversation.
- An AI content-generation system had a complete auth middleware that was never imported into the API routes. An anonymous request for the lead list returned every lead. The middleware now guards every API route, and a test asserts that the same request returns 401.
What changes in Supabase apps
Supabase can enforce the check in the database. Supabase’s Row Level Security guide says a table in an exposed schema without RLS is readable and writable by any role with a grant on it, and that auth.uid() returns the ID of the user making the request. Policies should compare the row’s owner to auth.uid(), never to a value the client supplies. The same guide warns that policies based on user_metadata are risky because authenticated users can modify it, so roles belong somewhere the user cannot write.
Two traps recur. Edge functions using the service role key bypass RLS and need their own ownership checks. And a too-strict policy looks like a bug, which tempts people to loosen it; our guide to Supabase returning an empty array covers fixing that without opening the table.
How to test it with two accounts
Most of these need only two accounts and a browser’s developer tools to find.
- Create two users. Sign up as user A and user B in a test environment, and give each some records: a booking, a message, a profile, an invoice.
- Capture A’s requests. As user A, open the network tab and note every request that carries an ID: in the URL, the query string, the body or a header.
- Swap in B’s IDs. Replay each request as A, replacing record IDs with B’s. Any response containing B’s data, or any write that changes B’s record, is a broken check.
- Change who you claim to be. Where the body contains
userId,ownerId,roleor similar, change it to B’s ID or to an admin role and resend. - Drop the filters and the token. Remove optional query parameters, then remove the auth header entirely. The response should narrow or return 401, never widen.
- Turn every hit into a test. OWASP’s guidance is to write tests for the authorization mechanism and not deploy changes that make them fail.
The rule that prevents all of it
The server decides who the caller is from a verified token. Every function that loads a record by an ID from the client checks that the caller may touch that record. Treat every identifier, role and filter the browser sends as a claim the server has to check.
Related Zenveus services: Security & Data Isolation Audit, Supabase Security Audit and the 48-Hour Verdict