Your login page is protected but your API route is open: 6 causes and a 5-minute test
You hid the dashboard behind a login page. A friend opens the API URL in a private window, not signed in, and sees real data. That is one of the most common gaps in AI-built apps: the page is protected, the route behind
You hid the dashboard behind a login page. A friend opens the API URL in a private window, not signed in, and sees real data.
That is one of the most common gaps in AI-built apps: the page is protected, the route behind it is not.
Why it happens
-
Auth only in the UI. The button is hidden, but
/api/usersanswers anyone. -
Middleware that does not cover the path. A Next.js
matcherthat skips/api, or a typo in the pattern. -
Checking that a token exists, not that it is valid.
if (req.headers.authorization)passes for any string. -
Checking login but not ownership. The user is signed in, but
/api/orders/123returns someone else's order. Change the id and see. - A service key used for convenience. The route uses a database key that bypasses row level security, so the database cannot help.
-
Client-side redirects. A
useEffectredirect to /login runs after the data already loaded.
The unsafe fixes
- Adding auth only in the front end because it "looks done".
- Switching the route to the service key to make an error go away.
- Returning the whole row, then hiding fields in the UI. The response still contains them.
A 5-minute test
- Open a private window, not signed in.
- Visit each API URL your app calls (DevTools, Network tab shows them).
- If any returns data, it is open.
- Sign in as user A, copy a request, change the record id to one that belongs to user B. If it works, ownership is not checked.
The safe pattern
- Check the session on the server in every route that returns private data.
- Filter by the signed-in user id on the server.
- Use the user's own token with row level security where you can.
- Return only the fields the page needs.
An outside view
ProofForge at proofforge.live runs a free public-side scan of AI-built apps. It never signs in, so it finds what an anonymous visitor can reach, which is the first half of this test. The second half, user A reading user B's data, needs two accounts. ProofForge has a free two-account test for Supabase apps for that.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes â full credit and traffic to the original publisher.