Book an audit
All posts

Governance23 Nov 20263 min read

Stopping OWASP Agentic AI attacks at the MCP gateway

Why prompt guardrails cannot stop indirect prompt injection or MCP tool rug pulls, and how five deterministic BYOC gateway controls enforce ASI01 through ASI06.

Teams connecting language models to Model Context Protocol (MCP) servers quickly discover an uncomfortable boundary: the model reading an untrusted invoice or email is the same component deciding which MCP tool call to propose next. When your enforcement lives inside a system prompt, a single adversarial string in an external document competes directly with your security policy.

Governance has to sit outside the model, in deterministic infrastructure that the LLM cannot rewrite or bypass.

We just released v0.1.0 of truly-agentic-governance-kit under Apache-2.0 so engineering and InfoSec teams can inspect and run these controls locally. All test suites and included attack scenarios run strictly on synthetic lab fixtures and local harnesses — never customer production deployments.

Two failure modes prompts cannot stop

Indirect prompt injection (ASI01)

In an invoice or support workflow, the model reads vendor PDFs, HTML email bodies, and attachment notes supplied by external parties. Hidden <IMPORTANT> blocks, zero-width characters, or role delimiters injected inside an invoice description can instruct the model to alter a payout destination or invoke a write tool with inflated amounts. Ask an LLM to ignore untrusted instructions, and you still have a probabilistic classifier guarding deterministic financial or identity state.

MCP tool poisoning and rug pulls (ASI04)

Even when a prompt looks benign, MCP tool schemas themselves are untrusted supply-chain inputs. A compromised third-party or community MCP package can embed covert exfiltration instructions inside a tool description (ASI04), or behave cleanly at registration time and mutate its manifest or parameters days later in a rug pull.

If your runtime does not cryptographically pin approved tool manifests and validate every argument outside the model context window, the first sign of drift is a production write.

Five deterministic controls at the gateway

To keep security guarantees verifiable, every tool call in our architecture passes through an enforcement choke-point before touching an external ERP, CRM, database, or cloud API:

  1. Provisioned service identities (AgentRegistry) — Agents run under scoped workload identities with explicit tool allowlists, rejecting personal handles, root, and shared admin credentials (ASI03).
  2. Read / propose / write separation (PolicyEngine) — Permissions align with the five Levels of Agency and verify monetary ceilings, currency codes, IBAN prefixes, and allowlisted vendor domains in typed application code (ASI02, ASI05).
  3. Named individual human sign-off (ApprovalGate) — Sensitive write calls pause on Slack Block Kit tickets verified via HMAC-SHA256, binding an individual approver ID (usr_*) to the exact SHA-256 input digest and idempotency key to neutralize duplicate-click replays.
  4. Budget reservations and instant kill switch — Estimated workflow spend is reserved pre-flight, and suspending an agent lease immediately blocks subsequent execution with a signed revocation record.
  5. Fail-closed "No log, no action" ledger — Before executing any downstream call, the gateway writes a SHA-256 hash-chained pre_execution record to PostgreSQL enforced by triggers that block UPDATE and DELETE. If the audit sink is unreachable, execution aborts (ASI06).

Scanning untrusted payloads and pinned MCP manifests

Before any model output reaches policy evaluation, scanUntrustedPayload checks inbound documents and ticket bodies for hidden HTML/XML injection markers, role overrides, and zero-width obfuscation. In parallel, scanMcpToolDefinition verifies connected MCP tool metadata against SHA-256 pinned manifests so unreviewed description changes or schema drift fail closed before invocation.

You can reproduce all six local defense scenarios — including an offline audit sink abort, an injected invoice hijack, an MCP rug pull, a Slack replay attack, and kill-switch revocation — in one command from the repository:

pnpm install
pnpm run demo:attack

Where architecture review begins

Running deterministic policy checks at the gateway also keeps Bring-Your-Own-Cloud isolation straightforward: the gateway container, PostgreSQL append-only ledger, secrets manager, and private VPC inference endpoints stay inside your own AWS, GCP, or Azure account, paired with starter Terraform modules.

If your team is moving internal MCP integrations or operational agents toward production and wants a concrete, read-only risk map first, review the v0.1.0 governance kit on GitHub or book an Agentic Operations Audit.

Written by

Anil Pervaiz

Software, web and mobile engineer since 2016 based in Dubai (UTC+4). Builds Bring-Your-Own-Cloud agentic systems, MCP OAuth gateways and deterministic operational controls.

Book an audit