- 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.
Identity & least agency
Replace god-mode service keys with user-delegated OAuth 2.1 tokens and tightly parameterized tools.
Runtime policy & approvals
Intercept every write call with deterministic schema/limit checks and human-in-the-loop gates.
Injection & egress defense
Isolate untrusted documents from instructions, restrict outbound domains, and cap loops and spend.
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.
| Action tier | Examples | Required control | Who executes |
|---|---|---|---|
| Tier 0: Read | Lookup order status, search internal docs, read ticket history | User-delegated row-level auth + PII redaction in logs | Agent automatically |
| Tier 1: Draft | Draft email reply, create unapproved quote, stage Jira ticket | Isolated draft state; zero external side effects until edited/sent | Agent automatically |
| Tier 2: Bounded write | Tag support ticket, log call note, update status within allowed state machine | Deterministic server policy check + idempotency key + rate cap + audit log | Agent within strict bounds |
| Tier 3: High-impact | Send external email, issue refund, delete records, bulk update, change roles | Mandatory Human-in-the-Loop (HITL) approval token + diff preview | Human 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  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
- OWASP Top 10 for LLM Applications (Prompt Injection & Excessive Agency) (checked Nov 30, 2026)
- Model Context Protocol — Authorization Specification (OAuth 2.1, PKCE, RFC 8707) (checked Nov 30, 2026)
- IETF RFC 9728 — OAuth 2.0 Protected Resource Metadata (checked Nov 30, 2026)
- IETF RFC 8707 — Resource Indicators for OAuth 2.0 (checked Nov 30, 2026)
- Promptfoo — Red-Teaming & Automated LLM Security Testing (checked Nov 30, 2026)
- Cloud Security Alliance — Agentic AI Security & Governance Guidance (checked Nov 30, 2026)