iwebforyou
Start a Project
All articles

SaaS

Roles and permissions in a SaaS before the code

The roles and permissions of a SaaS are written before the code, as a table showing which role does what. The base is three OWASP rules: least privilege, deny by default and a check on every request at the server. The result is verified with tests.

Publisher: iwebforyouPublished Updated 5 min read

Roles and permissions in a SaaS before the code

In a SaaS platform, not everyone sees the same things. A manager, an operator and a customer have different needs and different permissions. These permissions are written before the code, in a simple table that you approve. The reason is practical: a mistake here does not show on the screen, but it exposes data to someone who should not have seen it.

What is access control?

Access control decides what each user is allowed to do after signing in. Signing in says who the user is. Access control says what they can see, change or delete. These are two different jobs, and the second needs its own design.

OWASP, the open community for application security, puts Broken Access Control in first place in its Top 10 list of 2021. Compared with the previous list, it moved up from fifth place to first. This shows how often applications send users where they should not go.

What is a role?

A role is a name for a group of permissions. NIST describes RBAC (role-based access control) as a model where users are assigned to roles, and each role has one or more permissions. Administrators define which actions each job needs and put people in the matching role.

NIST notes that without roles, administrators often set up access lists for each user, which is costly and prone to mistakes. With roles, management follows the structure of the organisation. When an employee changes position, they change role, not dozens of separate settings.

How is the permissions table written?

The permissions table is written with one row per action and one column per role. We make it at the requirements stage, together with the people who will use the system. Each cell answers yes or no.

Action

Manager

Operator

Customer

Sees the dashboards of the whole team

Yes

No

No

Creates and edits requests

Yes

Yes

Only their own

Approves a request

Yes

No

No

Deletes data

Yes

No

No

The above is an example, not a ready recipe. In every project the roles differ. The value of the table is that you reach agreement before anything is built, and that the code and the tests follow exactly what was approved.

Which rules are followed?

We follow three rules from the OWASP Authorization Cheat Sheet. The first is least privilege: the user gets only what they need for their job. The second is deny by default, meaning whatever has not been explicitly allowed is forbidden. The third is a check on every request.

The third rule has a practical consequence. OWASP stresses that the check is done at the server and not only in the browser, because the browser is controlled by the user. A button hidden from the screen protects nothing if the server accepts the request. For the same reason, a check missing in a single place can expose a whole resource.

What about the user's own data?

The role is not always enough. In the table above, the customer can edit requests, but only their own. That is a rule about the record and not about the role. The OWASP Top 10 lists it as a prevention: access models must enforce record ownership, so that a user cannot read, change or delete the records of others.

The OWASP Cheat Sheet itself recommends, for applications, models that look at attributes or relationships (ABAC, ReBAC), because roles struggle when the decision depends on the record itself. That is why we start from roles, which are easy to explain to the whole team, and add ownership rules where the table asks for it. In a platform with many customers there is one more level, the separation of data per tenant, described in the article on customer data in a SaaS.

How do we check that it works?

It is checked with automated tests that are written before the code. OWASP recommends tests for the permission logic, which confirm that access is denied by default and that the rules are applied. It adds that automated tests do not replace a manual security review.

In our own work, the test is written first for each function, and for each feature that handles data a test for the wrong user is written too: what the system answers to another role, to a visitor who is not signed in, to a user of another customer. For the method, see the article test first, then code. A team of agents also reviews the finished project, as we explain in the case study on quality and security agents.

Frequently asked questions: Roles and permissions in a SaaS before the code

How many roles does a platform need?

As many as the people who use it need, and no more. We start with a few roles that match real jobs. If the team needs something in between, it is added through the change process, with a new row in the table.

Can my customer create their own roles?

It depends on the product and is decided in the requirements. Some platforms have fixed roles, others let each customer's administrator define roles. The second option adds work, because every role must be verified with tests.

Is it enough to hide the buttons that are not allowed?

No. A hidden button helps the user experience, but it is not access control. The check is done at the server, on every request, so that it holds even if someone sends the request another way.

When does this work start?

In the first stage, in the requirements, before the screen designs. The permissions table affects the screens, the data and the tests, so it is worth having from the start.

Do you want us to define the roles of your platform?

If you are planning a platform with different user roles, the permissions table is a good first step, and you can start it yourself on one page. Describe your project in the project request and we will complete it together at the requirements stage. See also the page on SaaS platforms.

Sources: Roles and permissions in a SaaS before the code

In practice: Roles and permissions in a SaaS before the code

Start a project

Want a website your visitors understand right away? We will help you organise it properly.

Planning a new website?

See how we build business websites