All posts

Anyone can open your admin page: fix roles in AI-built apps

You built an app with Lovable, Bolt, Cursor or Replit. It has an admin page, and a customer area where people see "my orders". You log in as a normal user and the admin menu is gone. It looks safe. But a hidden menu is not a lock. I checked the facts below against the official docs in November 2026.

Short answer: a role check that only runs in the browser is a suggestion, not security. The server or the database must check the role on every request. To test it, sign up a second normal account, open the admin URLs directly, and replay the admin page's requests with that account. Then change the IDs in the requests and see if you get someone else's data.

The pattern: the browser checks, the data does not

AI tools often protect an admin page like this. The app asks "is this user an admin?" and, if not, hides the menu or redirects to the home page. That is a route guard. It runs in the visitor's browser, which the visitor controls.

The data calls behind the page are separate. If the admin page loads all users from your database or API, and that call only needs a signed-in user, then any signed-in user can make the same call. They do not need your admin page. They can open the URL directly, or send the request with their own login.

The second version of the same mistake is "only my own data". The page asks for /orders/123, and the server returns order 123 without checking that it belongs to the user. Change 123 to 124 and you see another customer's order. This is called IDOR, short for insecure direct object reference.

This is a well-known problem class. OWASP lists Broken Access Control as number one (A01) in its Top 10:2021. Two of the examples on that page match what I described: "Bypassing access control checks by modifying the URL (parameter tampering or force browsing)" and "Permitting viewing or editing someone else's account, by providing its unique identifier". On the fix, OWASP says access control is "only effective in trusted server-side code or server-less API", and: "Except for public resources, deny by default."

Check it in 15 minutes, as a normal user

Only test your own app. You need two accounts: your admin account and a second, normal test account.

  1. Make a normal test account. Sign up with a second email. Use a private browser window so you stay logged in as both.
  2. Open the admin URLs directly. Log in as the normal user and type the admin page address into the browser bar, for example /admin or /dashboard/users. If you do not know the paths, look for the routes in your code. If the page opens, that is already a problem.
  3. Record what the admin page requests. Log in as your admin account, open DevTools in Chrome, go to the Network tab, and open the admin page. Note the requests that return lists of users, orders or settings.
  4. Replay them as the normal user. In the admin window, right-click one of those requests and choose Copy, then Copy as fetch. Paste it into the console of the normal user's window, and swap the sign-in token (the Authorization header) for the normal user's own token. Run it. If the data comes back, the check is missing on the server.
  5. Change the IDs. As the normal user, open one of your own records, like an order or a profile. Find its request in the Network tab. Change the ID in the URL or the body to the ID of a record that belongs to your admin account. If it loads, that is IDOR.
  6. Try the write calls too. Reading is bad. Changing or deleting is worse. Repeat steps 4 and 5 for update and delete requests, on test data only.
  7. Check what the database allows. In Supabase, read the policies on every table in the dashboard. In Firebase, read the Security Rules. If a rule only says the user is signed in, every account is allowed.

Every attempt as the normal user should end in an error or an empty result. Anything else is a gap. For the Supabase basics of switching on Row Level Security (RLS), see the database security checks.

Where roles must live

The rule is simple. A role must come from a place the user cannot change, and it must be checked where the data is, not in the browser.

Supabase

On its Row Level Security page the docs say raw_user_meta_data "can be updated by the authenticated user using the supabase.auth.update() function." They add: "It is not a good place to store authorization data." About raw_app_meta_data they say it "cannot be updated by the user, so it's a good place to store authorization data."

So if the AI tool wrote user_metadata.role = 'admin' into a policy or a check, treat that as a bug. A user can give themselves that value.

Supabase also describes a pattern for roles in its guide Custom Claims & Role-based Access Control (RBAC). It says to "Use Auth Hooks to add custom claims for managing role-based access control." The guide has you create "a table to track user roles and permissions" and use a custom access token hook, which "runs before a token is issued", to add the role to the user's token. Your RLS policies then check that role. Ask your AI tool to follow that guide.

