EveryRole

Permission testing: build an access matrix for your app

Permission testing starts with a table: pages down, kinds of user across. Fill in every cell, then test every cell. The ones you can’t fill are the risk.

Permission testing answers one question for every page of your app: who may open this, and what does everyone else get? The tool for it is an access matrix. Put your pages down the side and your kinds of user across the top, write the right answer in every cell, then check each cell on the live app. The cells you can’t fill in are where to look first.

For a small app it is a short job. We did it for our practice app and found a cell nobody had decided.

The access matrix of the items app. Rows: the list, new item, the editor's own item, another editor's item, set up. Columns: visitor, viewer, editor. A visitor is sent to log in everywhere. A viewer opens the list, is refused at new item, gets not found for items. An editor opens their own item and gets not found for another editor's. The viewer's cell at set up is dashed: Opens, with a question mark.
Fourteen cells we could fill in from what the app is for, and one we couldn’t.

How to build an access control matrix

1. List the kinds of user. Not the role names in your database. The kinds of person: a visitor who isn’t signed in, a free user, a paying one, an admin. Our practice app has a visitor, a viewer and an editor.

2. List the pages, and split the ones that belong to someone. “An item’s page” is two rows: the owner’s own item, and somebody else’s. This is the row a matrix by role alone leaves out, and it is where one customer sees another’s data. Two people with the same role are still two people, and IDOR testing is the check for it.

3. Write the right answer in every cell, before looking at the app. Use a small fixed set of words. Ours:

  • Opens: the page, with its content.
  • Log in: sent to the login page, and brought back after.
  • Refused: a page that says no, with a 403 status.
  • Not found: the app’s own not-found page, with a 404 status.

Deciding between “Refused” and “Not found” is a real decision. “Refused” tells the person the thing exists. For another person’s private item, “Not found” gives away less. Pick one per kind of page and write it down.

4. Circle the cells you couldn’t fill. Do not guess. An empty cell means nobody decided, and the app is doing something anyway.

The empty cell we found

Filling in ours, the first four rows came straight from what the app is for. Then the set-up wizard. Should a viewer be able to run it?

We didn’t know. So we logged in as the viewer and went to /setup.

The practice app's set-up wizard, step two, "Set up: your team", with a team size field and Back and Next buttons, open for a viewer who has just sent step one.
The viewer got through step one of set up and is on step two. Nothing refused them.

The app lets a viewer type a company name, press “Next” and carry on. Nothing in the code checks the kind of user on that page. It is a practice app built for tests, so nobody is harmed. In a real app that is a read-only account changing company settings, found only because a table had a hole in it.

That is the argument for the matrix. Page by page, each permission looks fine. The gaps only show when you force yourself to answer every cell.

RBAC test cases: turn each cell into a case

Each cell becomes one test case with three parts: who, which address, what must come out.

WhoAddressWhat must come out
Viewer/items/newA page headed “Not allowed” that says “Viewers can’t create items.”, status 403, no form
Viewer/items/1 (an editor’s item)“There is no such page.”, status 404, a link back to the list
Editor/items/1 (another editor’s item)The same not-found page, and nothing of the item on it
Visitor/itemsThe login form. After logging in, the list

Those answers are quoted from the app. Write yours the same way: the exact words and the status. “Access is denied” as an expected result will be passed by any page that isn’t the real one, including an error page and a blank one. That is a hollow pass.

Three rules for running them:

  • Type the address. Don’t look for a link. A hidden link proves nothing about the page behind it. (Role-based testing shows a viewer’s disabled button and the refusal behind it as two separate facts.)
  • Check what is not there. A refusal page that still shows the item’s name in its title has leaked it.
  • Check the “Opens” cells too. A permission bug that locks paying users out of what they paid for is found by the same table.

Permission testing is never done once

A matrix checked by hand is true on the day you checked it. Permissions break in refactors: a check moves from the page into a shared function, one route forgets to call it, and nothing on screen changes for the person who made the change, because they are an admin.

So the cells have to be run again after every deploy. Fifteen cells by hand is a slow, dull job, and we wouldn’t do it after every deploy either. This is the part to automate first, before any form test. The checks are simple (open an address as a given user, compare the answer) and what they protect is other people’s data.

When you add a page, add its row. When you add a kind of user, add a column, and every cell in it is a decision to make on that day and not after an incident.

How EveryRole does it

EveryRole checks which kind of user can open which page. You give it a test login for each kind of user; it explores the app signed out and as each of them, on the live site, and builds that table from what it sees.

In a journey it goes further. At each stop, after the cases of the journey’s own kind of user, the other kinds of user are checked at that stop: does the page open for them, and do they get its button.

EveryRole's "Other kinds of user" section for the new item stop, at phone width: the viewer and the visitor each open /items/new and look for "Create". Both rows read Not checked yet.
The new item stop, as the two kinds of user it doesn’t belong to. Not checked yet: the first answer waits for a person’s yes.

The first answer for each waits for your yes. After that, every run compares with it, and a cell that changes (a viewer who suddenly gets the “Create” button) comes back to you as a changed result, never as a silent pass.

What it can’t do is fill in your empty cells. If set up is a stop in one of your journeys, it shows you that a viewer can open it. Whether a viewer should is the decision in step 4, and it is yours.

Keep reading

Roles and permissions

IDOR testing: open another user’s item by its URL

IDOR testing in one move. Log in as a second user, type the address of the first user’s item, and the app must answer not found. How to run it on every deploy.

6 min read

Roles and permissions

Role-based testing: your app is several apps

Role based testing means running each journey as every kind of user, each with its own expected result. One suite run as admin tests one of your apps.

5 min read

Roles and permissions

Test accounts for each role, kept safe

Test accounts for QA: one per kind of user, made for testing, never a real person’s, with the least rights that do the job.

5 min read