What you'll learn: By the end of this lesson you will be able to define identity, authentication and authorization and keep them apart, say which part of a system enforces each, explain why hiding a control in the UI is a usability feature and not a security control, choose between
401and403handling in the client, and design a UI that reads permissions from the server without being trusted to decide them.
A hotel gives you a key card at reception. The clerk checks your passport (that is authentication: are you who you say you are?) and then encodes the card for room 412 and the gym (that is authorization: what may you open?). The lift has buttons for every floor, but the button for floor 9 does nothing for your card. Now suppose a guest paints over the floor 9 button. Nothing changes: the doors still check the card. The painted button is a courtesy. The door lock is the security.
A web page has the same two layers. The browser draws the buttons. The server owns the doors. This lesson is about telling them apart, because most access-control mistakes in front ends come from treating the painted button as a lock.
The core idea
Hold on to three words and one rule.
- Identity is a representation of who or what is making a request. OWASP's authentication guidance calls a digital identity "the unique representation of a subject engaged in an online transaction".
- Authentication is "verifying that an individual, entity, or website is who or what it claims to be" (OWASP). It answers who are you?
- Authorization is "verifying that a requested action or service is approved for a specific entity" (OWASP). It answers what may you do?
- The rule: the code that decides must run where the user cannot change it. OWASP's Top 10 entry on broken access control says access control is only effective when implemented in trusted server-side code or serverless APIs.
Two things follow. Authentication comes before authorization: you cannot decide what an entity may do until you know which entity it is (or that it is anonymous). And the UI only reports and requests: it shows what the server says is allowed and asks the server to act, and the server decides each time.
The standards use the same split. NIST's Digital Identity Guidelines (SP 800-63-4) treat identity proofing, authentication and federation as separate subjects. RFC 6749, the OAuth 2.0 framework, gives the resource server and the authorization server different jobs: the first accepts access tokens for protected resources, the second issues them after authenticating the resource owner. Token flows come later in this module; here only the vocabulary matters.
Figure 1. Who enforces what
How to read this: only the three boxes in the zone are trusted, because a user cannot edit them. The UI on the left is the user's code in the user's browser. It can be changed, bypassed or replaced by any program that can send the same request.
What the browser can do, and what it cannot
The UI's job has four parts, and none of them is "decide".
- Hold the session state. Signed out, signed in, or expired. The client knows this only as the server last told it.
- Send credentials correctly. Cookies or an
Authorizationheader, as the earlier lessons on fetch and CORS describe. - Shape the experience. Hide a "Delete" button the user may not use, send a signed-out visitor to sign in, show a clear message for a refused action. This is usability: less clutter and fewer dead ends.
- React to the verdicts. A
401and a403need different screens.
What it cannot do is enforce. The browser runs on the user's machine. Any value the page holds (a role name, a flag, a decoded token) can be changed there, and any request the page can send, another client can send without the page at all. A check that exists only in the UI protects nothing; it decides what honest users see.
| Question | Where it is answered | Whether the browser can be trusted |
|---|---|---|
| Is this person who they claim to be? | Server or identity provider | No |
| What may this person do or read? | Server, per request | No |
| Should this button be shown? | Browser, from data the server sent | Yes, for presentation only |
401, 403 and what the client does next
HTTP separates the two failures. MDN says a server that receives invalid credentials should respond with 401 Unauthorized and the client may send a new request, and that a server that receives valid credentials that are inadequate for the resource should respond with 403 Forbidden, after which "authentication is impossible for this user and browsers will not propose a new attempt". MDN's 403 page says that for 403, authenticating or re-authenticating makes no difference.
The client's reaction follows from that.
| Response | Meaning | Client behaviour |
|---|---|---|
401 |
Not authenticated, or credentials invalid or expired | Go to sign-in, remember where the user was, return after success |
403 |
Authenticated, but not permitted | Show a "no access" state; do not send to sign-in, since signing in again changes nothing |
404 instead of either |
The server hid the resource's existence | Show "not found"; MDN notes a server may prefer 404 for this reason |
Figure 2. One request, two decisions
How to read this: the two checks happen in order, on the server, for every request. The browser's reactions in the right column are all it does with the answer.
Illustration 1 (minimal example): the painted button. A page hides a delete button unless the user's role is admin:
// Sketch for illustration. It is not part of a tested lab.
function OrderRow({ order, role }: { order: Order; role: string }) {
return (
<li>
{order.id}
{role === "admin" && <button onClick={() => deleteOrder(order.id)}>Delete</button>}
</li>
);
}
For an honest non-admin the button is gone, and that is good UX. But the check proves nothing to the server. The real control is on the other side of deleteOrder:
// Sketch for illustration, server side. It is not part of a tested lab.
app.delete("/orders/:id", requireAuthenticated, async (req, res) => {
const order = await orders.find(req.params.id);
if (!order || !canDelete(req.user, order)) return res.sendStatus(403); // deny by default
await orders.remove(order.id);
res.sendStatus(204);
});
canDelete runs on every call, whatever the page did. If it is missing, the hidden button changes nothing about who can delete orders.
UI gating is for users, not for security
OWASP's authorization guidance states the server-side duties plainly. Deny by default: the application must always decide, implicitly or explicitly, to deny or permit the request. Validate the permissions on every request: an attacker only needs one way in, so checking most requests is not enough. Enforce least privilege, since it is easier to grant permissions than to take them away. Centralize the handling of failed checks. Those are properties of the server.
The UI may legitimately hide what a user cannot use, disable it with an explanation, or pre-check a form. All three are conveniences and all go stale: permissions change while a page is open, so the server's answer may disagree with what the UI showed.
Where the UI gets its permissions. The robust pattern is to let the server say what the current user may do, and render from that: a response such as GET /me that returns the user and a list of capabilities ("orders:refund"). The UI reads the list to draw the screen; the server still checks the same capability on the action. The list is a hint with an expiry, and the next section shows why.
Figure 3. The three layers of a protected screen
signed out: go to sign-in"] --> B["Controls on the page
shown from server-sent capabilities"] B --> C["API call"] C --> D["Server: authenticate and authorize
every request, deny by default"] D --> E["Data or action"] A -. "usability only" .-> B B -. "usability only" .-> C
How to read this: the first two layers shape what people see. Only the third protects anything. A missing browser layer makes the product worse; a missing server layer makes it unsafe.
Illustration 2 (realistic example): a staff dashboard with refunds
A shop's staff dashboard has three screens: orders, refunds and settings. Support staff may view orders; finance staff may also issue refunds; only administrators see settings. The page loads, calls GET /me, and gets back the user and a capability list. A route guard sends signed-out visitors to sign-in, and the Refund button shows only when the list contains orders:refund.
On the server, POST /orders/1042/refund checks that the caller has orders:refund and that this order is one they may refund. In the UI, a 401 anywhere goes to sign-in with the path remembered, a 403 shows a "no access" panel, and a 404 shows "not found". These policies live in one wrapper around fetch, so no component handles them its own way.
Illustration 3 (failure case): the order that was never yours
The orders page lists only the signed-in customer's orders, and each row links to /orders/1042. The server checks that the caller is signed in, and then loads whatever order the id names. The UI never shows another customer's orders, so it looks correct in every test. But the endpoint authenticates without authorizing: it asks "is this a signed-in person?" and never "is this their order?". This is the pattern OWASP calls Insecure Direct Object Reference: access to objects by manipulating the identifiers in URLs or parameters. OWASP's top-ten entry lists "permitting viewing or editing someone else's account by providing its unique identifier" among the common weaknesses of broken access control.
Hiding other orders in the UI does nothing for the endpoint. Hard-to-guess ids help, but OWASP's IDOR guidance says that even with complex identifiers, access control checks are essential, because anyone who obtains a URL should still be blocked. The fix is on the server: check ownership on every request for the specific object.
Choosing where checks live
| Check | Gains | Costs |
|---|---|---|
| UI only | Quick; nice UX | No security at all |
| UI plus route guard | Clean flows for honest users | Still no security |
| Server check on every request | The only layer that protects data | Must be done in every handler or in shared middleware |
| Server check plus capabilities for the UI | Honest UX and real protection from one source of truth | The capability list can go stale; the UI must handle 403 |
| A back-end-for-front-end layer that holds the session | Tokens kept out of page code | One more service; it must still authorize |
In practice: a role is removed while a page is open
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
A finance team member changes teams and the administrator removes their refund permission. The dashboard is still open in a tab from the morning.
Starting architecture
Figure 4. A capability list that can go stale
How to read this: the list was true at 09:00 and the tab never asked again. The refund endpoint reads the permission store at the moment of each action, so it is the one that is right at 11:30.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Trust the loaded list until reload | Nothing; the status quo | None | The Refund button stays visible, and clicks fail |
Refetch capabilities on focus and on every 403 |
The UI follows the server quickly | An extra call | A small delay before the screen updates |
The decision
| Field | Decision record |
|---|---|
| Context | Permissions change while pages are open; the server already checks every action. |
| Decision | Keep server checks as they are. On any 403, refetch the capability list, redraw, and show a clear message. Also refetch when the tab regains focus. |
| Consequences, good | A removed permission shows in the UI within one interaction; no retry loop. |
| Consequences, bad | One more request on focus and on each 403. |
| Revisit when | Permission changes must reach open tabs immediately, which would justify a push channel. |
Rollout and verification
- Test the stale case: load the page, remove the permission on the server, click the button. The server must return
403and the UI must show the message and refresh the list. - Test every verdict: a
401goes to sign-in with the return path, a403shows "no access", and neither is retried. - Check the server separately: call the refund endpoint directly as a user without the capability and confirm
403.
The 2 a.m. failure
Support reports a "Refund failed" toast loop. The server is behaving correctly. The client treats any non-success as transient and retries with backoff, so it repeats a 403 that can never succeed.
First three checks: (1) read the status code of the failing call: it is 403, not 5xx; (2) check the client's retry rule for 4xx; (3) check whether the capability list was refreshed after the verdict. Mitigation: stop retrying 403 and show the no-access state. Follow-up: keep the verdict policy in the one wrapper, add a test for 401, 403 and 404, and alert on repeated 403s from one client.
The other side of this topic
The server owns the check and the model behind it: who the user is, which roles, attributes or relationships grant which actions, and how a decision is made and logged. The back-end view is in Authentication and Authorization Basics and System Design: Security. A front end consumes the result: a session state, a capability list, and a verdict on each call.
Architect's notes
- Put the decision where users cannot edit it. If it is only in the browser, it is not a control.
- Render from server-sent capabilities, not from a role name you hard-code in many components.
- Handle
401and403in one place, with different behaviour: sign-in versus no-access. - Treat capability lists as expiring hints. Refresh them on
403.
Common mistakes
- Hiding a control and calling it protected. The endpoint is still there.
- Checking "signed in" and stopping. Authentication without per-object authorization is the IDOR pattern.
- Sending a
403user to sign-in. Signing in again changes nothing. - Trusting a role read from browser storage to enforce anything.
Key takeaways
- Identity is who, authentication proves it, authorization decides what that identity may do.
- Authentication comes first; both checks run on the server on every request.
- The browser draws and asks. It can be changed or bypassed, so UI checks are usability, never security.
401means credentials are missing or invalid and a new attempt may help;403means authenticated but not permitted, and retrying or re-signing-in will not help.- The server should tell the UI what the user may do; the UI treats that as a hint that can go stale.
- Checking only that someone is signed in, without checking the object, is a broken access control.
Practice exercises
Exercise 1: Starter (30 min). List five controls in a project that are shown or hidden by role. For each, find the server endpoint behind it and write down what it checks.
Exercise 2: Intermediate (2 hours). Write a fetch wrapper that classifies 401, 403 and 404 into three result kinds, and tests for each. Make sure 403 is never retried.
Exercise 3: Advanced (half day). For one resource type, write the authorization rule per action (view, change, delete), name the handler that enforces each, and describe how a stale capability list is corrected.
Related reading
In this course:
- The Same-Origin Policy and CORS and CORS in Practice: Preflights, Credentials and Debugging, for how credentials cross origins and why CORS is not access control.
- API Integration Basics: Fetching, Headers and Failure, the call and its failure kinds.
- Client Retries and Backoff, why a
403must not be retried. - Error, Loading and Empty States, designing the "no access" screen.
- Backend for Frontend, a layer that can hold the session.
- Auth and Shared Session in Micro-Frontends, when several apps share one sign-in.
Official documentation
- OWASP Authorization Cheat Sheet, deny by default, least privilege, validating on every request.
- OWASP Authentication Cheat Sheet, definitions, generic errors, TLS and multi-factor.
- OWASP Top 10 2025: A01 Broken Access Control, server-side enforcement and common weaknesses.
- MDN: HTTP authentication,
401,403and the challenge and response flow. - NIST SP 800-63-4: Digital Identity Guidelines
- RFC 6749: The OAuth 2.0 Authorization Framework, for the role names and the access token definition.