Broken API authentication: tokens, keys, and the checks that get skipped
Common API authentication failures: unvalidated JWT claims, API keys in URLs, missing rate limits on token endpoints, and long-lived tokens. Includes a review checklist and the validation code that closes them.
Diagram
Validating a bearer token properly
Step 1 of 4
Header
The client sends a bearer token.
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMjYtMTAifQ...
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Claims nobody checks
- What fails
- A token signed by the right issuer for a different API is accepted.
- Who is affected
- Users of every API that trusts the same identity provider.
- What you would notice
- Validation code that never passes audience.
- What you change
- Pin audience and issuer, and reject tokens without exp.
Keys in the wrong place
- What fails
- API keys in query strings end up in logs, browser history, and referrers.
- Who is affected
- The key owner and everything the key can reach.
- What you would notice
- URLs like /v1/data?api_key= in access logs.
- What you change
- Accept keys only in headers and rotate any key found in logs.
Token endpoints without limits
- What fails
- Login, token, and password-reset endpoints accept unlimited attempts.
- Who is affected
- Every account, through guessing and credential stuffing.
- What you would notice
- No 429 responses from /oauth/token or /login under load in a test.
- What you change
- Rate-limit by account and by client, and alert on spikes.
Review checklist
Read the authentication middleware once, then confirm every route uses it.
- Algorithm list fixed server-side, never read from the token header
- Audience and issuer checked
- Expiry required and short for access tokens
- Refresh tokens rotated and revocable
- API keys hashed at rest and scoped to one client
- Internal routes on the same host also require authentication
Reading a token without trusting it
Decoding a JWT payload is base64url and shows what the token claims; it proves nothing until the signature and claims are verified. In a review, decode sample tokens from the test environment to see whether aud and exp are present at all.
$ cut -d. -f2 <<<"$LAB_TOKEN" | tr '_-' '/+' | base64 -d 2>/dev/null | jq
{"iss":"https://login.example.test","sub":"user-311","exp":1793750400}
# no aud claim: any API trusting this issuer would accept itCheck yourself
Recognition and the fix. Nothing here is a procedure.
A token issued for the billing API is accepted by the orders API. Which check is missing?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
- 01API security misconfiguration: defaults, debug modes, and permissive CORSThe configuration mistakes that turn a sound API into an exposed one: debug endpoints, verbose errors, wildcard CORS with credentials, open documentation consoles, and missing TLS settings, with a scan-and-fix workflow.
- 02Injection through API fields: JSON bodies reaching SQL, NoSQL, and shellsWhy JSON APIs are still injection targets: operator injection in MongoDB-style queries, typed fields that are never type-checked, and filter parameters passed to query builders.
- 03Unsafe consumption of third-party APIs: treating partner data as trustedWhen your service calls a partner or SaaS API, its responses are input too.
- 04API inventory gaps: shadow, zombie, and undocumented endpointsYou cannot protect APIs you do not know about.
- 05GraphQL security: introspection, resolver authorization, and query costWhere GraphQL APIs go wrong — missing authorization in resolvers, unbounded nested queries, batching that defeats rate limits, and injection in resolver code — and how to review a schema and test it with a tool like InQL or graphql-cop.