A single auth test proves one route for one caller. A matrix proves
every route for every caller, and that is where broken function
level authorization hides: the admin route that accepts a user
token, the user route that accepts no token, the tenant route that
accepts another tenant. This sub-skill builds the matrix for an API
you are authorized to test, fills it with live evidence, and turns
every unexpected 200 into a finding.
Quick Workflow
- List every endpoint with its method, from the spec and from
discovery, and every role the API defines.
- Write the expected matrix: which role may call which endpoint,
including no token as a role.
- Collect one valid token per role, plus a token for a second
tenant where tenancy exists.
- Call every cell: every endpoint times every role, and record
the status code and a short response note.
- Flag every cell where the live result differs from expected.
- Confirm each flagged cell by hand: repeat the request, check
for data returned versus an empty success, and rule out caching.
- Re-run the matrix after fixes; a fixed matrix is the regression
proof for the next release.
1. Building the matrix
#!/usr/bin/env python3
"""Authentication matrix runner: every endpoint times every role.
Fill ENDPOINTS from the spec and discovery, and TOKENS from test
accounts created for this audit. Expected codes come from the
access policy; anything else is flagged for manual confirmation.
"""
import subprocess
BASE = "https://target.example"
ENDPOINTS = [
("GET", "/api/v1/users/me", {"anon": 401, "user": 200, "admin": 200}),
("GET", "/api/v1/users", {"anon": 401, "user": 403, "admin": 200}),
("POST", "/api/v1/users", {"anon": 401, "user": 403, "admin": 201}),
("DELETE", "/api/v1/users/2", {"anon": 401, "user": 403, "admin": 204}),
("GET", "/api/v1/admin/settings", {"anon": 401, "user": 403, "admin": 200}),
]
TOKENS = {
"anon": None,
"user": "user-token-value",
"admin": "admin-token-value",
}
for method, path, expected in ENDPOINTS:
for role, token in TOKENS.items():
cmd = ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
"-X", method, BASE + path]
if token:
cmd += ["-H", f"Authorization: Bearer {token}"]
got = subprocess.run(cmd, capture_output=True,
text=True).stdout.strip()
want = str(expected[role])
mark = "OK " if got == want else "FLAG"
print(f"[{mark}] {method} {path} as {role}: got {got}, want {want}")
2. Cross tenant and method cells
# Cross tenant cell: tenant A token reading tenant B objects
echo "== tenant A token, tenant B user record"
curl -s -o /dev/null -w '%{http_code}\n' \
-H 'Authorization: Bearer tenant-a-token-value' \
"https://target.example/api/v1/tenants/B/users/9"
echo "want 403 or 404; a 200 is horizontal escalation even if the"
echo "record looks ordinary, because the boundary itself failed"
# Method cells: the same path with every method, not just the one
# the documentation lists. Gateways often protect GET and forget
# DELETE, or protect the documented method and not HEAD.
for m in GET POST PUT PATCH DELETE HEAD OPTIONS; do
code=$(curl -s -o /dev/null -w '%{http_code}' -X "$m" \
-H 'Authorization: Bearer user-token-value' \
"https://target.example/api/v1/admin/users")
echo "$m /api/v1/admin/users as user -> HTTP $code (want 403)"
done
3. Matrix reporting
#!/usr/bin/env python3
"""Render the matrix as a report table from the runner output.
Paste the runner lines in as rows, or extend the runner to write
them to a file. The table is the finding: one row per endpoint,
one column per role, with FLAG cells expanded below it.
"""
rows = [
("GET /api/v1/users/me", "401", "200", "200"),
("GET /api/v1/users", "401", "403", "200"),
("DELETE /api/v1/users/2", "401", "FLAG 204", "204"),
]
print(f"{'endpoint':<32} {'anon':<10} {'user':<10} {'admin':<10}")
for endpoint, anon, user, admin in rows:
print(f"{endpoint:<32} {anon:<10} {user:<10} {admin:<10}")
print()
print("FLAG cells need a manual repeat and a data check: a 204 with")
print("no effect is a weaker finding than a 204 that deleted data.")
print("Re-run the full table after every fix, and keep the old")
print("table beside the new one as the regression comparison.")
Edge cases
- The API returns 404 instead of 403 for forbidden objects. That is
a valid design against enumeration, but the matrix must record
it as expected, or every cell will look like a finding.
- Caching serves a previous role's response to the next caller.
Repeat flagged cells with cache-busting query strings and fresh
tokens before reporting.
- Roles are hierarchical in the docs but flat in the code. Then the
matrix, not the docs, is the truth, and the report should say so.
- Some endpoints accept both a user token and an API key. Test the
matrix for each credential type; a key that bypasses role checks
is a finding even if the token path is clean.
- Token expiry during a long run poisons later cells. Refresh
tokens mid-run and re-run any cell that changed after refresh.
Key references
- OWASP API Security Top 10, broken object level and broken
function level authorization.
- OWASP testing guidance for authorization, including multi-account
methodology.
- Related skills: api-gateway-security, api-security-testing,
api-key-management.
1---2name: api-authentication-matrix3description: Use when building or testing the authentication matrix4 for an API on an authorized engagement. Covers mapping every5 endpoint against every role, testing no token, low privilege, and6 cross tenant callers, and proving the matrix with Burp Suite or7 curl traffic. Use when roles exist, when endpoints serve8 user-specific data, or when gateway auth must be verified per9 route rather than assumed from one sample.10version: 1.0.011domain: api12lifecycle: stable13last_verified: "2026-10-27"14parent: api-gateway-security15requires: [api-gateway-security]16extends: []17relates: [api-security-testing, api-key-management, openapi-security-review]18tools:19 - name: curl20 version: "8.5"21 - name: Python22 version: "3.12"23 - name: jq24 version: "1.7"25metadata:26 source: https://skillmd.com/skills/mizazhaider-ceh/api-authentication-matrix27---2829A single auth test proves one route for one caller. A matrix proves30every route for every caller, and that is where broken function31level authorization hides: the admin route that accepts a user32token, the user route that accepts no token, the tenant route that33accepts another tenant. This sub-skill builds the matrix for an API34you are authorized to test, fills it with live evidence, and turns35every unexpected 200 into a finding.3637## Quick Workflow38391. List every endpoint with its method, from the spec and from40 discovery, and every role the API defines.412. Write the expected matrix: which role may call which endpoint,42 including no token as a role.433. Collect one valid token per role, plus a token for a second44 tenant where tenancy exists.454. Call every cell: every endpoint times every role, and record46 the status code and a short response note.475. Flag every cell where the live result differs from expected.486. Confirm each flagged cell by hand: repeat the request, check49 for data returned versus an empty success, and rule out caching.507. Re-run the matrix after fixes; a fixed matrix is the regression51 proof for the next release.5253## 1. Building the matrix5455```python56#!/usr/bin/env python357"""Authentication matrix runner: every endpoint times every role.5859Fill ENDPOINTS from the spec and discovery, and TOKENS from test60accounts created for this audit. Expected codes come from the61access policy; anything else is flagged for manual confirmation.62"""63import subprocess6465BASE = "https://target.example"66ENDPOINTS = [67 ("GET", "/api/v1/users/me", {"anon": 401, "user": 200, "admin": 200}),68 ("GET", "/api/v1/users", {"anon": 401, "user": 403, "admin": 200}),69 ("POST", "/api/v1/users", {"anon": 401, "user": 403, "admin": 201}),70 ("DELETE", "/api/v1/users/2", {"anon": 401, "user": 403, "admin": 204}),71 ("GET", "/api/v1/admin/settings", {"anon": 401, "user": 403, "admin": 200}),72]73TOKENS = {74 "anon": None,75 "user": "user-token-value",76 "admin": "admin-token-value",77}7879for method, path, expected in ENDPOINTS:80 for role, token in TOKENS.items():81 cmd = ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",82 "-X", method, BASE + path]83 if token:84 cmd += ["-H", f"Authorization: Bearer {token}"]85 got = subprocess.run(cmd, capture_output=True,86 text=True).stdout.strip()87 want = str(expected[role])88 mark = "OK " if got == want else "FLAG"89 print(f"[{mark}] {method} {path} as {role}: got {got}, want {want}")90```9192## 2. Cross tenant and method cells9394```bash95# Cross tenant cell: tenant A token reading tenant B objects96echo "== tenant A token, tenant B user record"97curl -s -o /dev/null -w '%{http_code}\n' \98 -H 'Authorization: Bearer tenant-a-token-value' \99 "https://target.example/api/v1/tenants/B/users/9"100echo "want 403 or 404; a 200 is horizontal escalation even if the"101echo "record looks ordinary, because the boundary itself failed"102```103104```bash105# Method cells: the same path with every method, not just the one106# the documentation lists. Gateways often protect GET and forget107# DELETE, or protect the documented method and not HEAD.108for m in GET POST PUT PATCH DELETE HEAD OPTIONS; do109 code=$(curl -s -o /dev/null -w '%{http_code}' -X "$m" \110 -H 'Authorization: Bearer user-token-value' \111 "https://target.example/api/v1/admin/users")112 echo "$m /api/v1/admin/users as user -> HTTP $code (want 403)"113done114```115116## 3. Matrix reporting117118```python119#!/usr/bin/env python3120"""Render the matrix as a report table from the runner output.121122Paste the runner lines in as rows, or extend the runner to write123them to a file. The table is the finding: one row per endpoint,124one column per role, with FLAG cells expanded below it.125"""126rows = [127 ("GET /api/v1/users/me", "401", "200", "200"),128 ("GET /api/v1/users", "401", "403", "200"),129 ("DELETE /api/v1/users/2", "401", "FLAG 204", "204"),130]131print(f"{'endpoint':<32} {'anon':<10} {'user':<10} {'admin':<10}")132for endpoint, anon, user, admin in rows:133 print(f"{endpoint:<32} {anon:<10} {user:<10} {admin:<10}")134print()135print("FLAG cells need a manual repeat and a data check: a 204 with")136print("no effect is a weaker finding than a 204 that deleted data.")137print("Re-run the full table after every fix, and keep the old")138print("table beside the new one as the regression comparison.")139```140141## Edge cases142143- The API returns 404 instead of 403 for forbidden objects. That is144 a valid design against enumeration, but the matrix must record145 it as expected, or every cell will look like a finding.146- Caching serves a previous role's response to the next caller.147 Repeat flagged cells with cache-busting query strings and fresh148 tokens before reporting.149- Roles are hierarchical in the docs but flat in the code. Then the150 matrix, not the docs, is the truth, and the report should say so.151- Some endpoints accept both a user token and an API key. Test the152 matrix for each credential type; a key that bypasses role checks153 is a finding even if the token path is clean.154- Token expiry during a long run poisons later cells. Refresh155 tokens mid-run and re-run any cell that changed after refresh.156157## Key references158159- OWASP API Security Top 10, broken object level and broken160 function level authorization.161- OWASP testing guidance for authorization, including multi-account162 methodology.163- Related skills: api-gateway-security, api-security-testing,164 api-key-management.