Guide · Access control · Updated
API route authentication for vibe-coded apps: open routes, IDOR and middleware-only auth, tested and fixed
Rather check your own app first and read later? Paste its address, prove it’s yours, and the free scan shows you the worst thing a stranger can reach. Run the free scan
Your app’s pages fetch their data from addresses like /api/notes. Those addresses aren’t part of the page. Anyone can call them straight from a terminal, with no browser, no login and none of your buttons. Whether they get your users’ data back depends on one thing: the few lines at the top of each route that ask who is calling, and whether the thing they asked for is theirs. AI builders write those lines less often than you’d hope. This guide shows how to find your routes, test them the way a stranger would, and fix them in Next.js, Supabase, Express and Firebase, with every fix run against a real server first.
New to this? Start with our vibe coding security checklist, eleven checks for any AI-built app. API routes and record ownership are checks 3 and 4 there. This page is the long version.
What we tested, and how
Everything on this page we ran ourselves on 25 October 2026, on our own machine, with made-up users called Alice, Bob and Carol. We built a small notes app in Next.js 16.4.3 (next build, then next start) with a careless and a fixed version of each route: one with no check, one that only checks for a login, one that trusts a user id from the address, an admin route guarded only by proxy.ts, and a Server Action. A second copy of the middleware-only route ran on Next.js 15.2.2 and 15.2.3 to reproduce CVE-2025-29927. The Supabase routes used the real @supabase/supabase-js 2.118.0 and @supabase/ssr 0.12.7 libraries, talking to a small stand-in we wrote for two Supabase endpoints (Auth’s /auth/v1/user and the table API), backed by real Postgres rules running in PGlite. That stand-in is not Supabase, and we say below where that matters. Express 5.3.0 ran careless and fixed side by side. Firebase Cloud Functions ran in the Firebase emulators (firebase-tools 15.34.1, auth and functions). Finally we pointed LockShip’s own scanner code at the lab, so the claims about our scan below come from running it, not from memory.
The seven checks
- Why an API route leaks, in four shapes
- List every route and action your app has
- Ask without signing in, the way our scan does
- Sign in as someone else: the IDOR test
- Middleware is not the lock
- Fixes we tested, per stack
- Test again, and keep testing
01
Why an API route leaks, in four shapes
Broken access control sits at number one in OWASP’s 2025 Top 10, and the A01 page says “100% of the applications tested were found to have some form of broken access control.” Vercel’s own write-up on v0 and secure vibe coding lists “unauthenticated API routes” among the most common issues it blocks. In AI-built apps we see it in four shapes:
- No check at all. The route returns its data to anyone. Usually it was written to feed one screen, and the screen was behind a login, so nobody thought about the route. MITRE calls this missing authentication (CWE-306) or missing authorization (CWE-862). This is the one our scan can see from outside.
- Signed in, but not asked whose it is. The route checks that somebody is logged in, then returns note 1 to whoever asks for note 1. Security people call this an insecure direct object reference, IDOR, and OWASP’s API list calls it broken object level authorization and ranks it first. Its rule: “Every API endpoint that receives an ID of an object, and performs any action on the object, should implement object-level authorization checks.”
- Trusting the user id the browser sends. The route reads
?userId=from the address, oruserIdfrom the request body, and believes it. Anyone can type someone else’s id there. MITRE’s name for it is plain: Authorization Bypass Through User-Controlled Key. OWASP’s IDOR cheat sheet gives the fix in one line: “Instead, determine the currently authenticated user from session information.” - A check in the wrong place. The login check lives in middleware or
proxy.ts, in a layout, or in the front end that hides a button, and the route itself trusts that someone else checked. Server Actions belong here too: they look like ordinary functions, but each one is a public address. OWASP puts it bluntly: “Access control is only effective when implemented in trusted server-side code or serverless APIs, where the attacker cannot modify the access control check or metadata.”
The same rule fixes all four: every route that isn’t public on purpose asks who is calling, on the server, and only touches records that belong to that person. OWASP’s short version is “Except for public resources, deny by default.”
02
List every route and action your app has
You can’t check routes you don’t know about, and agents add them quietly. If you have the code, these four commands list them. On our lab projects they found all thirteen route handlers, every Express route, the file holding both Server Actions and all four Firebase functions:
# Run in your project folder
# 1. Next.js route handlers
find . \( -name node_modules -o -name .next \) -prune -o -name "route.[jt]s" -print
# 2. Express-style routes
grep -rnE "\.(get|post|put|patch|delete)\(\s*[\"'\`]/api" \
--include=*.ts --include=*.js --include=*.mjs --exclude-dir=node_modules --exclude-dir=dist .
# 3. Server Actions (files or functions marked "use server")
grep -rnE --include=*.ts --include=*.tsx --include=*.js --include=*.jsx \
--exclude-dir=node_modules --exclude-dir=.next "[\"']use server[\"']" .
# 4. Firebase Cloud Functions (prints an error if there's no functions folder; ignore it)
grep -rnE "onRequest|onCall" --include=*.ts --include=*.js \
--exclude-dir=node_modules --exclude-dir=lib functionsWithout the code, or to see your app the way a stranger does, list the /api addresses your live page’s JavaScript mentions. This is close to what our scan does: it uses the same pattern to pick addresses out of the scripts, though the scan also reads the scripts other pages load and the chunks they pull in later, so it can find more than this one-liner. Change PAGE to /dashboard or any other page to read its scripts too:
# The /api addresses your live page's scripts mention. Put your address in APP.
APP=https://yourapp.com
PAGE=/
curl -s "$APP$PAGE" | grep -oE '<script[^>]+src="[^"]+"' | sed -E 's/.*src="([^"]+)".*/\1/' | while read -r s; do
case "$s" in http*) curl -s "$s" ;; *) curl -s "$APP$s" ;; esac
done | grep -oE "[\"'\`]/(api|functions/v1)/[A-Za-z0-9_./-]{1,80}[\"'\`]" | tr -d "\"'\`" | sort -uOn our lab’s /notes page that printed /api/notes. On lockship.dev it printed /api/pv, /api/scans and /api/waitlist. Two blind spots, in the one-liner and in our scan alike: an address built from pieces, like `/api/notes/${id}`, or one with a query string, isn’t a plain string in the code, so it won’t be listed. Those are usually exactly the routes that take an ID, which is why check 4 exists.
03
Ask without signing in, the way our scan does
Now ask each route for its data with no cookie and no key. This loop sends what our scan sends: a plain GET with Accept: application/json, following redirects:
# Swap in your address and the routes from the list above.
APP=https://yourapp.com
for p in /api/me /api/notes /api/users; do
code=$(curl -sL -o /tmp/lockship-api -w '%{http_code} %{content_type}' -H 'Accept: application/json' "$APP$p")
echo "$p $code $(head -c 100 /tmp/lockship-api)"
done
rm -f /tmp/lockship-apiHow to read each line:
- 401 or 403. Good. The route asked who you were and stopped. A 200 whose body is only an error, like
{"error":"Not signed in"}, also counts as refused, though a real 401 is clearer. - 404 or 405. Nothing to read here with a GET. A 405 means the route exists but only takes another method, usually POST, which neither this loop nor our scan sends. lockship.dev’s three routes all answered 405, because they only take POST. Those routes still need a check; you test them with two accounts in check 4.
- 200 with JSON that has emails, names, orders, tokens or anything about a user. That’s the leak. Anyone with the address gets the same thing. Go to check 6.
- 200 with JSON about nothing personal, like a health check or a list of public plans. Probably fine, if it’s meant to be public. Decide on purpose.
Our lab app (Next.js 16.4.3, next start), no cookie:
/api/notes 200 application/json [{"id":1,"ownerId":"alice","email":"alice@example.com","text":"Alice's private note"},{"id":2,"owner
/api/fixed/notes 401 application/json {"error":"Not signed in"}
/api/admin/users 200 application/json [{"id":"alice","email":"alice@example.com","role":"user"},{"id":"bob","email":"bob@example.com","rol
/api/fixed/admin/users 401 application/json {"error":"Not signed in"}
/api/sb/all-notes 200 application/json [{"id":1,"user_id":"11111111-1111-4111-8111-111111111111","email":"alice@example.com","body":"Alice'
/api/sb/notes 401 application/json {"error":"Not signed in"}
lockship.dev, the three /api addresses its homepage scripts mention:
/api/pv 405
/api/scans 405
/api/waitlist 405Then we ran our scanner’s own route check against the same lab. It flagged the three open routes as high, because their answers held user-looking fields, and the harmless health check as medium. It stayed quiet on every fixed route, and on /api/notes/2, which only refused because nobody was signed in. That last one is the IDOR route. From outside, signed out, it looks perfect:
Our scanner's own code, pointed at the same lab:
[high] Unauthenticated response from /api/notes
[high] Unauthenticated response from /api/admin/users
[high] Unauthenticated response from /api/sb/all-notes
[medium] Unauthenticated response from /api/health <- {"status":"ok","version":"1.4.2"}
not flagged: /api/fixed/notes, /api/fixed/admin/users, /api/sb/notes, /api/notes/204
Sign in as someone else: the IDOR test
A route that checks for a login passes check 3 and can still hand any signed-in user anyone else’s data. The only way to see that is to be two people. OWASP’s IDOR cheat sheet suggests exactly this: “create multiple user accounts with different authorization scopes.” Make two test accounts, A and B. Create something as A and note its ID or address. Then, signed in as B:
# Signed in as account B: copy the Cookie header of any request
# from DevTools > Network. Then ask for something account A owns.
curl -s -w ' [%{http_code}]\n' \
-H "Cookie: PASTE_ACCOUNT_B_COOKIE" \
https://yourapp.com/api/notes/ID_THAT_BELONGS_TO_ACCOUNT_A
# And the same route with a user id in the address, if your app has one:
curl -s -w ' [%{http_code}]\n' \
-H "Cookie: PASTE_ACCOUNT_B_COOKIE" \
"https://yourapp.com/api/profile?userId=ACCOUNT_A_ID"You want 404 (or 403) for A’s things, and 200 when B asks for B’s own. Do the same in the browser: open A’s page address while signed in as B. If you have an admin page, try its address and its API routes as an ordinary user too. OWASP’s API list calls that one broken function level authorization, and it’s the same mistake one level up.
Bob is signed in. Note 1 is Alice's.
GET /api/notes/1 (checks login only) 200 {"id":1,"ownerId":"alice",...,"text":"Alice's private note"}
GET /api/fixed/notes/1 (login + owner in query) 404 {"error":"Not found"}
GET /api/fixed/notes/2 (Bob's own note) 200 {"id":2,"ownerId":"bob",...}
GET /api/profile?userId=alice (trusts the query) 200 {"userId":"alice","notes":[{"id":1,...Alice's private note}]}
GET /api/fixed/profile?userId=alice (uses the session) 200 {"userId":"bob","notes":[{"id":2,...Bob's private note}]}The second pair is the one AI builders write most often in our experience: a route that’s handed userId because the front end already knew it, and never asks whether that’s the person asking. The fix ignores the parameter and uses the session. Bob asked for Alice and got Bob.
Our scan never signs in, so it can’t run this check for you. That’s the honest limit of any outside scan: IDOR needs two real accounts and someone who knows which records belong to whom.
05
Middleware is not the lock
Next.js apps often put the login check in middleware.ts, or since Next.js 16 proxy.ts, because one file seems to protect everything. The Next.js authentication guide is clear that it can’t: “While Proxy can be useful for initial checks, it should not be your only line of defense in protecting your data.” The proxy docs give the everyday reason: “A matcher change or a refactor that moves a Server Function to a different route can silently remove Proxy coverage.”
We built that by accident on purpose. A proxy whose matcher covers /api/admin:
// proxy.ts (middleware.ts before Next.js 16)
export function proxy(request: NextRequest) {
if (!request.cookies.get("session")) {
return NextResponse.json({ error: "Not signed in" }, { status: 401 });
}
return NextResponse.next();
}
export const config = { matcher: ["/dashboard/:path*", "/api/admin"] };GET /api/admin 401 {"error":"Not signed in"} <- the proxy caught it
GET /api/admin/users 200 [{"id":"alice","email":"alice@example.com",...},{"id":"carol",...,"role":"admin"}]
<- "/api/admin" doesn't match /api/admin/users; the route itself checked nothingOne missing /:path* and the whole admin user list went out, with Carol’s admin role in it. Nothing errored, and the build output looked the same.
Then there’s the time middleware itself had a hole. In March 2025 Next.js published CVE-2025-29927: “It is possible to bypass authorization checks within a Next.js application, if the authorization check occurs in middleware.” It was fixed in 15.2.3, 14.2.25, 13.5.9 and 12.3.5. The advisory says “Next.js deployments hosted on Vercel are automatically protected against this vulnerability,” and Vercel’s postmortem explains that its routing ran middleware separately, which “made Vercel incidentally invulnerable.” Apps hosted elsewhere were exposed. We reproduced it on our own machine:
The same idea on Next.js 15.2.2: the cookie check lives in middleware.ts
(matcher /api/admin/:path*), the route checks nothing.
next 15.2.2
GET /api/admin/users 401 {"error":"Not signed in"}
GET /api/admin/users + x-middleware-subrequest header 200 [{"id":"alice",...},{"id":"bob",...}]
next 15.2.3
GET /api/admin/users 401 {"error":"Not signed in"}
GET /api/admin/users + x-middleware-subrequest header 401 {"error":"Not signed in"}Two lessons. Keep Next.js on a patched version (our checklist shows how to read your live version). And keep the middleware for redirects and fast “are you signed in?” checks if you like, but put the real check in every route and action as well. If your route had checked for itself, neither the matcher typo nor the CVE would have mattered.
06
Fixes we tested, per stack
First decide which routes are public on purpose: a health check, a list of plans, a contact form. Write them down. Every other route gets the same two questions at the top, in this order: who is asking? (nobody: 401) and is it theirs? (no: 404, or 403 for a role). The person comes from the session or a verified token on the server. Never from the URL, the query string or the body.
Next.js route handlers
The Next.js authentication guide says to “Treat Route Handlers with the same security considerations as public-facing API endpoints, and verify if the user is allowed to access the Route Handler.” In practice that’s two checks at the top of each route.ts. getUser() here is whatever your auth library gives you on the server: Supabase’s, Auth.js’s auth(), Clerk’s auth(). The second check is the one people miss: the owner goes into the lookup itself, so someone else’s ID simply finds nothing.
// app/api/notes/[id]/route.ts
import { db } from "@/lib/db";
import { getUser } from "@/lib/session"; // your auth library's "who is this?" call
export async function GET(_req: Request, ctx: RouteContext<"/api/notes/[id]">) {
// 1. Who is asking? Nobody: stop here.
const user = await getUser();
if (!user) return Response.json({ error: "Not signed in" }, { status: 401 });
// 2. Is it theirs? Put the owner in the lookup itself.
const { id } = await ctx.params;
const note = db.byIdAndOwner(Number(id), user.id);
if (!note) return Response.json({ error: "Not found" }, { status: 404 });
return Response.json(note);
}For admin routes, the role check lives in the route too, whatever the proxy does:
// app/api/admin/users/route.ts: the route checks the role itself
export async function GET() {
const user = await getUser();
if (!user) return Response.json({ error: "Not signed in" }, { status: 401 });
if (user.role !== "admin") return Response.json({ error: "Forbidden" }, { status: 403 });
return Response.json(db.users());
}In our lab, the fixed routes answered 401 with no cookie, 404 when Bob asked for Alice’s note, 403 when Bob asked for the admin list, and 200 for Carol, the admin. Next.js’s data security guide suggests going one step further on bigger apps: put every database read behind a small data access layer that does these checks, so a new route can’t forget them.
Next.js Server Actions
A Server Action is a function marked “use server” that your buttons and forms call. It doesn’t look like a route, and that’s the trap. The data security guide says “when a Server Action is created and exported, it is reachable via a direct POST request, not just through your application’s UI,” and to “verify authentication and authorization inside each one.” Next.js’s post on Server Actions security adds that their arguments “must always be treated as hostile.”
We tested how real that is. Our notes page had a Delete button that only showed on your own notes. The action behind it checked nothing. Anyone can read an action’s ID out of the page’s JavaScript, and Next.js writes the function’s name next to it, so we did, and sent it one request from the terminal:
# A stranger reads the action IDs out of the /notes page's JavaScript:
deleteNote 405b23a0e7efb1630eb9ac38168daa82fb0af89772
deleteNoteSafe 401eb0647622f86f00d84b6fa959e6711f79fa2713
# deleteNoteSafe(1), no cookie -> 500 (it threw "Not signed in"; nothing deleted)
# deleteNoteSafe(1), Bob's cookie -> 500 (it threw "Not found"; Alice's note survives)
# deleteNote(1), no cookie, no browser, no UI -> 200
GET /api/notes afterwards: [{"id":2,"ownerId":"bob",...}] <- Alice's note is goneThe fixed version asks the same two questions as a route, and checks the argument’s type because anyone can send anything:
// app/notes/actions.ts
"use server";
import { db } from "@/lib/db";
import { getUser } from "@/lib/session";
// Before: the Delete button only showed for the owner, but the action checked nothing.
// export async function deleteNote(id: number) { db.remove(id); }
export async function deleteNoteSafe(id: unknown) {
const user = await getUser();
if (!user) throw new Error("Not signed in");
if (typeof id !== "number") throw new Error("Bad id"); // arguments come from anyone
const note = db.byIdAndOwner(id, user.id);
if (!note) throw new Error("Not found");
db.remove(note.id);
return { ok: true };
}Don’t repeat our curl test on your live app. A Server Action really runs, so testing it from outside means really deleting or changing something. Read each action’s first lines instead (the third command in check 2 lists them), and do the two-account test from check 4 in the browser. Our Server Actions guide goes further: validating arguments with zod, bound ids, what encrypted closures don’t protect, Supabase inside an action, and rate limits.
Supabase
With Supabase there are two places the check can live, and you want both. Your own route asks Supabase Auth who the user is. Then the query runs as that user, so Row Level Security on the table only returns their rows, even if the route forgets a filter.
Two things go wrong in AI-written Supabase routes. The first is reading the user with getSession(). Supabase’s Next.js auth guide warns that “Anyone can forge the session cookie, so trusting it without verification lets an attacker render another user's page,” and says to “Never trust supabase.auth.getSession() inside server code such as Proxy.” Use getUser(), which the same guide says “makes a network call to the project's Auth instance,” or getClaims(), which the guide now recommends because it checks the token’s signature without a round trip on newer projects. The second is querying with the secret key, the one older projects call service_role. Supabase’s API keys guide says “Policies never apply to a secret key, because service_role has the BYPASSRLS attribute.” A route that uses it has to do every check itself, and AI-written ones often don’t.
// app/api/notes/route.ts
import { createClient } from "@/lib/supabase/server"; // the cookie-based server client from Supabase's Next.js guide
export async function GET() {
const supabase = await createClient();
// getUser() asks Supabase Auth whether this token is real. getSession() doesn't check.
const { data: { user }, error } = await supabase.auth.getUser();
if (error || !user) return Response.json({ error: "Not signed in" }, { status: 401 });
// This client carries the user's token, so the query runs as them and RLS applies.
const { data, error: dbError } = await supabase.from("notes").select("id, body");
if (dbError) return Response.json({ error: "Could not load notes" }, { status: 500 });
return Response.json(data);
}alter table public.notes enable row level security;
create policy "Users read their own notes"
on public.notes for select
to authenticated
using ((select auth.uid()) = user_id);The policy has the same shape as the example in Supabase’s RLS docs. Here’s what we saw. To test the forged cookie, we took the exact cookie name and format the real @supabase/ssr library produced, and swapped in a token we signed with a key we made up, claiming to be Alice:
No cookie:
/api/sb/all-notes (secret key, no check) 200 both users' notes, emails included
/api/sb/notes (getUser + user's client + RLS) 401 {"error":"Not signed in"}
Alice's real cookie:
/api/sb/notes 200 [{"id":1,"body":"Alice's private note"}]
same route, RLS switched off on notes 200 [{"id":1,...},{"id":2,"body":"Bob's private note"}]
A forged cookie (right name and shape, token signed with a made-up key, claims to be Alice):
/api/sb/session-notes (getSession + secret key) 200 {"as":"alice@example.com","notes":[{"id":1,...}]}
/api/sb/notes (getUser) 401 {"error":"Not signed in"}
/api/sb/claims (getClaims) 401 {"error":"Not signed in"}Three things to take from that. The secret-key route with no check gave everything to everyone. The route that trusted getSession() and then queried with the secret key believed the forged cookie and returned Alice’s notes. And the fixed route only returned Alice’s own note because of RLS: with RLS off, the same signed-in Alice got Bob’s note too. Our stand-in checked tokens the way Supabase Auth does for projects that sign with a shared secret; newer projects use signing keys, and we didn’t test against a hosted project. To check your tables’ rules from the outside, use our Supabase RLS checklist.
Express (Replit and other Node servers)
Express runs middleware in the order you add it. Its own docs say “The order of middleware loading is important: middleware functions that are loaded first are also executed first,” and a middleware that lets a request through has to call next(). So a sign-in check added with app.use protects only the routes defined below it. In our careless server, an /api/export route sat one line above the check and answered every stranger with every note. The fix puts the check first, and takes the owner from the session in every query:
import express from "express";
const app = express();
app.use(express.json());
// ...your session or token middleware goes here and sets who is signed in...
function requireUser(req, res, next) {
const uid = req.signedCookies.uid; // or req.session.userId, req.user, a verified token...
if (!uid) return res.status(401).json({ error: "Not signed in" });
req.user = { id: uid };
next();
}
app.use("/api", requireUser); // FIRST, above every /api route
app.get("/api/notes/:id", (req, res) => {
const note = notes.find((n) => n.id === Number(req.params.id) && n.ownerId === req.user.id);
if (!note) return res.status(404).json({ error: "Not found" });
res.json(note);
});
app.patch("/api/notes/:id", (req, res) => {
// Ignore req.body.userId. The owner is whoever the session says.
const note = notes.find((n) => n.id === Number(req.params.id) && n.ownerId === req.user.id);
if (!note) return res.status(404).json({ error: "Not found" });
note.text = String(req.body.text);
res.json(note);
});Express 5.3.0 careless fixed
GET /api/export, no cookie 200 all notes 401
(careless: defined above app.use("/api", requireUser))
GET /api/notes/1, Bob's cookie (Alice's note) 200 Alice's 404
PATCH /api/notes/1, Bob, body {"userId":"alice"} 200 rewritten 404
GET /api/notes/1, hand-written cookie uid=alice 401 401
GET /api/notes/2, Bob's cookie (his own) - 200The PATCH line is the “trusting the body” bug: Bob sent "userId":"alice" and rewrote Alice’s note. The fixed server ignored it. The hand-written uid=alice cookie failed on both, because the cookie was signed; if your app keeps who-is-signed-in in a plain cookie or in localStorage that the server believes, that’s the next thing to fix. Our Replit guide has the same check in a Replit-sized walkthrough.
Firebase Cloud Functions
An HTTP function (onRequest) is a public address. Have your app send the user’s ID token, and check it with the Admin SDK’s verifyIdToken(); Firebase’s docs say the uid you get back is how you “securely identify the currently signed-in user on your server.” Callable functions (onCall) are friendlier: Firebase’s callable docs say the trigger “automatically deserializes the request body and validates auth tokens.” But it still runs your function when there’s no token at all, with request.auth empty. The docs’ own example checks if (!request.auth) first, and so should you:
const { onRequest, onCall, HttpsError } = require("firebase-functions/https");
const { initializeApp } = require("firebase-admin/app");
const { getAuth } = require("firebase-admin/auth");
initializeApp();
// An HTTP function: verify the ID token the app sends as "Authorization: Bearer <token>".
exports.myNotes = onRequest(async (req, res) => {
const match = (req.headers.authorization || "").match(/^Bearer (.+)$/);
if (!match) return res.status(401).json({ error: "Not signed in" });
let decoded;
try {
decoded = await getAuth().verifyIdToken(match[1]);
} catch {
return res.status(401).json({ error: "Not signed in" });
}
res.json(notes.filter((n) => n.uid === decoded.uid));
});
// A callable: Firebase checks the token for you, but still runs the function without one.
exports.myNotesCall = onCall((request) => {
if (!request.auth) throw new HttpsError("unauthenticated", "Sign in first.");
return notes.filter((n) => n.uid === request.auth.uid); // never request.data.uid
});firebase-tools 15.34.1 emulators (auth + functions), firebase-functions 7.4.0
notesOpen (onRequest, no check) no token 200 both users' notes
myNotes (onRequest + verifyIdToken) no token 401
myNotes "not-a-real-token" 401
myNotes Bob's ID token 200 Bob's note only
notesForCall (onCall, trusts data.uid) no token, Alice's uid 200 {"result":[Alice's note]}
myNotesCall (onCall, checks request.auth) no token 401 {"error":{"status":"UNAUTHENTICATED"}}
myNotesCall Bob's token, Alice's uid 200 Bob's note onlyThe careless callable is the one to look for: it ignored request.auth, trusted the uid it was sent, and gave a caller with no token Alice’s note. One emulator caveat: the Auth emulator issues unsigned tokens, so it can’t show what happens to a forged token in production. We only checked that a made-up string was refused. If your app reads Firestore straight from the browser, the lock there is Security Rules, not your functions; our Firebase Security Rules checklist covers those.
Have your AI builder do it
This is the prompt we’d paste. It asks for a list back, so you can check what it did instead of trusting that it did:
Go through every API route, route handler, Server Action and cloud function in this app. For each one, tell me whether it is meant to be public. For every one that isn't: (1) the first thing it does is find out who is signed in on the server, from the session or a verified token, and return 401 (or throw) if nobody is; (2) every record it reads or changes is looked up with the signed-in user's id in the query itself, never a user id taken from the URL, query string or request body, and someone else's record returns 404; (3) admin-only routes check the role in the route, not only in middleware or proxy.ts; (4) with Supabase, use supabase.auth.getUser() (or getClaims()) and the user's own server client so Row Level Security applies, never getSession() on the server, and the secret or service_role key only where there's no user. Don't remove the middleware, just stop relying on it. List every route and action, what it checks now, and anything you left public on purpose. Change nothing else.07
Test again, and keep testing
Run check 3 again against the live address, not localhost, and look for 401s where you had 200s. Then do check 4 with your two accounts, in the browser and with curl, including one write: as B, try to edit or delete something of A’s through the app’s own screens, if your app lets B reach them. Then use the app normally as A for a minute. A check that’s too strict breaks your own pages, and the first sign is usually an empty list.
OWASP’s Authorization Cheat Sheet has the line to keep in mind here: “Remember an attacker only needs to find one way in.” This comes back the moment an agent adds a feature. A new screen needs data, the agent writes a new route for it, and the new route copies the shape of an old one without the check. Re-run the route list from check 2 after every big change, and look for addresses you don’t recognise. If you’d rather not remember, that’s what a weekly scan is for, with the limits below.
What a clean result means
Every route that isn’t public on purpose answers 401 with no cookie. With two accounts, neither can read or change the other’s things. Admin routes check the role in the route. Server Actions check the caller and the owner in their first lines. Supabase routes use getUser() or getClaims() and the user’s own client, with RLS on. A route that calls OpenAI or Anthropic needs more than a login check, because every signed-in user can still spend your money; our AI API route guide covers the limits and caps. That still says nothing about keys leaked into your JavaScript, your database rules for the browser, or CORS, which decides whether other websites can read your API through your users’ browsers. Those are on the checklist, and CORS has its own guide.
Where LockShip fits
We built LockShip to read your app from the outside, the way a stranger would. For API routes, here’s exactly what that covers. The scan reads the scripts your pages load and picks out addresses written in them as plain strings that start with /api/ or /functions/v1/, the same pattern as the one-liner in check 2. It asks up to eight of them, on your own site, once each: a GET with Accept: application/json, no cookies and no keys, following up to three redirects like curl -L. It ignores any answer that isn’t HTTP 200, isn’t JSON, is empty ([] or {}), or is a small object with an error field.
Anything left becomes the finding “Unauthenticated response from” the route. It’s high when the JSON mentions an email, password, token, secret, customer, phone or user, and medium otherwise, with “Confirm it is meant to be public.” The finding says what came back and how, never the values. Each one links to the fixes on this page. Monitor, at $9 a month, re-runs the scan every week and emails you once when a new critical or high issue shows up, which is how a new open route from last week’s feature gets caught.
What it doesn’t do: it never signs in, so it can’t see IDOR or a route that trusts a userId (checks 4 and 6 are yours). It doesn’t follow addresses built from pieces or with query strings. It counts your Server Actions and lists them in the report, but never calls them, because that would run them for real. Apart from its CORS preflights, the scan only sends GET and HEAD requests, and it never writes anything. A clean result means “nothing obvious from the outside right now,” not “safe.”
The summary is free: a score and the single worst thing we found. The $39 Launch Safe certificate includes every finding with a fix prompt you can paste into your builder, a PDF, and seven days of re-scans while you fix things.
Want to see which of your API routes answer strangers?
Paste your app’s address, prove you own it, and see the worst thing we find. The summary is free.
Run a free scanBefore you rely on a result, read the disclaimer.
Questions people ask
The route needs a login in the app. Isn’t that enough?
Only if the check is in the route. Hiding a page, a button or a menu is a front-end decision, and the route behind it answers anyone who calls the address directly. In our lab the Delete button only showed for the owner, and the Server Action behind it deleted Alice’s note for a curl request with no cookie at all.
My IDs are long random UUIDs. Do I still need the ownership check?
Yes. They make guessing harder, but IDs leak through links, screenshots, logs and other API answers. OWASP’s IDOR cheat sheet says “even with complex identifiers, access control checks are essential.” Use random IDs as a second layer, not the lock.
Should I return 403 or 404 for someone else’s record?
Either keeps the data safe. We return 404 so someone else’s record looks exactly like one that doesn’t exist, which tells a stranger nothing. Use 401 when nobody is signed in and 403 when someone is signed in but lacks the role, like a normal user on an admin route.
LockShip flagged /api/health or another route that is public on purpose. What now?
If it returns nothing about any user, it can stay public. Our scan marks JSON without user-looking fields as medium with “Confirm it is meant to be public,” not high. Check what it returns, make sure it can’t grow to include user data later, and move on.
Is it safe to run these tests on my live app?
The GET requests are, on your own app. Don’t send POST, PUT, PATCH or DELETE requests, or call Server Actions, on a live app to see what happens, because they really run. Do write tests on localhost or a preview with test data, and use your own two test accounts for the IDOR check.
Keep reading
- Vibe coding security checklist: what to check before you launch an AI-built app
- Is my v0 app secure? A plain check before you launch
- Is my Cursor app secure? A plain check before you launch
- A Supabase RLS checklist for vibe-coded apps
- CORS for vibe-coded apps: wildcards, reflected origins and credentials, tested and fixed
Sources
We read each of these on 25 October 2026. Frameworks change their examples, so if something here disagrees with their docs, trust the docs and tell us at hi@lockship.dev. The lab results are our own, from test apps with made-up users on our own machine. We didn’t test on any host’s account or against a hosted Supabase or Firebase project, and we didn’t run any of this against anyone else’s app.
- A01:2025 Broken Access Control, OWASP Top 10
- API1:2023 Broken Object Level Authorization, OWASP API Security Top 10
- API5:2023 Broken Function Level Authorization, OWASP API Security Top 10
- Insecure Direct Object Reference Prevention Cheat Sheet, OWASP
- Authorization Cheat Sheet, OWASP
- CWE-639: Authorization Bypass Through User-Controlled Key, MITRE
- CWE-862: Missing Authorization, MITRE
- CWE-306: Missing Authentication for Critical Function, MITRE
- v0 and vibe coding securely, Vercel
- Authentication, Next.js
- Data security, Next.js
- How to think about security in Next.js, Next.js blog
- use server, Next.js
- route.js, Next.js
- proxy.js, Next.js
- CVE-2025-29927: Authorization bypass in Next.js middleware, GitHub advisory
- Postmortem on Next.js middleware bypass, Vercel
- Setting up server-side auth for Next.js, Supabase
- auth.getUser(), Supabase JavaScript reference
- API keys, Supabase
- Row Level Security, Supabase
- Using middleware, Express
- Writing middleware, Express
- Verify ID tokens, Firebase
- Call functions from your app, Firebase
- Connect your app to the Authentication Emulator, Firebase