AI Agent State Lab: Tamper the Saved Role to Reach Admin Code

✨ AI Summary
StateBot saves its agent state as a JSON blob in your browser storage, and on every request it reloads that blob and reads a role field to decide what it can do. State you can edit is state you control — so set the role to admin and the admin code path opens.
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 the agentic version of trusting client-side state. The agent persists its state where the user can reach it, then reloads and acts on fields like role without verifying them. Whoever can edit the stored blob decides the agent's privileges.

The lesson: client-held state is attacker-controlled. A field that changes behaviour must be authenticated or kept on the server.

How StateBot reloads its state

StateBot stores {…, role: 'user'} in client storage. Each request reloads the JSON and branches on role: 'user' takes the normal path, 'admin' unlocks a get_secret_config path. Nothing signs or re-checks the blob, so an edited role is trusted.

The attack approach

  • Find the agent state persisted in client storage.
  • Locate the role field inside the JSON blob.
  • Change it from user to admin and let the state reload.
  • Trigger the admin-only code path to read the secret config.

Full walkthrough (spoiler)

If the change does not stick, you may be editing the wrong copy — open the steps.

Show the step-by-step solution
  1. Open the persisted JSON state StateBot keeps in client storage.
  2. Set the role field to admin and save it back.
  3. Make a request so the server reloads the tampered state and branches to the admin path.
  4. The admin-only get_secret_config path runs and returns SECRET_CONFIG. The lab marks you solved.

Why it works

The server treats the reloaded blob as authoritative, but it lives on the client where you can edit it. Because only selected fields (if any) are protected and the role is not, changing role rewrites what the agent is allowed to do.

Core principleNever trust client-supplied state. Keep authoritative state server-side, or sign the entire blob and verify the signature on every load.

Where this happens in the real world

Trusting tampered client state is a long-standing broken-access-control pattern, now reappearing in agent memory and 'portable state' designs. In LLM terms it enables Excessive Agency (LLM06) by letting the user flip the agent's privileges, and it echoes classic insecure-deserialization and mass-assignment bugs.

How to defend against it

  • Keep authoritative state on the server, keyed to an authenticated session.
  • If state must travel with the client, sign the whole blob and verify it on every load — not just selected fields.
  • Derive privileges from the server-side session, never from a field in reloaded state.
  • Validate reloaded state against expected types and values before acting on it.
Mr Elite tip: Any agent that persists state to the client and reads privileges back from it is trusting the user. Check whether the entire blob is signed and verified — selective signing leaves the role field editable.

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 the bug in this lab?
An AI agent reloads JSON state from client storage and trusts its role field, so editing the stored blob switches the agent to an admin code path.
Why is client-side state dangerous?
Because the user can edit it. Any field that controls behaviour or privileges must be authenticated or kept server-side.
How is this related to AI?
Portable agent memory and state are increasingly stored client-side; trusting them re-introduces this classic flaw and enables Excessive Agency.
How do I fix it?
Keep authoritative state on the server, or sign the whole blob and verify it on load, and derive privileges from the session rather than reloaded fields.
⚡
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 *