Status Code Determinism Audit
Check that 401 and 403 are chosen consistently across the API, so authorization state cannot be inferred from which code a caller happens to receive
Use when: responses use a mix of 401, 403 and 404 and you want the boundary between them to be a state machine, not improvisation
Avoid when: the API always hides behind a single catch-all code and you have no signal worth auditing
Procedure
- Define the intended semantics and write the decision table: no credential gives 401, wrong scope gives 403, hidden object gives 404.
- Collect responses from every refusal path in your earlier phases and tabulate which code each condition actually produced.
- Find divergences: the same condition producing different codes on different endpoints, which itself is an inference channel.
- Test object-level refusals for 403-versus-404 determinism, since that choice either hides or reveals existence.
- Check error bodies for code-specific wording or machine-readable fields that give away which check fired.
- Record the audit as a condition-by-code matrix with every divergence as an explicit row in the report.
Signals
- One endpoint returns 403 for a peer-owned object while its sibling returns 404 for the identical condition.
- Expired credentials sometimes produce 403 instead of 401, blurring authentication from authorization states.
- A machine-readable error code distinguishes forbidden from not-found in one endpoint and not another.
- Wording differs, such as not authorized versus unknown resource, so a caller learns which layer refused without testing.
Patterns
1. Decision table
no-credential=401 bad-role=403 hidden-object=404 unknown-object=404
2. Divergence row
GET /api/a/{id} peer=404 | GET /api/b/{id} peer=403 -> existence oracle across resources
3. Result row
divergences=3 worst=peer-object 403-vs-404 across /api/a vs /api/b
Pitfalls
- Treating any 4xx as authorization working, when 400 masquerading as 403 just means the caller cannot parse the rule.
- Overlooking heuristics such as latency and response size, which leak existence even when codes were made uniform.
- Fixing only two endpoints while the rest of the audit continues to emit the inconsistent code pair.
Done when
- Every refusal condition observed in testing has its actual code recorded next to the intended code in one matrix.
- Object-level 403-versus-404 behavior is documented per endpoint with an explicit existence-leak verdict.