Whatever you choose, the table that holds the roles needs RLS as well. If any signed-in user can write to it, they can make themselves an admin.

Firebase

Firebase calls this custom claims. Its custom claims guide says they "should only be set from a privileged server environment by the Firebase Admin SDK." The browser app must not set them. The same page says custom claims are "only used to provide access control", not for profile data.

Security Rules can then read the claim. The Firebase page on rules and auth says "the auth.token variable also contains any custom claims you specify." Its Firestore example is allow write: if request.auth.token.admin == true;. A rule that only checks that someone is signed in is not enough for admin data.

Your own server functions

Netlify Functions, Vercel Functions and Supabase Edge Functions all run on the server, so a check there cannot be skipped by the visitor. The steps are the same on each:

  1. Read the sign-in token from the request.
  2. Verify it on the server.
  3. Get the user ID and role from the verified token or from your database, and decide.
  4. Never take "isAdmin" or a user ID from the request body or the URL. The caller can write anything there. The same goes for prices and other form values: see why browser form checks aren't enough.

On Firebase, the Admin SDK can verify an ID token to "retrieve the uid from it" and securely identify the signed-in user on your server. That page also notes it "does not check whether or not the token has been revoked." On Supabase, the JWT guide says to rely on supabase.auth.getClaims() to verify the signature. The getUser reference says it "performs a network request to the Supabase Auth server", so the result can be used for authorization decisions.

"Only my own data" rules

For "my orders" the check has to compare the row's owner with the person asking. Both can do that in the database layer.

  • Supabase: The docs say auth.uid() "Returns the ID of the user making the request." A policy like using ( auth.uid() = user_id ) on the orders table only lets a user see rows where user_id is theirs. The page notes that without a signed-in user, auth.uid() "returns null", and recommends adding auth.uid() IS NOT NULL AND. It also warns that a policy such as to anon using ( true ) "grants every unauthenticated visitor read access to every row the role can already reach through grants."
  • Firebase: the Security Rules conditions page shows this pattern: "Another common pattern is to make sure users can only read and write their own data", with the rule allow read, update, delete: if request.auth != null && request.auth.uid == userId;.

If your app calls your own API instead, the same idea applies in code. Take the user ID from the verified token, and filter the query with it. Do not use an ID that came in the request. That is the whole fix for IDOR.

Prompts for your AI tool

"Make it secure" makes the tool rewrite things you did not ask about. Name the table, say where to enforce it, and say what must not change.

  • "The /admin page hides itself for non-admins, but the data calls behind it don't check the role. Enforce the admin check in the database with RLS policies on the tables the admin page reads and writes, not just in the frontend. Keep the UI exactly the same."
  • "Show me every place the app reads a role from user_metadata. Don't change anything yet. Then move the role to a roles table that only admins can write, following Supabase's RBAC guide."
  • "The orders table: add an RLS policy so a signed-in user can only select, update and delete rows where user_id equals auth.uid(). Only admins can see all rows. Don't change the page layout."
  • "In the Netlify function that returns orders, verify the sign-in token on the server and take the user ID from the verified token. Ignore any user ID sent in the request. Return 403 if the user is not allowed."

Do not trust "done" from the tool. Repeat the 15-minute check with the second account. Then log in as the admin and make sure the admin page still works. A tight rule can lock out the real admin too.

Checklist

  1. A normal test account cannot open admin pages or load admin data.
  2. Replaying admin requests as a normal user returns an error.
  3. Changing an ID in a URL or request never shows another user's record.
  4. Roles are not stored in user_metadata or anywhere a user can edit.
  5. The roles table (if you have one) cannot be written by normal users.
  6. Firebase claims are set only on a server, and Security Rules check them.
  7. Every server function verifies the token and takes the user ID and role from it, never from the request body.

Adding company accounts with several users? See adding teams, invites and roles.

Related: the launch-ready checklist, checking for exposed API keys, stopping fake sign-ups (anyone can create a normal account) and the first tests for an AI-built app.

Want this fixed for you?

I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including moving role and "own data" checks from the browser into the database and server. Or send me the details and I'll reply within 24 hours.