Web apps & CRM ·
Web app security basics: roles, sessions and audit logs
The security basics I build into every CRM, dashboard and portal: logins, sessions, permission checks, input handling and audit logs, explained for business owners.
By Kareem Mohamed, Web Developer at Digital House
Web application security for a business app is less about exotic attacks and more about a handful of basics done every time: who can log in, how long they stay logged in, what they are allowed to touch, and whether you can tell afterwards who did what. These are the basics I build into every CRM, dashboard and portal, explained for the people who own them.
Authentication: proving who someone is
Authentication is the login: checking that a person is who they claim to be. It is the front door, and most of its rules are well known. The problem is that they are easy to skip when a deadline is close.
- Passwords are hashed with a deliberately slow algorithm such as bcrypt or Argon2, never stored or emailed in plain text.
- Login attempts are rate-limited, so nobody can guess passwords at speed.
- Two-factor authentication is available to everyone and required for admins.
- Password reset links expire quickly and work only once.
- Invitations, not shared accounts. Every person has their own login, which makes everything else in this article possible.
Sessions and tokens: staying logged in safely
After login, the app has to remember who you are on every request. That memory is a session or a token, and it is what attackers try to steal, because it skips the password entirely.
- Tokens are signed by the server, so they cannot be altered in the browser.
- They live in secure, httpOnly cookies that scripts on the page cannot read.
- They expire, and sensitive actions such as changing a password or exporting data ask for the password again.
- Removing a user ends their access straight away, not whenever their token happens to expire.
The token also carries identity the server can trust. In Step, the multi-tenant platform I built for Saudi real-estate offices, the office a user belongs to is read from the signed token and nowhere else: never from the URL, the form or a header the browser could change.
Permissions: checking every request on the server
Authorisation is the second question: now that we know who you are, are you allowed to do this? Broken access control sits at the top of the OWASP Top 10, the best-known list of web application risks, and it usually looks innocent: a page that is hidden from a user, while its API still answers them.
Hiding a button is not a permission. Every request has to be checked on the server, against the role and against the specific record.
const can = {
admin: ['deal:read', 'deal:edit', 'deal:delete', 'user:manage'],
sales: ['deal:read', 'deal:edit'],
viewer: ['deal:read'],
};
const allow = (perm) => (req, res, next) =>
can[req.user.role]?.includes(perm) ? next() : res.status(403).end();
async function loadDeal(req, res, next) {
const [[deal]] = await db.query(
'SELECT * FROM deals WHERE id = ? AND company_id = ?',
[req.params.id, req.user.company_id]
);
const notTheirs = req.user.role === 'sales' && deal?.owner_user_id !== req.user.id;
if (!deal || notTheirs) return res.status(404).end();
req.deal = deal;
next();
}
app.patch('/api/deals/:id', auth, allow('deal:edit'), loadDeal, updateDeal);
Two checks run on that route: the role must allow editing, and the deal must belong to this company and, for a sales agent, to this person. Miss either one and a customer can end up reading another customer’s data.

Input handling: never trust what arrives
Everything that comes from a browser can be changed by the person using it, including hidden fields, prices and ids. Treat it as a suggestion to be checked, not a fact.
- Parameterised queries for every database call, so input is never stitched into SQL. That closes the door on SQL injection.
- Validation on the server for type, length and allowed values, even when the form already checks.
- Recalculate anything that matters. Totals, discounts and VAT are computed on the server from the line items, never accepted from the browser.
- Escape output, so a customer name containing a script tag displays as text instead of running.
- File uploads are limited by type and size, renamed, and stored outside the public folder.
Audit logs: knowing who did what
An audit log is a record of every important action: who, what, when and from where. It turns “someone changed the price” into a name and a time, and it settles disputes quickly, inside the team and with clients.
The Digital House dashboard keeps an activity log behind its roles, and Step goes further for money: rows created automatically from invoices and contracts have no edit or delete path at all. Corrections are new entries, so the history cannot be quietly rewritten.
CREATE TABLE audit_log (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
user_id INT NOT NULL,
action VARCHAR(40) NOT NULL, -- 'invoice.issue', 'user.remove'
record_type VARCHAR(40),
record_id INT,
changes JSON, -- values before and after
ip VARCHAR(45),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
The application’s database user should be able to add to this table and read it, but never update or delete rows. Enforce that with database permissions, not only in code.
Habits that keep an app safe after launch
Security is not finished at launch. Most of the work afterwards is routine, and it only protects you if someone actually does it.
- Secrets stay out of the code. Database passwords and API keys live in environment variables on the server, never in the repository or the browser.
- The database user has only the rights it needs: no permission to drop tables, and no access to other systems’ databases.
- Dependencies are updated on a schedule, with security fixes applied promptly rather than at the next big release.
- HTTPS everywhere, including the admin area and any internal tools.
- Staging uses fake or anonymised data, so a test server never becomes a copy of your customer list.
- Leavers lose access on their last day, across the app, the hosting and the code repository.
What should a business owner ask their developer about security?
- Where are passwords stored, and how?
- Is two-factor login available, and is it required for admins?
- If I remove a user today, when does their access actually end?
- Is every API request checked for role and ownership on the server?
- Can you show me the audit log for one of our records?
- How are backups made, where are they kept, and when was one last restored?
- Who is told, and how quickly, if something goes wrong?
Good answers are short and specific. For your public website, the website security checklist covers hosting and plugins. For systems shared by many client companies, six rules I never break in a multi-tenant SaaS goes deeper. And in the custom CRM development guide, security is its own stage that comes before the money, not after it.
Security in a business app is mostly boring rules, applied on every request, without exceptions.