Agent Permissions and Execution Safety
🎯 Introduction
Agents can select tools for a task automatically, but a model's suggestion to close a ticket does not mean the operation is approved. High-risk operations such as closing tickets or deleting records need current user permission checks before execution, plus approval tied to a specific request. This article implements permission checks, approval bound to operation parameters, and one-time execution for ticket closure, preventing an agent from bypassing approval or swapping the target ticket.
🧱 Separate requests, approval, and execution
An employee may have permission to close tickets while company policy still requires a manager's approval. Permission determines who may act; approval determines whether this particular operation may proceed.
The diagram below shows what the model can propose and what the server must handle.
Separate proposals, authorization, approval, and execution
Approval covers one specific request; it cannot be reused or transferred to another target
1. Model proposal
Close ticket t1
2. Permission check
User, ticket, tenant
3. Manager approval
Bind approval to request parameters
4. One-time execution
Unexpired, unused, unchanged
Follow these steps in order. Reject execution if any check fails; the model cannot replace the approver.
| Stage | Responsible party | Required checks |
|---|---|---|
| Proposal | Model | Tool name and target parameters are only a request awaiting review |
| Authorization | Server | User identity, tenant, operation permissions, and resource ownership |
| Approval | Trusted approver | Specific target and parameters of this operation |
| Execution | Server | Approval is valid, unexpired, unused, and matches unchanged parameters |
🛠 Protect ticket closure with one-time approval
Use Node.js 22 built-in APIs without additional dependencies. Create 09.agent-permissions.mjs:
import { createHash, randomUUID } from 'node:crypto';
const tickets = new Map([
['t1', { tenantId: 'team-a', status: 'open' }],
['t2', { tenantId: 'team-a', status: 'open' }]
]);
const approvals = new Map();
// Simulate identities supplied by trusted server-side sessions
const actor = { id: 'u1', tenantId: 'team-a', permissions: ['ticket:close'] };
const manager = { id: 'm1', tenantId: 'team-a', permissions: ['ticket:approve'] };
const proposal = { actorId: 'u1', tenantId: 'team-a', tool: 'ticket:close', ticketId: 't1' };
function fingerprint(request) {
return createHash('sha256').update(JSON.stringify({
actorId: request.actorId,
tenantId: request.tenantId,
tool: request.tool,
ticketId: request.ticketId
})).digest('hex');
}
function authorized(request, user) {
const ticket = tickets.get(request.ticketId);
return request.actorId === user.id &&
request.tenantId === user.tenantId &&
request.tool === 'ticket:close' &&
user.permissions.includes('ticket:close') &&
ticket?.tenantId === user.tenantId;
}
function approve(request, approver, user) {
if (!authorized(request, user) ||
!approver.permissions.includes('ticket:approve') ||
approver.tenantId !== user.tenantId) return null;
const id = randomUUID();
approvals.set(id, { hash: fingerprint(request), expiresAt: Date.now() + 60000, used: false });
return id;
}
function execute(request, approvalId, user) {
if (!authorized(request, user)) return 'FORBIDDEN';
const approval = approvals.get(approvalId);
if (!approval) return 'NEEDS_APPROVAL';
if (approval.used) return 'ALREADY_USED';
if (approval.expiresAt <= Date.now()) return 'EXPIRED';
if (approval.hash !== fingerprint(request)) return 'CHANGED_REQUEST';
approval.used = true;
tickets.get(request.ticketId).status = 'closed';
return 'CLOSED';
}
console.log(execute(proposal, null, actor));
const approvalId = approve(proposal, manager, actor);
console.log(execute({ ...proposal, ticketId: 't2' }, approvalId, actor));
console.log(execute(proposal, approvalId, actor));
console.log(execute(proposal, approvalId, actor));
Run node 09.agent-permissions.mjs:
NEEDS_APPROVAL
CHANGED_REQUEST
CLOSED
ALREADY_USED
The second request replaces t1 with t2 in the same team. Although the user has closure permission, the operation fingerprint no longer matches the approval, so it returns CHANGED_REQUEST. Approval covers only the approved request; its credential cannot authorize a different operation.
🧱 What else must real systems check?
The example keeps authentication, approver identities, and ticket data in memory to highlight the key logic. In production:
actorandmanagermust come from authenticated server-side sessions, not values supplied or fabricated by the model.- Record the approver, time, reason, and request contents in transactional storage.
- Consume approval and execute the operation in the same transaction; otherwise, two concurrent requests could both pass the one-time check.
- Before execution, validate tool arguments, check the current ticket state, and record audit events.
This is more reliable than merely prompting that ticket closure requires approval, because the model cannot decide whether approval is valid.
❓ Questions and answers
Q1: Why is manager approval needed when a user has ticket:close permission?
Permission establishes eligibility to act. Approval confirms the specific target and timing of this high-risk operation.
Q2: Can an approval token be reused?
It should not be reused. Bind one-time approval to target parameters and atomically mark it used when execution succeeds.
🧪 Exercise
Change tool or actorId in proposal and try the original approval ID. Then add a manager from team-b and test whether they can approve a team-a ticket.
Acceptance criteria: Changing the target returns CHANGED_REQUEST, a manager from another team cannot approve, and the original request succeeds at most once. Explain why an in-memory Map cannot guarantee atomic approval consumption across multiple instances.
🎉 You now know how to require authorization and approval before an agent's high-risk proposal becomes an operation.
MCP Security
Connect safely to MCP servers over Streamable HTTP, restrict tool calls with allowlists and definition checks, and understand access token boundaries.
Agent Memory and Context Security
Control the sources, user scopes, and expiration of agent memory to prevent cross-user exposure and memory poisoning.
