Authorization vs Authentication: The Top API Security Risk

· 7 min read ·

A man in a green sweater holds a laptop in an old library archive while a small white robot in a detective cap holds a magnifying glass to one wooden drawer that stands slightly open among rows of locked drawers

Authentication checks who you are. Authorization checks what you are allowed to touch. A login screen only does the first. When the second is missing, the app knows you are signed in and then hands you whatever record you ask for, including someone else’s. OWASP ranks that bug, broken object level authorization, first in its 2023 API Security Top 10.

QuestionNameExample
Who are you?AuthenticationEmail and password, a Google sign-in
What may you touch?AuthorizationYou can open your invoices, not mine

What does a missing check look like in a real incident?

In April 2026, a researcher reported that any free Lovable account could read other users’ project data, including source code and chat history. The Register describes it as a broken object level authorization bug. Lovable’s own account is narrower: between February 3 and April 20, 2026, chat history and source code of public projects could potentially be reached by any Lovable user who had a project link, private projects were not affected, and a fix shipped within two hours of the public report. It says that access had been deliberately removed during 2025 and that “backend regressions re-enabled public access” in February 2026. The researcher and the company disagree about how wide the exposure was and how the report was handled, so read both.

Both accounts share one shape: everyone was logged in, and the check on what they could reach was broken. The lesson that holds either way is Lovable’s own description of the failure, a closed door reopened by a regression, with nothing failing loudly. OWASP’s guidance for this class of bug says to write tests for the authorization mechanism and not to deploy changes that make them fail. The rest of this post is how.

How does authorization go missing?

1. There is no check at all. The route loads a record by the id in the URL and returns it. OWASP’s IDOR cheat sheet describes an id reaching the lookup with nothing verifying that the object belongs to the current user. OWASP says access checks are essential even with complex identifiers. The same hole hides in list, search and export routes that return everyone’s rows.

2. The check is in the wrong place. The admin button is hidden in the browser, and the API behind it answers anyone. OWASP’s authorization cheat sheet says permissions must be validated on every request, whatever its origin. The February 2026 Lovable-hosted app from the auth post was the reverse: a guard that was present and inverted.

3. The check trusts something the user controls. A role sent in a header, a field in the request body, or user_metadata, which the user can edit. The server has to decide the role from its own records.

How do I fix missing authorization?

Four rules, each a line of code, not a framework:

  1. Every route needs a login unless you wrote down that it does not. OWASP calls this deny by default. A route you add next month is locked on arrival.
  2. Look the record up through the user. Not “get note 17”, but “get note 17 that belongs to this user”. If nothing comes back, answer 404, so the response does not reveal which ids exist (OWASP’s IDOR guide suggests this). Use 403 where existence is not a secret, like an admin page that everyone knows is there.
  3. Take the role from your own database or token, never from the request. On Supabase that means app_metadata, per Supabase’s user data docs. Claims in a token count only after the signature is verified.
  4. Only copy the fields you allow. Spreading the whole request body into an update lets a user set owner or role themselves.

On Supabase, row level security puts rule 2 inside the database as a policy, such as “rows where user_id equals auth.uid()”, where a forgotten route cannot skip it. Background jobs, webhooks and file links skip the HTTP routes below, so they need the same ownership check.

Roles (admin, member) are one input to authorization. Ownership (“this note is mine”) is the other, and it goes missing most.

Tests that say what each visitor can do

A regression like the one Lovable describes breaks a behavior, not a function. So the test is about behavior, not implementation details: for every route and every kind of visitor, what should they get? These tests do not look inside the app, they were not run against any real app, and they only protect what the matrix lists. The last test is there for that reason: it fails when the app has a route the matrix does not list.

Save as authz.test.js, put the app in app.js, run npm i express, then node --test (Node 18 or newer, Express 5).

