Authentication vs authorization: who you are vs what you can do
Two words that sound alike and fail in very different ways. Authentication proves identity once; authorization has to be checked on every single request, for every single resource.
In one sentence
Authentication answers *who are you?* Authorization answers *are you allowed to do this, to this thing, right now?* Most breaches of web apps are the second one missing.
Two different questions
When Ana logs in with her password, the server authenticates her: it now knows that requests carrying her session cookie come from Ana. That's all it knows.
When Ana then asks for invoice 43, a second question must be asked: does invoice 43 belong to Ana, or does Ana have a role that lets her see other people's invoices? That's authorization, and it depends on the user, the action and the specific resource.
Ways to decide what someone can do
| Model | Rule looks like | Good for |
|---|---|---|
| Ownership | user.id === invoice.ownerId | Personal data: orders, messages, files |
| RBAC (roles) | user.role in ['admin', 'support'] | Back offices with a few clear job types |
| ABAC (attributes) | same team AND document not archived AND office hours | Complex enterprise rules |
| ReBAC (relationships) | user is editor of folder that contains the doc | Sharing models like Google Drive |
// Authorization lives next to the data access, on the server
const invoice = await db.invoice.findUnique({ where: { id } });
if (!invoice || invoice.ownerId !== session.userId) {
return new Response("Not found", { status: 404 });
}
return Response.json(invoice);Where it goes wrong
- Hiding the button instead of checking on the server. The UI isn't a security control; anyone can call the API directly.
- Checking once at login. Roles change, users get removed from teams: decide on each request.
- Trusting IDs or roles sent by the client.
role=adminin a request body or an unsigned cookie is a wish, not a fact. - One check per endpoint, not per resource. "Is logged in" passes; "owns this record" was never asked.
Key takeaways
- 01Authentication = identity. Authorization = permission for this action on this resource.
- 02Authorization must be checked on the server, on every request.
- 03Never trust roles, IDs or prices coming from the client.
- 04Deny by default and return 404/403 when the user doesn't own the resource.
Check your understanding
1 of 3
Authorization answers which question?
Related concepts
Access control & IDOR
If `/api/orders/1042` works for a user who doesn't own order 1042, that's an IDOR. Every query that loads a record by ID must also filter by who's asking.
7 min read →Sessions & cookies
A session cookie is as good as a password while it's valid. Ship it as HttpOnly; Secure; SameSite=Lax, keep it short-lived, and rotate it on login and privilege changes.
7 min read →JWT
A JWT is base64, not encryption: anyone can read it. Its signature only proves the server issued it, and only if you verify it with a fixed algorithm and check the expiry.
8 min read →