Broken access control and how to prevent it
Day 16 of our web security series: why the top risk on the OWASP list is so common, the shapes it takes in real applications, and the habits that prevent it.
Yesterday we met the OWASP Top 10. Today we take the item at the very top: broken access control. It has held first place since 2021, and in OWASP’s data it turned up in almost every application that was tested.
On Day 13 we covered the basic rule: logged in doesn’t mean allowed, and the server must check that this user may touch this record. Today we look at the different shapes the problem takes in real systems, why it keeps happening, and how teams prevent it for good.
What “access control” means
Access control is every rule that decides who can do what:
- Who can read a record, page or file.
- Who can change or delete it.
- Who can use a function, such as issuing a refund, inviting a user or changing a role.
It’s “broken” when any of those rules is missing, wrong or can be sidestepped.
Why it’s so common
Logins are built once, in one place, and tested by every user every day. Access rules are the opposite: they’re spread across every page, API endpoint and background job, and each new feature adds more. A single forgotten check in one of hundreds of places is enough. And because a missing check doesn’t break anything for normal users, nobody notices until someone goes looking.
The shapes it takes
Sideways: other users’ data
This is the classic from Day 13. A user changes an ID in an address or API call and gets another user’s order, invoice or message. Security people call it horizontal privilege escalation, or an insecure direct object reference (IDOR). The fix is an ownership check on every request.
Upwards: functions above your role
An ordinary user reaches something meant for staff or admins: an admin page, an export, a “change role” API. This is vertical privilege escalation. It usually happens because the interface hides the feature but the server never checks the role. Hiding a button is not a lock.
Some methods checked, others forgotten
A team adds a permission check to viewing a record, but not to the API that updates or deletes it. Or the main website checks permissions while the mobile app’s API, built later, doesn’t. Every route and every method needs the same rule.
Trusting what the client says about itself
Some applications store the user’s role or account ID in a cookie, hidden form field or token and then believe it. If the server reads role=admin from something the browser sends without verifying it, anyone can edit it (remember Day 2). Roles and ownership should come from the server’s own records, or from a token whose signature is always checked.
One customer seeing another company’s data
Software used by many businesses at once (multi-tenant SaaS) needs an extra rule: every query must be limited to the current customer’s data. Forgetting that filter once, in a report or search, can expose one company’s records to another.
Files and links left open
Uploaded files in a public storage bucket, predictable download links and “anyone with the link” sharing all bypass the application’s checks. Storage needs its own access rules.
Cross-origin doors left open
On Day 6 we saw how a loose CORS policy can let any website read responses meant for a logged-in user. That’s access control too, enforced by the browser on your behalf, and it only works if your server configures it narrowly.
Why it matters for security
Broken access control often leads straight to a data breach. The attacker doesn’t need to crack anything: they use a normal account and ask for data the server shouldn’t give them. Many large leaks of personal information started exactly this way, with an API that returned any record whose ID was supplied. Because the requests look ordinary, they can continue for a long time without being noticed.
How teams prevent it
Deny by default. Every route starts closed and is opened on purpose. A forgotten check then fails safely.
Centralise the rules. Put permission logic in one shared module or your framework’s policy system, and call it from everywhere. Scattered, hand-written checks are where gaps appear.
Check ownership in the query itself. Instead of loading a record and then checking it, ask the database only for records the user is allowed to see, for example “this order, belonging to this user”. If the record isn’t theirs, it simply isn’t found.
Use the server’s own facts. Take the user’s identity from the session, not from a field in the request. Never accept a role, account ID or tenant ID from the client without checking it.
Avoid relying on hidden IDs. Long random IDs make records harder to guess, which is a useful extra layer, but they are not a replacement for permission checks. Links get shared and logs get leaked.
Write tests for “should not”. Most tests check that features work. Add tests that check a user cannot see another user’s data, and that an ordinary user cannot call admin functions. Run them on every change, so a new feature can’t quietly remove a check.
Log and alert on denials. A burst of “access denied” responses from one account usually means someone is probing. Record them, and alert on unusual spikes.
Review access when people change roles. Remove staff access when people move teams or leave, and review admin accounts regularly.
What you can do today
If you use websites:
- Review who has access to your shared documents, folders and cloud storage, and remove anyone who no longer needs it.
- Turn off “anyone with the link” sharing for personal or financial files.
- If a site ever shows you someone else’s information, report it to the company through its security or support contact. Don’t explore further.
If you run a website:
- Make every route deny by default, and keep permission rules in one shared place.
- Filter database queries by owner and tenant, rather than checking after loading.
- Never trust roles, user IDs or tenant IDs sent by the client.
- Add automated “user A cannot see user B’s data” and “member cannot use admin function” tests.
- Log access denials and alert on spikes. The OWASP Top 10 entry on broken access control and the OWASP Authorization Cheat Sheet go into more detail.
Coming up next
On Day 17 we look at the root of many web vulnerabilities: why you never trust user input, and the basics of validating what comes in.