One Permission Policy for Every AI Agent Action: Allow, Hold or Block
In the last six labs, AI agents were tricked by a resume, a receipt image, a poisoned memory, another agent, a web page and their own made-up answers. Every time, the model proposed something bad and the app ran it. Thi
In the last six labs, AI agents were tricked by a resume, a receipt image, a poisoned memory, another agent, a web page and their own made-up answers. Every time, the model proposed something bad and the app ran it.
This lab gives one agent all of those powers: it reads pages, remembers things, sends email and updates accounts. Then it puts one permission policy between the model and every tool. The model proposes, and code decides: ALLOW, HOLD (the user approves it) or BLOCK.
The four questions
| Question | Rule |
|---|---|
| Who is this for? (identity) | Actions only touch the signed-in user's own things. |
| What did this turn read? (taint) | After untrusted content, anything with side effects waits for the user. |
| How risky is the tool? (tiers) | Read, write, external and account each get their own rule. |
| Where does data go? (allowlist) | Outbound data only goes to approved destinations. |
The policy, in code
RISK = {"fetch_page": "read", "remember": "write", "send_email": "external", "update_account_email": "account"}
def decide(tool, args, user, tainted):
risk = RISK.get(tool)
if risk is None:
return "BLOCK", "unknown tool"
if risk == "read":
return "ALLOW", "read only"
if risk == "account":
if args.get("customer") != user["name"]:
return "BLOCK", f"{user['name']} can't change {args.get('customer')}'s account"
return "HOLD", "account changes need the owner to confirm"
if risk == "external" and args.get("to") != user["email"]:
return "BLOCK", f"{args.get('to')} isn't an allowed recipient"
if tainted:
return "HOLD", "this turn read untrusted content"
return "ALLOW", "the user asked for it directly"
Every tool handler is wrapped so it calls decide() first. A poisoned page can no longer save a fake refund portal or email order history out, and nobody can touch someone else's account. Saving your own preference and emailing yourself still work.
Run the lab yourself
git clone https://github.com/usinha79/hack-it-then-fix-it
cd hack-it-then-fix-it/ep15-agent-permission-policy
pip install -r requirements.txt
python vulnerable/app.py # http://localhost:5000, then ./attack.sh
python fixed/app.py
APP=fixed python -m pytest -v tests # 5 passed
APP=vulnerable python -m pytest -v tests # 3 failed: the attacks go through
A GitHub Actions workflow runs the tests on every push and pull request. Everything is fake, and .example domains can't be registered. Full lab: github.com/usinha79/hack-it-then-fix-it
Take-home checklist
- Put one policy layer between the model and every tool. The model proposes, and code decides.
- Carry the user's identity from the session, and check ownership on every action.
- Track taint: after untrusted content, side effects need a human.
- Allowlist where data can go.
- Turn every attack into a test, and keep the legitimate actions in the suite too.
Watch the whole module
This episode is part of Module 2 of Hack It, Then Fix It. If you'd rather watch every lab in the module back to back, here is the full cut:
Hack It, Then Fix It is a series where I build a small AI app with a real flaw, break it, fix it in code, and run the same attack again to prove the fix holds. Everything shown uses fake data on my own machine. Only test systems you own or are authorised to test.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.