Authorization decides what an authenticated user, or an anonymous visitor, may do. Logging in proves identity. It does not grant everything.
Check every request
The server must check permission on each request that touches protected data. Hiding a button or menu item is only presentation. A user can send the request directly:
curl -i -b jar.txt -X DELETE https://app.example.com/users/42For an ordinary user this should return 403 Forbidden and change nothing. Without valid login it should typically return 401.
Object level checks
Being allowed to view invoices does not mean being allowed to view every invoice.
GET /invoices/1001 your invoice: 200
GET /invoices/1002 someone else's: 403 or 404If changing the number reveals another customer's data, that is broken object level authorization, often called IDOR. Check ownership in the query itself, for example "invoice 1002 and owned by this user". Random identifiers make guessing harder but do not replace the check. Some sites return 404 to avoid confirming that the object exists.
Models and principles
- Role based: permissions attach to roles such as
vieweroradmin. - Attribute based: rules use facts such as owner, department or time.
Deny by default: if no rule allows an action, refuse it. Least privilege: grant only what the job needs. Put the logic in one shared place so that a new page cannot easily forget it.
Take identity and role from the server's session or a verified token, never from a field the client can edit, such as ?role=admin. Also limit which fields a user may update, so a profile form cannot be used to set a role.
Test the refusals
Tests often confirm only that allowed users succeed. Add tests where the wrong user tries and is refused, for reading, changing and deleting. Log denied attempts, since many of them in a row deserve a look.
Linux uses the same idea for files: the system checks owner, group and others on access. The permissions lab shows this directly.
Try it
In a test copy of your application, create two ordinary accounts. Log in as the first and request an object belonging to the second. You should be refused. Repeat for update and delete requests, then confirm the data is unchanged.
Check your understanding
Authorization
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.