ServicesSecurity BlueprintInsightsAboutTalk to us

Case study: an API that trusted its tokens more than its own servers

Signing in is only as strong as the check behind it. In this review, the API accepted tokens it had never checked, kept stolen sessions alive and stored a database password where anyone with the code could find it.

This is the third review of LendStack, our deliberately vulnerable reference build, this time focused on authentication. It is not a client system. The findings and evidence are public on GitHub.

Three boundaries we tested

  • Secrets: are the keys and passwords behind sign-in kept secret?
  • Verification: does the server check that a token really came from it?
  • Lifecycle: when a token is stolen or a session should end, can the server stop it?

LendStack failed all three.

A token nobody checked (Critical)

The authentication middleware read each token with jwt.decode instead of jwt.verify. Decoding only reads a token. It never checks the signature. So we wrote our own token, naming a user in another tenant, set its algorithm to none and left the signature empty. The API answered 200 with that user’s record, and its logs recorded no denial.

No key and no special tools were needed. Any user, in any tenant, with any role, could be impersonated by hand.

An updated library did not mean a safe code path

The well-known attack on token libraries tricks a server into checking a signature with the wrong kind of key. The library version LendStack used blocks that attack, and we confirmed it did. The application was vulnerable anyway, through a different line of code that never asked the library to verify anything.

That is the lesson we would most want a client to take away: an up-to-date dependency does not prove the code path is safe. Test the path the requests actually take.

Sessions that could not be ended

  • Refresh tokens were never rotated (High). We used the same refresh token twice, and got a fresh access token both times. A stolen refresh token kept working, even after a password change.
  • Nothing could revoke a token (Medium). Access tokens lasted 24 hours, there was no logout endpoint and no denylist. An administrator who spotted an intruder could not cut them off.
  • Tokens were not tied to one service (Medium). Without audience and issuer checks, a token issued for one service could be replayed against another.

A password in the code history (Critical)

The file holding the database credentials had been committed to Git from the very first commit. Anyone with the repository had the database password.

The fixes

  • Verify every token with jwt.verify, and allow only the one expected algorithm.
  • Rotate refresh tokens on every use, and revoke them all when a password changes.
  • Shorten access tokens to 15 minutes, and add logout and a denylist.
  • Check the audience and issuer of every token.
  • Change the leaked password, stop tracking the file and remove it from the history.

What this means for your product

Authentication bugs rarely look dramatic in code review. A single function call or a missing option can turn sign-in into a formality. An Application & API Security review tests the real path every request takes, and shows you with evidence where it can be bypassed.

Newsletter

Get new insights by email.

Short, practical notes on security and technology risk, sent only when there’s something worth reading. Never more than one a month.