ACC-36Required
Test every role and a signed-out visitor against every action
Keep a table of every role and every action with the expected answer, and run it as a test against the server on every change.
How to do it
Build the list of actions from the route table or the permission list, so a new route without an entry fails the test. For each role, sign in as a test user with that role and call each action. Expect 2xx where allowed and 403 or 404 where refused. Add a signed-out visitor and a user from another organisation, as check ownership on every record says. Cover sign-up, sign-in, password reset and every admin page before launch, and attack resets as Make password resets safe shows. AI app builders produce sign-in screens that look right but leave pages and API routes open. Hiding a link is not a check.
Examples
Python example
import itertools
import pytest
ROLES = ["owner", "admin", "member", "viewer", "signed_out", "other_org"]
EXPECTED = load_table("access-matrix.csv") # (role, "POST /invoices/{id}/refund") -> 200 or 403
@pytest.mark.parametrize("role,action", itertools.product(ROLES, all_routes()))
def test_access(client_for, role, action):
method, path = action.split(" ", 1)
assert client_for(role).open(path, method=method).status_code == EXPECTED[(role, action)]
JavaScript example
import { test } from 'node:test';
import assert from 'node:assert/strict';
for (const role of ROLES) {
for (const action of allRoutes()) {
test(`${role} ${action}`, async () => {
const [method, path] = action.split(' ');
const response = await clientFor(role).fetch(path, { method });
assert.equal(response.status, EXPECTED.get(`${role} ${action}`));
});
}
}
How to check
Add a route without adding it to the table, and the test fails. Change a role's permissions without changing the table, and the test fails too. Signed out, every page and API route found in the code answers only if it is public. As a normal user, admin routes answer 403 or 404.
Sources
- OWASP Authorization Cheat Sheet on unit and integration tests for authorization
- OWASP Forgot Password Cheat Sheet
Related rules
- TST-11 Test rules with several conditions as a table in Testing
- ACC-77 Check ownership on every record in Accounts and identity
- ACC-69 Make sign-in and reset links single-use and short-lived in Accounts and identity
- CMP-32 Keep roles as code in Compliance and governance
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/accounts/roles-and-permissions/permission-matrix-test">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.