Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

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

  1. Auth only in the UI. The button is hidden, but /api/users answers anyone.
  2. Middleware that does not cover the path. A Next.js matcher that skips /api, or a typo in the pattern.
  3. Checking that a token exists, not that it is valid. if (req.headers.authorization) passes for any string.
  4. Checking login but not ownership. The user is signed in, but /api/orders/123 returns someone else's order. Change the id and see.
  5. A service key used for convenience. The route uses a database key that bypasses row level security, so the database cannot help.
  6. Client-side redirects. A useEffect redirect 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

  1. Open a private window, not signed in.
  2. Visit each API URL your app calls (DevTools, Network tab shows them).
  3. If any returns data, it is open.
  4. 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.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.