The agent has admin rights, the user is a viewer. What's allowed?
Question
A shop's back-office assistant calls the order and customer APIs with one service key. The key has admin rights in every store.
Dana is a viewer in store north: she may read orders and customers there, nothing else. The assistant itself is built only for read_order, refund_order and read_customer.
Dana asks the assistant to do four things:
read_orderin northrefund_orderin northread_customerin southdelete_customerin north
Which ones may run? Where do you enforce the rule, and what happens when a setting is missing?
Show hints (3)
- "TWO SETS"
The key says what the assistant can reach. Dana's role says what she may do. Which should decide an action for her?
- "PER OPERATION"
Allowing the orders API as a whole also allows refunds. Check the operation and the store.
- "WHERE TO CHECK"
A prompt rule is text the model can be talked out of. Which component sees every call, whatever the model writes?
Show checked explanation
Only request 1. An agent acting for a user may do only what both may do, checked per operation and store. Enforce it in the tool or the API with the user's identity, not in the prompt. A missing setting means deny.
DANA = {"ops": {"read_order", "read_customer"}, "stores": {"north"}} # viewer
BOT = {"ops": {"read_order", "refund_order", "read_customer"}} # its job
def may(op, store, user=DANA, agent=BOT):
# a missing setting is an empty set: it allows nothing
return (op in user.get("ops", set())
and op in agent.get("ops", set())
and store in user.get("stores", set()))
requests = [("read_order", "north"), ("refund_order", "north"),
("read_customer", "south"), ("delete_customer", "north")]
for op, store in requests:
print(op, store, "allow" if may(op, store) else "deny")
print("no store list:", may("read_order", "north", user={"ops": DANA["ops"]}))read_order north allow refund_order north deny read_customer south deny delete_customer north deny no store list: False
Code run on CPython 3.12 against the example above. Checked by an editor other than the author.
Walkthrough
Check each request against both sets. The admin key doesn't count: it only says what the assistant can reach.
| request | Dana allows | assistant allows | result |
|---|---|---|---|
read_order, north | yes | yes | allow |
refund_order, north | no | yes | deny |
read_customer, south | no, other store | yes | deny |
delete_customer, north | no | no | deny |
Take the intersection, not the union. With a union, the assistant's refund_order would cover for Dana's missing right, and a viewer could refund money by asking a bot.
This is the confused deputy problem, named by Norm Hardy in 1988. A program that acts for a caller with its own, wider authority lets the caller borrow that authority. Here the admin key is the assistant's power, and Dana or text hidden in a document can steer it.
Where to enforce. Not in the system prompt: "never refund for viewers" is only a request, and a clever message can talk the model out of it. Put the check in the tool, or in the API behind it:
- The tool receives Dana's identity and checks both her rights and the assistant's own list.
- The service key is no broader than the assistant's job, so even a bug in the check can't reach
delete_customer.
OWASP's Top 10 for LLM Applications calls this risk Excessive Agency (LLM06). Its advice: run actions in the user's context, and authorize in the downstream system, not in the model.
Missing settings. If Dana's store list is missing, the answer is deny, the same as an empty list.
Common mistakes
- Writing the rule only in the system prompt. Injected text or a persistent user can still get
refund_ordercalled. - Allowing by tool name. Access to the orders API also allows refunds. Grant operations, and check the store on every call.
- Calling the API with the admin key and filtering the reply afterwards. By then the refund or delete has already run.
- Treating a missing setting as "no restriction". A deploy that forgets one config line then hands out admin rights.
Follow-up questions
- "Dana becomes an admin. Can the assistant now delete customers?" No. The assistant's own list doesn't include
delete_customer, so the intersection still denies it. Removing a right from either side never adds an action. - "How does the tool know the call is for Dana?" The app passes a short-lived token for Dana with each call, outside the model's text. The tool checks it and never trusts a user name in the model's arguments, which injected text can change.
- "There's an incident in store north. Stop refunds there, but keep everything else working." Store the stop as its own record: an id, an owner and a scope (store north,
refund_order). Every call checks all active stops. Releasing it removes only that record, so a global stop someone else set stays in force. One shared "enabled" flag can't do that.
What a strong answer covers
Checks each operation and store against both sides and explains why a union fails. Names the confused deputy. Enforces the rule in the tool with the user's identity. Narrows the service key and treats a missing setting as deny.
Open in interactive practice deck →