AI Token Forgery Lab: When the Backend Trusts a Model-Made Token

✨ AI Summary
AuthBot's LLM writes a session token into its reply after you authenticate, and the backend trusts whatever token comes back from the model as real. But an LLM cannot keep a secret or sign anything — so a token it 'mints' is only as trustworthy as a sentence you can talk it into writing.
Lab at a glance: Advanced · 145 XP · about 20 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

This is a design error: authentication state is produced by the model instead of by an auth service. Because you can influence the model's output, you can influence the token it emits — including its claimed role — and a backend that trusts that token hands you whatever the claims say.

The lesson: models generate text, not trust. Anything security-critical must come from a system the model cannot forge.

How AuthBot issues a session token

After a login step, AuthBot's LLM writes a session token in its response and the backend accepts it. The token's claims — including the role — are whatever ends up in the model's text, which you can steer.

The attack approach

  • Confirm the token in AuthBot's reply is produced by the model and trusted by the backend.
  • Steer the reply so the emitted token claims an admin role.
  • Take that token to the admin-only endpoint.
  • Surface the admin user list the endpoint returns.

Full walkthrough (spoiler)

If the backend rejects the token, the claim format is off — open the steps.

Show the step-by-step solution
  1. Interact so that AuthBot emits a session token whose role claim is admin rather than user.
  2. Copy that model-produced token.
  3. Call the /admin/users endpoint with it.
  4. The backend trusts the model's token, honours the admin claim, and returns the user list. The lab marks you solved.

Why it works

The backend treats the model like an identity provider, but the model is a text generator you can influence. Nothing cryptographic binds the token to a real authentication event, so a token claiming admin is accepted simply because it came back from the LLM.

Core principleLLMs cannot mint authentication. Tokens must come from the auth service and be signed with a key the model never sees.

Where this happens in the real world

Trusting model output for security decisions is a direct case of OWASP LLM05 Improper Output Handling (and overlaps Excessive Agency). As teams wire LLMs into auth and authorisation flows, 'the model said so' becomes a dangerous substitute for a real trust boundary.

How to defend against it

  • Issue tokens from the auth service only, signed with a key the model never has access to.
  • Never let the model see or produce signing material or security claims.
  • Verify tokens server-side against the issuer, with role and scope set by the backend, not the reply.
  • Keep authorisation decisions out of the model entirely.
Mr Elite tip: If an LLM ever produces something the backend trusts — a token, a role, an 'approved' flag — treat it as attacker-controlled. Security state must originate where the model cannot reach.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is LLM token forgery?
A flaw where a backend trusts an authentication token produced by the language model, so steering the model's output lets an attacker mint a token with elevated claims.
Why can't an LLM issue tokens?
Models generate text and can be influenced by input; they cannot hold a signing key secret or guarantee a claim. Authentication must come from a service the model cannot forge.
How is this like JWT bugs?
Both come from trusting a token's claims without a real cryptographic guarantee tied to an authentication event.
How do I fix it?
Issue and verify tokens in the auth service with a key the model never sees, and keep role/scope decisions in the backend, not the model's reply.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *