Agents, tools and permissions

Unit 4 of 5 in Securing LLM applications.

You will be able to limit an agent with narrow tools, user-scoped permissions and approvals checked outside the model, and review a tool server before connecting it.

Lesson

Agency is functions, permissions and autonomy

OWASP says an LLM-based system is often given some agency by its developer: the ability to call functions or interface with other systems through extensions, also called tools or plugins. Excessive agency is the vulnerability that allows damaging actions in response to unexpected, ambiguous or manipulated model output, whatever caused the model to misbehave: a hallucination, a prompt injection, a compromised extension or, in multi-agent systems, a compromised peer agent. The page names three root causes: excessive functionality, excessive permissions and excessive autonomy.

Its examples make each concrete. An extension meant only to read documents that can also modify and delete them. A database connection for reading that uses an identity with update, insert and delete permissions. An extension that acts for one user but reaches the data of all users through a generic high-privileged identity. A deletion tool that acts without any confirmation.

Shrink the toolbox

OWASP's first mitigations are to minimize the extensions an agent may call, and the functions inside each one: an extension that summarizes email only needs to read it, so it should not also send or delete. It advises avoiding open-ended extensions such as 'run any shell command' or 'fetch any URL' in favour of narrow ones, because an open-ended tool leaves an enormous space of possible actions. A file-writing tool that only writes the file you need is safer than a shell tool that could do anything.

The agent cheat sheet says the same in configuration terms: grant the minimum tools for the task, scope each tool's permissions (read-only versus write, specific resources), use separate tool sets for different trust levels, and require explicit authorization for sensitive operations. Its good example is a file-reading tool limited to a reports folder and read-only, with patterns such as environment files and keys blocked. It also says to fail closed for unknown tools.

Permissions follow the user, and the downstream system decides

Two more mitigations from OWASP: run extensions in the user's context, so an action on a user's behalf reaches downstream systems with that user's identity and the minimum privileges needed (for instance by asking the user to authenticate with the least OAuth scope required), and apply complete mediation, meaning authorization is checked in the downstream systems for every request instead of trusting the model to decide whether an action is allowed. Its example of minimum permissions is a purchase recommender that needs read access to one products table and nothing else, enforced by database permissions on the identity it uses.

The prompt injection cheat sheet repeats the core advice for agents: validate tool calls against user permissions and session context, validate tool parameters, use read-only database accounts where possible, and restrict API scopes and system privileges.

Approvals that mean something

OWASP recommends requiring a person to approve high-impact actions, implemented in a downstream system or inside the extension that performs the action. The agent cheat sheet explains what makes an approval real. A simple 'confirmed' flag is not enough. The component that executes the action, outside the agent's context, must check that the approval belongs to the current user and the exact tool call, is still valid and has not already been used, and it should check and consume the approval in one atomic step just before execution so repeated or concurrent requests cannot reuse it. A change to the target or the parameters needs a new approval, and unknown tools or missing approval rules fail closed.

It also suggests classifying actions by risk, from low (searching documents) to critical (deleting a database or transferring funds), previewing actions before running them, keeping an audit trail of decisions, and letting users interrupt and roll back. Name-based risk tiers have a trap: judge risk by the operation, target and arguments, not by the tool's name.

Tool servers: review them like software you are about to run

The Model Context Protocol (MCP) connects models to tools and data. Its security best practices page warns that local MCP servers run on the user's machine, may have direct access to it and may be reachable by other local processes. It lists attacks such as a malicious startup command in a client configuration, a malicious payload inside the server, and an insecure local server reached through DNS rebinding. Where a client offers one-click setup, the page says it must show a consent dialog with the exact command, untruncated, identify it as potentially dangerous because it runs code on the user's system, and require explicit approval.

The same page's section on scope minimization applies the least privilege idea to tokens: start with a minimal set of low-risk scopes, raise them step by step only when a privileged operation is first needed, accept tokens with fewer scopes than requested, and log elevation events. It warns that a stolen token with broad scopes lets an attacker reach unrelated tools and is hard to revoke without disrupting everything. Before you connect a server, read the tools it exposes as if you were reviewing a package: what can each do, with what permissions, and does its description match its behaviour.

Memory and teams of agents

The agent cheat sheet lists risks that appear when an agent remembers or works with others: malicious data kept in memory that influences later sessions or other users, and cascading failures where one compromised agent in a multi-agent system spreads the problem. Its recommendations are to validate and sanitize what is stored, isolate memory between users and sessions, set expiry and size limits, check memory for sensitive data before storing it, and protect long-term memory with integrity checks. Give each agent its own narrow credential so a problem in one cannot reach everything the team can reach.

Key points

Sources

Practice in the labs

Write the rules that gate an agent, review a tool server, and measure how well approvals and scoped credentials hold up. All labs use dummy data and run on your own machine.

Knowledge check

  1. An extension reads a user's documents but connects with an account that can also delete. Which root cause is this? Answer: Excessive permissions. OWASP gives this as an example of excessive permissions: the extension's identity on the downstream system has rights beyond what the feature needs.
  2. Why is a 'user_confirmed' flag in the prompt a weak approval? Answer: The executing component must verify an approval for that exact action, still valid and unused, outside the model. The agent cheat sheet says a simple flag is insufficient: the component that executes must check that the approval belongs to the current actor and exact tool call, is valid and not consumed, atomically, and fail closed.
  3. A client offers one-click setup of a local tool server. What must it show before running it? Answer: The exact command, untruncated, flagged as potentially dangerous, with explicit approval. The MCP security page says clients must show the exact command that will run, mark it as a potentially dangerous operation that executes code, and require explicit user approval.
  4. Which tool is the safer choice for an agent that must save a report? Answer: A tool that only writes one named file in a reports folder. OWASP advises avoiding open-ended extensions such as run-a-shell-command in favour of one with granular functionality, because the open-ended one allows a huge range of unintended actions.

Back to the syllabus or see all classes.

Related