const test = require("node:test");
const assert = require("node:assert");
const { makeApp } = require("./app.js");
// Every route, and what each visitor should get. Add a row whenever you add a route.
const ROUTES = [
{ name: "list notes", method: "GET", pattern: "/notes", path: "/notes", owner: 200, other: 200 },
{ name: "read a note", method: "GET", pattern: "/notes/:id", path: "/notes/n1", owner: 200, other: 404 },
{ name: "edit a note", method: "PATCH", pattern: "/notes/:id", path: "/notes/n1", owner: 200, other: 404, body: { text: "changed" } },
{ name: "share a note", method: "POST", pattern: "/notes/:id/share", path: "/notes/n1/share", owner: 200, other: 404 },
{ name: "admin stats", method: "GET", pattern: "/admin/stats", path: "/admin/stats", owner: 403, other: 403 },
];
const TOKENS = { owner: "tok-alice", other: "tok-bob", admin: "tok-root" };
async function call(base, r, token, { headers = {}, body = r.body, auth } = {}) {
const h = { "content-type": "application/json", ...headers };
if (auth) h.authorization = auth; // send the header exactly as given
else if (token) h.authorization = `Bearer ${token}`;
return fetch(base + r.path, { method: r.method, headers: h, body: body ? JSON.stringify(body) : undefined });
}
async function withServer(fn) {
const { app } = makeApp();
const server = app.listen(0);
try { await fn(`http://127.0.0.1:${server.address().port}`, app); } finally { server.close(); }
}
const route = (name) => ROUTES.find((r) => r.name === name);
for (const r of ROUTES) {
test(`${r.name}: signed-out visitors are refused`, () => withServer(async (base) => {
assert.equal((await call(base, r, null)).status, 401);
}));
for (const who of ["owner", "other"]) {
test(`${r.name}: ${who} gets ${r[who]}`, () => withServer(async (base) => {
assert.equal((await call(base, r, TOKENS[who])).status, r[who]);
}));
}
}
for (const auth of ["Bearer constructor", "Bearer __proto__", "tok-alice"]) {
test(`an invented or malformed login (${auth}) is refused`, () => withServer(async (base) => {
assert.equal((await call(base, route("read a note"), null, { auth })).status, 401);
}));
}
test("a real admin can see admin stats", () => withServer(async (base) => {
assert.equal((await call(base, route("admin stats"), TOKENS.admin)).status, 200);
}));
test("claiming to be an admin in a header does not make you one", () => withServer(async (base) => {
const res = await call(base, route("admin stats"), TOKENS.other, { headers: { "x-role": "admin" } });
assert.equal(res.status, 403);
}));
test("a list shows each person only their own notes", () => withServer(async (base) => {
const bob = await (await call(base, route("list notes"), TOKENS.other)).json();
assert.deepEqual(bob.map((n) => n.id), ["n2"]);
}));
test("after Bob's blocked edit, Alice's note is unchanged", () => withServer(async (base) => {
await call(base, route("edit a note"), TOKENS.other);
const read = await call(base, route("read a note"), TOKENS.owner);
assert.equal((await read.json()).text, "alice secret");
}));
test("an owner cannot hand their note to someone else by editing owner", () => withServer(async (base) => {
await call(base, route("edit a note"), TOKENS.owner, { body: { text: "mine", owner: "bob" } });
assert.equal((await call(base, route("read a note"), TOKENS.other)).status, 404);
}));
test("an edit with no text is refused and the note keeps its text", () => withServer(async (base) => {
const res = await call(base, route("edit a note"), TOKENS.owner, { body: {} });
assert.equal(res.status, 400);
assert.equal((await (await call(base, route("read a note"), TOKENS.owner)).json()).text, "alice secret");
}));
test("every route the app has is in the matrix above", () => withServer(async (base, app) => {
const real = app.router.stack.filter((l) => l.route).flatMap((l) =>
Object.keys(l.route.methods).map((m) => `${m.toUpperCase()} ${l.route.path}`));
const listed = ROUTES.map((r) => `${r.method} ${r.pattern}`);
assert.deepEqual(real.filter((x) => !listed.includes(x)), []);
}));

Two kinds of test sit in there. Most of them fail on a broken app. A few, like “owner gets 200”, pass on a broken app too, and they are there for the other direction: they show that a fix does not lock out the people who should get in.

A first version often starts like this, app.js for the first run: login middleware that sets the user, routes that fetch by id, a share route added later with no login check, a list route returning everything, an update that copies the whole body, and an admin route that believes a header.

const express = require("express");
function makeApp() {
const users = { "tok-alice": { id: "alice", admin: false }, "tok-bob": { id: "bob", admin: false }, "tok-root": { id: "root", admin: true } };
const notes = new Map([
["n1", { id: "n1", owner: "alice", text: "alice secret" }],
["n2", { id: "n2", owner: "bob", text: "bob secret" }],
]);
const app = express();
app.use(express.json());
app.use((req, res, next) => { // authentication: who is this?
req.user = users[(req.headers.authorization || "").replace("Bearer ", "")];
next();
});
const needLogin = (req, res, next) => (req.user ? next() : res.sendStatus(401));
app.get("/notes", needLogin, (req, res) => res.json([...notes.values()]));
app.get("/notes/:id", needLogin, (req, res) => {
const n = notes.get(req.params.id);
return n ? res.json(n) : res.sendStatus(404);
});
app.patch("/notes/:id", needLogin, (req, res) => {
const n = notes.get(req.params.id);
if (!n) return res.sendStatus(404);
Object.assign(n, req.body);
res.json(n);
});
app.post("/notes/:id/share", (req, res) => res.json({ link: `https://x.test/s/${req.params.id}` })); // added later, no login check
app.get("/admin/stats", needLogin, (req, res) => {
if (req.headers["x-role"] !== "admin") return res.sendStatus(403); // role comes from the client
res.json({ users: 3 });
});
return { app };
}
module.exports = { makeApp };

