Many small custom web apps have the same story. The first version had one login, the owner's. Then staff joined, then a client portal was added, and every new person got an admin account because that was the only kind there was. Six months later, the intern can delete invoices and a client can see another client's orders by changing a number in the URL.
Each of those problems started at the planning stage. So before we write a feature list for an admin panel, portal or small CRM, we write down who can do what. It takes an hour and it saves a rewrite. If you're on the buyer's side, our guide to custom CRM development in India covers roles and ownership from the business angle; this post is the developer half.
Why bother this early
Access control is the top risk on the OWASP Top 10:2025. OWASP's A01 page says 100% of the applications tested had some form of broken access control. On a small app the cause is rarely clever. It's usually a route nobody thought to protect, or a record ID nobody thought to check.
It's also much cheaper to start strict. OWASP's Authorization Cheat Sheet makes the point that it's easier to grant users more permissions later than to take away ones they already have.
Step 1: list the people, not the roles
Start with real job titles from the business: owner, office manager, sales rep, accountant, delivery staff, client. Don't start with "admin, editor, viewer". Those words hide the questions you need to ask.
For each person, write one line: what do they come to the app to do? "The accountant comes to download invoices and mark them paid." That single line usually tells you most of their permissions.
Step 2: list the things, then the actions
Write the main records in the app (orders, invoices, customers, products, users, settings) down the side. Across the top, the actions: view, create, edit, delete, export. Export gets its own column because it's how data leaves the building.
Then fill the grid with three marks:
| Record | Owner | Office manager | Sales rep | Accountant | Client |
|---|---|---|---|---|---|
| Orders | all | all except delete | view + create own | view | view own |
| Invoices | all | view | none | all except delete | view own |
| Customers | all | all except delete | view + edit own | view | none |
| Users | all | none | none | none | none |
| Export | yes | orders only | no | invoices only | no |
The word that matters most in that table is "own". "View own orders" for a sales rep or a client is a rule about the relationship between the person and the record, not about their role. That's the part simple role checks miss.
Step 3: decide the default is "no"
Every cell you didn't fill is "no". OWASP calls this deny by default: the app should be able to justify each permission it grants, instead of assuming access and blocking a few cases. In code, that means your check returns false at the bottom, not true.
// One place for every permission decision.
function can(user, action, record) {
if (user.role === 'owner') return true;
if (record.type === 'order') {
if (action === 'view' && user.role === 'client') {
return record.clientId === user.clientId; // "own" rule
}
if (action === 'create' && user.role === 'sales') return true;
}
return false; // anything not listed is denied
}
It's plain on purpose. One function, used by every route, is easier to review than checks scattered across forty controllers. OWASP's cheat sheet also asks for checks on every request, through app-wide middleware rather than per-method code, because one missed check is enough.
Step 4: check the record, not just the route
This is often where the bugs live. A route like /orders/1042 is protected so only logged-in clients can reach it. But nothing checks that order 1042 belongs to the client asking. Change the number, see someone else's order. OWASP names this Insecure Direct Object Reference (IDOR).
Random IDs such as UUIDs make guessing harder, and OWASP's IDOR cheat sheet notes they help. But it's clear that access checks are still essential, because IDs leak in emails, screenshots and shared links. The fix is the "own" rule from step 2, applied on the server for every read and write.
If the app runs on PostgreSQL, you can add a second lock at the database. With row level security enabled on a table, every normal read or write has to be allowed by a policy, and if no policy exists, no rows are visible.
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
-- Clients only see their own orders.
CREATE POLICY client_own_orders ON orders
FOR SELECT
USING (client_id = current_setting('app.client_id')::int);
Two cautions from the PostgreSQL docs: superusers and roles with BYPASSRLS skip these policies, and the table owner normally does too unless you use FORCE ROW LEVEL SECURITY. So if your app connects as the table owner, the policy may do nothing. Treat it as a backstop, not the only check.
Step 5: test with two accounts of the same role
Most testing happens with one admin login, which finds nothing. Make two client accounts and two sales-rep accounts with different data. Log in as one and try to open, edit and export the other's records, including through the API, not just the screens. OWASP's IDOR cheat sheet suggests the same: several test accounts with different scopes.
Add these as automated tests once the matrix is stable. Every new feature then gets a row in the grid before it gets a screen.
What goes in the scope doc
We put three things into the project scope before any feature work:
- The people list with one line each (step 1).
- The grid with "own" rules marked (step 2).
- A short note on who can create users and change roles. Usually the owner only.
Clients understand the grid straight away, because it's their business, not our code. And when they ask for a feature later, the first question is easy: which row and which column?
Brightcode is a web development team in Delhi NCR, India. We build business websites and custom web apps such as portals, admin panels and small CRMs. If you're budgeting one, our guide to custom software development cost in India explains what drives the price. Reviewed by Gaurav Khokkar, Founder.
Top comments (0)