On this page4 sections
ReferenceBeginner3-5 min reference

Auth Error Codes

The most-confused pair in testing is 401 vs 403. This sheet pins down the status codes an authentication/authorization flow should return, what each actually means, and the check behind it. For the full status-code list see the HTTP Status Codes sheet; for the token mechanics see OAuth and JWT (all linked below).

The codes

CodeNameMeansTest
401UnauthorizedNot authenticated — no/invalid/expired credentialsCall with no token, bad token, expired token
403ForbiddenAuthenticated but not allowed — valid identity, wrong permissionValid token, access another user's / admin-only resource
419 / 440Session expiredVendor-specific session timeoutIdle past timeout, then act
429Too Many RequestsRate/throttle limit hitRapid repeated logins
400Bad RequestMalformed auth requestMissing grant params, bad body
404Not FoundSometimes used instead of 403 to hide existenceConfirm intended (anti-enumeration)

401 vs 403 — the rule

  • 401 = "I don't know who you are." → re-authenticate (the response should include a WWW-Authenticate header).
  • 403 = "I know who you are, and you can't do this." → re-authenticating won't help.
  • A common bug: returning 200 with empty data where 403 is correct — that's an authorization hole, not a UI quirk.

What to test

  • Missing token, malformed token, expired token → 401.
  • Valid token, wrong scope / another user's resource403 (not 200).
  • After logout/session expiry, a protected call → 401.
  • Error bodies are safe — no stack traces, tokens, or "user exists" leaks.

Common mistakes

  • Treating 401 and 403 as interchangeable.
  • 200 + empty payload instead of 403 (hides broken authorization).
  • Login telling attackers "wrong password" vs "no such user" (enumeration).
  • Leaking tokens or internal detail in the error response.