Run in a scratch folder (Node 22, Express 5.3.0), 13 of the 25 tests fail:

not ok 6 - read a note: other gets 404
not ok 9 - edit a note: other gets 404
not ok 10 - share a note: signed-out visitors are refused
not ok 12 - share a note: other gets 404
not ok 16 - an invented or malformed login (Bearer constructor) is refused
not ok 17 - an invented or malformed login (Bearer __proto__) is refused
not ok 18 - an invented or malformed login (tok-alice) is refused
not ok 19 - a real admin can see admin stats
not ok 20 - claiming to be an admin in a header does not make you one
not ok 21 - a list shows each person only their own notes
not ok 22 - after Bob's blocked edit, Alice's note is unchanged
not ok 23 - an owner cannot hand their note to someone else by editing owner
not ok 24 - an edit with no text is refused and the note keeps its text
# tests 25
# pass 12
# fail 13

Read the list, because it shows all three failure modes. Bob can read, edit and list Alice’s notes (no check). The share route works signed out (added later, forgotten). A real admin is locked out while anyone who types a header gets in (the client decides). Test 22 shows real damage: Bob’s blocked edit changed Alice’s note. The naive login even accepts the “token” constructor, because a plain object has inherited names.

The fixed version, with the login check in one place:

const express = require("express");
function makeApp() {
const users = new Map([ // a Map, so a token like "constructor" is simply unknown
["tok-alice", { id: "alice", admin: false }],
["tok-bob", { id: "bob", admin: false }],
["tok-root", { id: "root", admin: true }],
]);
const notes = new Map([
["n1", { id: "n1", owner: "alice", text: "alice secret" }],
["n2", { id: "n2", owner: "bob", text: "bob secret" }],
]);
const app = express();
app.use(express.json());
app.use((req, res, next) => {
const m = /^Bearer (.+)$/.exec(req.headers.authorization || "");
req.user = m && users.get(m[1]);
if (!req.user) return res.sendStatus(401); // every route needs a login unless it says otherwise
next();
});
const ownNote = (req, res, next) => {
const n = notes.get(req.params.id);
if (!n || n.owner !== req.user.id) return res.sendStatus(404); // same answer for "missing" and "not yours"
req.note = n;
next();
};
app.get("/notes", (req, res) => res.json([...notes.values()].filter((n) => n.owner === req.user.id)));
app.get("/notes/:id", ownNote, (req, res) => res.json(req.note));
app.patch("/notes/:id", ownNote, (req, res) => {
if (typeof req.body.text !== "string") return res.sendStatus(400); // an empty edit must not wipe the note
req.note.text = req.body.text; // only the field we allow
res.json(req.note);
});
app.post("/notes/:id/share", ownNote, (req, res) => res.json({ link: `https://x.test/s/${req.params.id}` }));
app.get("/admin/stats", (req, res) => (req.user.admin ? res.json({ users: 3 }) : res.sendStatus(403)));
return { app };
}
module.exports = { makeApp };

All 25 pass. Adding a DELETE /notes/:id route to this app without a matrix row makes the last test fail, which is what it is for. In this model even an admin cannot read other people’s notes, because that is the rule the matrix encodes, so change the matrix to match your real rules. An in-memory app says nothing about your database policies or queries.

A prompt to paste into your AI tool

List every route and API function in this app. For each, tell me: does it require a login, does it check that the signed-in user may touch the specific record in the URL or body (show me the line), and where does it get the user’s role from? Flag any route that reads a role, user id or owner id from the request instead of the verified session. Then write a test matrix with one row per route and the status code each kind of visitor should get (signed out, owner, a different user, admin), plus a test that fails if a route is missing from the matrix. Do not change any code yet.

The check you can do by hand

Make two accounts. As the first, open the browser’s DevTools (right-click the page, Inspect, Network tab), do something with your own record, right-click that request and choose Copy as cURL. Paste it into a terminal, then swap in the second account’s login token and run it again. A token is the long string after Bearer or in a cookie that proves you are signed in. You should get a 404 or 403, never the data. Do it for every kind of record the app stores.

The 20-minute security check tests the same idea from the outside, and it is the best next step.

The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.

Comments