Broken access control and privilege escalation explained
TL;DR
Difficulty: Intermediate
Broken access control is when a logged in user does something they were never meant to be allowed to do. It is the OWASP Top 10 number one risk.
- Vertical escalation: an ordinary user reaches admin level actions. Horizontal escalation: a user acts as another user, reading their orders or data.
- Two classic doors: mass assignment, where a sign up form is tricked into setting a role, and hidden admin routes that are only hidden, not actually protected.
- AI makes it worse because the missing check is invisible: the happy path works in the demo and nobody notices the refusal that was never written.
- I defend with deny by default, authorisation in one place using Pundit policies, strong parameters so a role can never be set from a form, a properly guarded admin namespace, Cucumber tests that prove a normal user is refused, Brakeman, and a pen test with Kali tools before release.
A logged in user is not the same as an allowed user. Broken access control is the gap between the two: the person is who they say they are, and the application still lets them do something it never meant to. It is the number one risk on the OWASP Top 10, and it is almost always one missing line. Here is how it happens, what it costs, and how I close it in Ruby on Rails.
What broken access control actually is
Every serious web application does two separate jobs when it decides what you can see. The first is authentication: proving who you are, which is what a login does. The second is authorisation: deciding what you, now that we know who you are, are allowed to do. Broken access control is a failure of the second job. The person is logged in as themselves, perfectly honestly, and the application still lets them do something it was never meant to let them do.
That sounds small. It is the single most common serious flaw on the web. The Open Worldwide Application Security Project keeps a list called the OWASP Top 10, the agreed shortlist of the risks that hurt real applications most often. In the 2025 edition, broken access control sits at number one1. It is first because it is everywhere, because the damage is immediate, and because it is almost always a mistake of omission: a check that should have been written and was not.
It comes in two shapes, and a good defence has to cover both.
Vertical escalation is when an ordinary user does something only a higher privilege user should be able to do. A customer reaches an admin screen. A support agent gives themselves the manager role. This is what most people mean by privilege escalation: the user climbs the ladder of permissions.
Horizontal escalation is when a user stays at their own level but acts as a different user at that same level. One customer reads another customer's order, downloads their invoice, or changes the delivery address on an order that is not theirs. Nobody became an admin. One ordinary account simply reached into another ordinary account.
I will use one invented shop throughout. Oakwell Cycles is an online bike shop in Leeds (oakwellcycles.example), built on Ruby on Rails with a Solidus storefront. Customers have accounts with their order history and saved addresses. Staff have accounts too, with roles: support agents answer tickets, warehouse staff mark orders as shipped, and a manager runs the back office. The shop and its people are made up. The mistakes are real, and I have cleaned up versions of all of them.
How the attack actually works
Horizontal: reading another customer's order
When a logged in customer at Oakwell looks at an order, the address bar reads something like /orders/4812. That number is the order's database id, and it is sitting in plain view. The obvious thing to try, and attackers try the obvious thing first, is to change it to 4813 and press return.
Here is the controller that makes the attack work, simplified down to the one line that matters:
class OrdersController < ApplicationController
before_action :authenticate_user!
def show
# Looks the order up by the id in the URL and nothing else
@order = Order.find(params[:id])
end
end
The before_action :authenticate_user! line is doing its job: you must be logged in. But that is authentication, not authorisation. Once you are through the door, the code looks the order up purely by the number in the address bar. It never asks the only question that matters here: does this order belong to the person asking? Change 4812 to 4813 and you are reading a stranger's order, with their name, their address and what they bought. This exact pattern has a name of its own, insecure direct object reference, and it is the plainest form of horizontal escalation.
Vertical: becoming an admin through mass assignment of a role
Oakwell's sign up form asks for an email, a password and a name. When you submit it, the browser sends those fields to the server as a bundle of parameters. The server then builds a user from that bundle. The danger is in how much of the bundle it trusts.
A user record has more fields than the form shows. It also has a role, which is "customer" by default and can be "support", "warehouse" or "manager". If the code that creates the user simply hands the whole incoming bundle to the database, an attacker can add a field the form never displayed:
# The dangerous version: trust everything the browser sent
def create
user = User.new(params[:user]) # includes whatever was posted
user.save
end
Nothing stops a determined visitor from crafting a request by hand, with any tool that can send a form, that includes user[role]=manager alongside the email and password. The form in the browser never offered that field. The server accepted it anyway. The attacker signs up and is a manager before the welcome email arrives. Letting the client set a field it was never meant to set is called mass assignment, and when the field is a role, mass assignment is privilege escalation in one request.
Hidden admin routes that are not actually protected
Oakwell's back office lives under /admin. The link to it only appears in the menu when a manager is logged in. The team reasoned, understandably, that a customer who cannot see the link cannot reach the page.
Hiding the link is not protecting the page. The address /admin/products still exists on the server whether or not anything links to it. An attacker does not need the menu. They guess common paths, or read them straight out of the JavaScript the browser already downloaded, which often lists every route the application has. If the controller behind /admin/products does not itself check that the visitor is a manager, then typing the address is enough. This is called forced browsing, and it defeats security that lives only in the navigation.
What the attacker is actually after
None of this is done for the thrill of seeing one order. Follow each shape to its end and you find money, data and leverage.
Horizontal escalation turns a single login into a harvesting tool. The order numbers run in sequence, so a short script can walk from 1 upwards and pull every order the shop has ever taken: names, email addresses, postal addresses, phone numbers, what each person bought and when. That is a complete customer list, and a customer list with home addresses is worth real money to people who send convincing phishing emails or resell personal data. Under UK and EU data protection law this is a personal data breach, which means notifying the Information Commission inside seventy two hours where there is a risk to people, and very possibly telling every affected customer2. The engineering mistake was one missing line. The bill is legal, financial and reputational.
Vertical escalation is worse, because an admin account is the shop. From the back office an attacker can change prices, issue refunds to a card they control, read every customer's details at once, export the whole database, quietly add a discount code for themselves, or plant a malicious script in a product description that then runs in every shopper's browser. They can also create a second hidden admin so that closing the first account changes nothing. One over trusting sign up form, and the business is no longer in control of its own shop.
This is not theoretical for the stack I build on. Solidus, the commerce engine behind Oakwell, published an advisory in 2026 describing exactly this: a back office user with permission to manage other users could assign themselves the admin role or reset an admin's password3. A separate 2026 advisory described admin forms that accepted more attributes than they should, the mass assignment problem again, this time inside the official software rather than anyone's custom code4. These are careful, well reviewed projects, and the flaw still reached release. That is how ordinary this mistake is.
How AI has raised the risk
A large share of new application code is now written with an AI assistant, and a growing share of it is written by people who could not have written it themselves. The code runs, the demo works, and nobody in the room can say what the code does not do. Access control is precisely the thing that lives in what the code does not do, so it is precisely the thing this way of working misses.
The measured picture is not reassuring. Veracode's 2025 GenAI Code Security Report found that AI generated code contains about 2.74 times more vulnerabilities than human written code5. A 2025 analysis by Ox Security of more than three hundred repositories found the same ten anti patterns recurring in 80 to 100 per cent of AI generated code6. Other research has found that roughly 45 per cent of AI generated code introduces a weakness from the OWASP Top 10, the very list broken access control tops7. And the problems do not get quietly fixed later: a 2026 study of more than 304,000 commits found that 24.2 per cent of the issues AI introduced were still unresolved over the life of the project8. The Georgetown Center for Security and Emerging Technology reached the same conclusion from the policy side in 2024, and CrowdStrike's 2025 research on AI written code pointed the same way9.
There is a specific reason this attack in particular slips past an AI. An authorisation check has no visible effect when everything is going right. Ask an assistant to build a page that shows an order, and the natural, demonstrably working answer is Order.find(params[:id]): it renders the order, the screenshot looks correct, the task appears done. The missing clause, "and only if it belongs to the person asking", produces no output and so does not announce its absence. The same goes for the sign up form: a permissive parameter list is shorter and makes the happy path work, so it is the easy thing to generate. And when asked to keep an admin page away from customers, hiding the link is the change that makes the interface look right in a screenshot, while guarding the route is invisible work nobody can see in a demo. AI is very good at making the happy path work. Broken access control is a failure on the unhappy path, where nobody was looking.
How I defend against it
The whole defence rests on one principle: deny by default. Every action starts from "no", and access is granted only by an explicit rule you can point to. A missing rule then fails safely, as a refusal, instead of failing open as a silent yes. Here is how I put that into a Rails and Solidus application.
Authorise every action in one place. I do not scatter permission checks through the views and hope they line up. I put them in policy objects with a library called Pundit, so that the rule for "who may see this order" lives in exactly one file and reads like a sentence.
class OrderPolicy < ApplicationPolicy
# An order is visible to the customer who placed it, or to staff
def show?
record.user_id == user.id || user.staff?
end
end
The controller then asks the policy rather than trusting the URL, and the ownership check that was missing earlier is now impossible to forget:
def show
@order = Order.find(params[:id])
authorize @order # raises and refuses unless show? is true
end
If a developer later adds a new action and forgets to authorise it, Pundit can be told to treat that as an error and refuse, so the default really is "no". The point is that authorisation is checked on every action, by the code that performs the action, not by whether a link happened to be shown.
Stop mass assignment with strong parameters. Rails has a built in gate for the bundle of fields a browser sends. I list the fields a form is allowed to set, and nothing else gets through, no matter what the request contains:
def user_params
# role is deliberately absent, so it can never be set from a form
params.require(:user).permit(:email, :password, :name)
end
A role is changed only through a dedicated staff action that is itself behind its own policy, never as a side effect of a visitor editing their own profile. user[role]=manager in the request now goes nowhere.
Protect the admin namespace at the door. The back office is not defended by hiding its link. It is defended by a check that runs before any admin controller does its work, so that typing /admin/products by hand lands on the same refusal as everything else:
# config/routes.rb
authenticate :user, ->(u) { u.manager? } do
mount Solidus::Admin::Engine, at: "/admin"
end
A visitor who is not a manager never reaches the admin code at all. Forced browsing finds a locked door, not an unguarded room.
Lock the defence in with a test the business can read. A check you added once can be deleted by accident next month. So I write the rule as an executable scenario with Cucumber, in plain language, and it runs on every change:
Scenario: a customer cannot open another customer's order
Given I am signed in as the customer "Priya"
And another customer "Tom" has placed order 4813
When I visit "/orders/4813"
Then I should be refused
And I should not see Tom's delivery address
There is a matching scenario for the sign up form, which posts a role of manager and then checks the new account is still an ordinary customer, and one that signs in as a customer, visits /admin/products directly and expects a refusal. These scenarios are the opposite of the happy path. They describe a normal user being told no, and they fail loudly the day someone removes a guard.
Read the code with Brakeman, then try to break it with real tools. Brakeman is a static analyser made for Rails. It reads the code without running it and flags exactly these patterns: mass assignment, unscoped record lookups, routes with no authorisation. It runs on every build, so a regression is caught before release10. Then, before a shop goes live, I pen test it with the same tools an attacker uses, from a Kali Linux machine: Burp Suite and OWASP ZAP to log in as a low privilege user and then deliberately request higher privilege pages and other users' records, and their automated access control checks to walk the object ids and the hidden routes the way the attacker would. Static analysis finds the missing check in the code; the pen test proves the running application refuses.
Why testing and pen testing make this insurable work
Broken access control is unusual among serious flaws in that you cannot see it by using the application normally. The happy path looks perfect. The only way to know the shop is safe is to try the unhappy path on purpose and watch it fail safely, and the only way to keep it safe is to make that attempt part of the build so it is repeated forever.
That is why I build the way I do. The code is owned and readable, not a black box: every authorisation rule sits in a named policy file a person can read in one sitting. Every one of those rules has a scenario in plain language that proves a normal user is refused, and those scenarios run on every change and block a release if any one of them goes red. The pen test is written down, with what was attempted and what the application did. When a client, an insurer or an auditor asks "can an ordinary customer reach the admin, or read another customer's order", the answer is not "I believe not". It is a file they can read and a test they can run. That is the difference between hoping a shop is secure and being able to show that it is.
A quieter note to close
Almost every broken access control story ends the same way: one missing line, written by someone who meant well, on a path nobody thought to walk. The fix is never clever. It is the discipline of deny by default, authorisation in one place, strong parameters, a properly guarded admin, and a set of tests that keep trying the attack long after everyone has moved on.
If you are not sure whether your own shop or application would pass that test, that is worth an hour. In the free workshop we take one real screen, your orders page or your sign up form, and I show you the three requests an attacker would send and whether your application says no. No slides, no hard sell. You leave knowing where you stand, and the first two weeks of any work we agree are on me.
