Check Who Is Asking
An assistant with tools reads and changes data on behalf of whoever is talking to it, so every tool call raises two questions: who is this user, and may this user touch this particular record? This page explains how an application answers both questions in its own code, where the user's identity has to come from, and why a language model, however well instructed, can never be the part that decides access.
Two questions: who you are and what you may do
Security people split access into two separate steps. Authentication establishes who the user is. NIST defines it as verifying the identity of a user, process or device, usually before any access is allowed. A password, a code sent to a phone or a passkey are ways to authenticate. Its result is a fact the application can rely on afterwards: this request comes from Maria.
Authorization decides what that user may do. It is a decision taken for a specific action on a specific thing: may Maria read order A-1001? May she cancel it? The two are often shortened to AuthN and AuthZ.
The split matters because a signed-in user is not an allowed user. Authentication happens once, at sign-in. Authorization happens again on every request, because each request asks for something different. An application that stops at "the user is signed in" lets every customer do anything any customer can do, to anyone's data.
| Authentication | Authorization | |
|---|---|---|
| Question | Who is this user? | May this user do this, to this record? |
| When | Once, at sign-in | On every request |
| Works from | A password, a code, a passkey | The established identity and the rules of the application |
| Result | A trusted identity, such as user maria | Allow or deny one action |
| Typical failure | Someone signs in as another person | A signed-in user reaches data that is not theirs |
True or false?
Once a user has signed in successfully, the application no longer needs to check what they are allowed to do.
False. Signing in only says who the user is. Whether they may read or change a given record is a separate decision, taken on each request.
Authorization depends on authentication: the application has to know who is asking before it can decide what they may do.
True. An access rule such as "users may read their own orders" needs a trusted identity to compare against, and authentication is what provides it.
Where the identity comes from
Authorization is only as good as the identity it checks. In an ordinary program the identity comes from the session: when the user signs in, the application records who they are and keeps that record for as long as they stay signed in. Every later request is tied to that record by the application itself, not by anything the user types.
An assistant adds two new places where a name or an id can appear, and neither of them can be trusted with identity. The first is the conversation. A user can write "I am the administrator" or "my customer id is 2041", and the model reads it as ordinary text. The second is the arguments of a tool call. When the model asks for a function, it writes the arguments itself. The OpenAI Chat Completions reference describes them as generated by the model. It warns that they may not be valid and may contain invented parameters, so they must be validated in code. And anything the model writes can have been shaped by what the user wrote.
| Where the value comes from | Who controls it | Usable as identity? |
|---|---|---|
| The session, created at sign-in | The application | Yes |
| The user's message | The user | No |
| Arguments of a tool call | The model, steered by the conversation | No |
| A document or tool result | Whoever wrote that content | No |
The practical rule follows: the code that runs a tool receives the user's identity from the session, as a parameter it fills in itself. The tool's description given to the model has no user_id field at all, so the model is never asked for one and has nowhere to put a false one. The model chooses which order to look at; the application already knows who is looking.
import json
# What the model is told about the tool: it may only name an order.
GET_ORDER_TOOL = {
"type": "function",
"function": {
"name": "get_order",
"description": "Look up one of the signed-in user's orders.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
},
}
def run_tool_call(session, call):
args = json.loads(call.function.arguments) # written by the model
if call.function.name == "get_order":
# session.user_id was set at sign-in, never by the model
return get_order(session.user_id, args["order_id"])
raise AccessDenied(f"Unknown tool: {call.function.name}")True or false?
Adding a required user_id parameter to the tool, so the model always passes the current user's id, is a safe way to give the tool the identity.
False. The model writes every argument, and a user can talk it into writing a different id. The identity has to be filled in by the application from the session.
It is fine for the model to choose which record id a tool should look up, as long as the code then checks that record against the user from the session.
True. Picking a record is the model's job. Deciding whether this user may have it is the code's job, done with an identity the model never touched.
Checking the record, not only the tool
Knowing who is asking is not yet enough. Many applications check only that the user may use a function at all: any customer may use "look up an order". That check is called function-level authorization. It says nothing about which order. If the lookup then fetches whatever id it is given, a customer who asks for someone else's order number gets someone else's name, address and purchases.
The check that closes this gap is object-level authorization: on every access, the code confirms that this user may read or change this particular record. When this check is missing, OWASP calls the flaw Broken Object Level Authorization and ranks it first in its API Security Top 10. In its description, the user is meant to reach the function; the violation happens one level lower, at the object, when the user changes the id. The same flaw is also known as an insecure direct object reference (IDOR).
Here are two versions of the same lookup over a small table of orders that belong to different users.
| Order | Owner | Item | Delivery address |
|---|---|---|---|
| A-1001 | maria | Desk lamp | 12 Elm Street |
| A-1002 | sam | Kettle | 4 Oak Road |
| A-1003 | maria | Notebook | 12 Elm Street |
-def get_order(order_id):
- return ORDERS[order_id]
+class AccessDenied(Exception):
+ pass
+
+def get_order(user_id, order_id):
+ order = ORDERS.get(order_id)
+ if order is None or order["owner"] != user_id:
+ raise AccessDenied("No order with that id for this user.")
+ return orderWith the first version, Maria can read order A-1002 simply by asking for it, and in an assistant she does not even need to know the id format: she can ask the model to try a few numbers. With the second, the lookup refuses any order whose owner is not the user from the session. Note that a missing order and someone else's order get the same answer, so the refusal does not reveal which ids exist. Trying a lookup like this against a system you do not own needs its owner's permission first.
Ownership is the simplest rule; real applications often have others, such as support staff who may read any order but change none. OWASP notes that comparing the session's user id with the id in the request covers only part of the cases, and that the check should come from the application's access policy. Whatever the rule is, it runs in code, on the record, every time.
Unguessable ids, such as long random strings, make guessing harder. OWASP treats them as an extra layer only. The check is still required, because ids leak through links, logs and earlier replies.
True or false?
If order ids are long random strings that nobody can guess, the per-record ownership check can be skipped.
False. Random ids are defence in depth. Ids still leak, for example in a shared link or a reply, and only the check on each record stops a user from opening one that is not theirs.
A user may be fully allowed to use a tool and still be refused on a specific call to it.
True. Function-level authorization lets them use the tool; object-level authorization then decides about the particular record named in this call.
Why an assistant is a confused deputy
The flaw above has an old name. In 1988 Norm Hardy described a compiler on a shared computer that was allowed to write into a system directory, because it kept its usage statistics there. The billing file lived in the same directory. A user who could not touch the billing file named it as the compiler's output file, the compiler wrote its output over it, and the billing records were destroyed. When the compiler opened the file, the system checked the compiler's permission, not the user's. Hardy called the compiler a confused deputy: a program that holds more rights than the person it works for, and is talked into using those rights on that person's behalf.
Nothing in the compiler was broken in the usual sense. It did exactly what it was asked. The flaw was that it acted with its own authority on a request from someone who lacked that authority.
- user: own orders only
- assistant: reads every order
- all orders
- "show order A-1002"
- with its own rights
An assistant with tools fits this description closely. Its tools usually reach the data store with one account that can read every customer's records, because the same tools serve all users. The person typing into it may only see their own. When the user, or text the model has read, persuades the model to request another customer's record, the tool does the work with the application's rights. The 2023 edition of the OWASP list of risks for LLM applications described a successful prompt injection in much the same terms: the compromised model effectively acts as an agent for the attacker. Its current edition asks to restrict the model's access privileges to the minimum it needs, and to handle privileged functions in code rather than leaving them to the model. The same list names a tool that serves individual users through one generic high-privileged identity as an example of Excessive Agency.
The way out is to make the deputy act with the authority of the person it serves. The tool receives that person's identity from the session and checks each record against it, so it can never do for a user what the user could not do directly.
True or false?
A confused deputy attack needs a bug in the deputy program's code.
False. The deputy can work exactly as written. The problem is whose authority it uses: its own, on a request from someone who does not have it.
An assistant whose tools read the data store with one account for all users holds more rights than any single user it serves.
True. That gap between the tool's rights and the user's rights is what makes it a confused deputy, unless each call is checked against the user it works for.
Every call goes through the check
A check that runs on most calls protects only those calls. In 1975 Saltzer and Schroeder wrote down a principle for protection systems that they called complete mediation: every access to every object must be checked for authority. For an assistant this means that every tool call, whatever the model asked for and however it was persuaded, passes through an authorization check in code before anything is read or changed. No tool, and no code path inside a tool, is left where the check is skipped.
- Tool call written by the model
- Dispatcher adds user from session
- Access check this user, this record
- Tool runs
- Refused nothing changes
- Tool call to Dispatcher
- Dispatcher to Access check
- Access check to Tool runs: allowed
- Access check to Refused: denied
Two habits keep the mediation complete. The first is to put the check where it cannot be bypassed: inside the function that touches the data, or in one dispatcher that every tool call must go through, with unknown tools refused by default. The second is to scope the lookup itself to the user, fetching "this user's order A-1002" in place of "order A-1002", so that a record outside the user's reach is never loaded in the first place.
What must never fill this role is the model's judgement. An instruction such as "only ever show the user their own orders" in the system prompt makes a leak less likely, but the model can be talked out of it, so nothing guarantees how it decides on any given call. OWASP's guidance on Excessive Agency asks for exactly this: implement authorization in logic rather than relying on the model to decide whether an action is allowed, and apply complete mediation to every request the tools make. The model decides what to ask for; code decides what is allowed.
True or false?
A firm instruction in the system prompt telling the model to refuse other users' records is an acceptable replacement for an ownership check in the tool.
False. A prompt only lowers the odds that the model goes along with a request. Access has to be decided by code that runs on every call, whatever the model decided.
If one tool out of ten skips the ownership check, the assistant is open through that one tool.
True. An attacker only needs one unchecked path, and the model can be steered to whichever tool provides it. Complete mediation means no such path exists.