# API Authentication Matrix

> Use when building or testing the authentication matrix for an API on an authorized engagement. Covers mapping every endpoint against every role, testing no token, low privilege, and cross tenant callers, and proving the matrix with Burp Suite or curl traffic. Use when roles exist, when endpoints serve user-specific data, or when gateway auth must be verified per route rather than assumed from one sample.

- Skill: `mizazhaider-ceh/api-authentication-matrix` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/api-authentication-matrix`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/api-authentication-matrix/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/api-authentication-matrix

---


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

1. List every endpoint with its method, from the spec and from
   discovery, and every role the API defines.
2. Write the expected matrix: which role may call which endpoint,
   including no token as a role.
3. Collect one valid token per role, plus a token for a second
   tenant where tenancy exists.
4. Call every cell: every endpoint times every role, and record
   the status code and a short response note.
5. Flag every cell where the live result differs from expected.
6. Confirm each flagged cell by hand: repeat the request, check
   for data returned versus an empty success, and rule out caching.
7. Re-run the matrix after fixes; a fixed matrix is the regression
   proof for the next release.

## 1. Building the matrix

```python
#!/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

```bash
# 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"
```

```bash
# 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

```python
#!/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.

