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
- Excessive agency has three roots: too many functions, too many permissions, too much autonomy.
- Give agents few, narrow tools; avoid open-ended tools such as run-any-command or fetch-any-URL.
- Act in the user's context with minimum scopes, and let the downstream system make the authorization decision.
- A real approval is tied to the exact action, checked outside the model, used once and fails closed.
- Review MCP servers before connecting: show the exact command, use minimum scopes and log elevations.
- Isolate and validate agent memory; give each agent its own scoped credential.
Sources
- OWASP GenAI Security Project: LLM06:2025 Excessive Agency
- OWASP Cheat Sheet Series: AI Agent Security
- Model Context Protocol documentation: Security Best Practices
- OWASP Cheat Sheet Series: LLM Prompt Injection Prevention
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.
- Gate an AI agent's tool calls with an OPA/Rego allow-list: deny by default, constrain the arguments, and unit-test every denial: You write an allow-list policy for an agent's tool calls and unit-test the denials, including the boundary at exactly the limit.
- Lock down a coding agent with permission rules before it touches your repo: protect .env and block destructive commands: You set deny, ask and allow rules and a sandbox for a coding agent in a throwaway repository, and note which test prompts were blocked, prompted or allowed.
- Review an MCP server's tools before you connect it, and write a default-deny allow-list: You review a server's tool list, write a default-deny allow list and spot a tool whose description contradicts its name.
- Defend an MCP client against tool poisoning and rug pulls: detect malicious tool descriptions and definition drift before the agent trusts them (offline, no API key): You compare a naive defence with a layered one that checks the whole tool definition for changes, scans descriptions and blocks cross-server shadowing.
- Tier an agent's approval requests by risk and measure approval fatigue (Part 2 of the approval gate): You compare approval policies on how many wrong approvals slip through and how many prompts a person must answer.
- Give each agent in a team its own scoped credential: measure blast radius and attribution when one agent is hijacked (free, offline, no API key): You issue each agent a signed, expiring, scoped token and measure how far one compromised agent can reach.
- Contain cross-agent prompt-injection propagation in a multi-agent system: the confused-deputy attack that jumps agent to agent, measured and defended (free, offline — no API key): You build a small reader, planner and actor system and measure how injection spreads before and after four layered defences.
- Secure a text-to-SQL agent against injection-driven data exfiltration: You turn a naive database agent into a read-only, deny-by-default one and test it against cross-table questions it must refuse.
- Sandbox AI-generated code with a locked-down executor (contain the code your agent writes): You run model-written code in a locked-down executor and check that harmless escape attempts fail.
Knowledge check
- 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.
- 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.
- 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.
- 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
- Securing LLM applications
- Gate an AI agent's tool calls with an OPA/Rego allow-list: deny by default, constrain the arguments, and unit-test every denial
- Lock down a coding agent with permission rules before it touches your repo: protect .env and block destructive commands
- Review an MCP server's tools before you connect it, and write a default-deny allow-list
- Defend an MCP client against tool poisoning and rug pulls: detect malicious tool descriptions and definition drift before the agent trusts them (offline, no API key)
- Tier an agent's approval requests by risk and measure approval fatigue (Part 2 of the approval gate)
- Give each agent in a team its own scoped credential: measure blast radius and attribution when one agent is hijacked (free, offline, no API key)
- Contain cross-agent prompt-injection propagation in a multi-agent system: the confused-deputy attack that jumps agent to agent, measured and defended (free, offline — no API key)
- Secure a text-to-SQL agent against injection-driven data exfiltration
- Sandbox AI-generated code with a locked-down executor (contain the code your agent writes)
- All classes
- Free cyber labs