AI-agent security audit and approval workflows for a commodities-trading platform

Photo: Bulk carrier at Halifax Grain Elevator by Quintin Soloviev, CC BY 4.0.

A bulk carrier loading at a grain terminal

Problem

The client is an AI startup building an operating system for physical commodity trading companies, the firms that buy, ship and sell sugar, grains, fuel and other physical goods. Its platform automates the work between trade capture and settlement. AI agents read trade confirmations, contracts and shipping documents out of email, PDFs and chat messages, turn them into system-ready records, check contracts against their terms, and escalate exceptions to a person. Its customers include large global trading houses. The platform is SOC 2 Type II audited and sells to enterprises, so an agent that could act outside a user's role was a serious problem.

Its in-app assistant, built on the Claude Agent SDK with in-process MCP tools, could update records regardless of the user's role. Role checks lived only in the HTTP middleware; the agent called shared services directly. Separately, the approvals engine for trade confirmations was broken end to end for an enterprise design partner: no notifications, contracts never activated, no stale-decision or concurrency guards, and no way to resubmit after a rejection.

What I built

Agent security audit: traced the agent's ~80 tools against the permission layer and wrote up five findings framed as OWASP LLM06 (excessive agency): write-path bypass, read-path exposure within a tenant, an open prompt-injection surface through attachments and email content, guardrails that weren't permission checks, and unguarded task-agent handlers. The plan adds a central gate in the tool wrapper that reuses the product's existing permission primitive, then parity tests.

Approvals epic: I audited the engine against the user-journey spec and wrote the gap analysis the engineering lead cut into 27 tickets, all assigned to me. I built a grouped approval-request model with revisions and resubmit, auto-activation, role notifications, a trigger-maintained content version for stale-decision protection, clean concurrency errors, and an approver view that reuses the trade form with the AI assistant alongside it.

I also shipped about 25 accounting and invoicing PRs and a public reporting API with a self-describing data-completeness catalog.

Stack

Claude Agent SDK, MCP, E2B, Next.js 16, React 19, TypeScript, Drizzle ORM, PostgreSQL / Supabase (RLS, triggers), Zod, Trigger.dev, shadcn/ui, Jest, Vitest, Playwright

Outcome

Audit and implementation plan delivered to the engineering leads in August 2026. The consolidated approvals feature PR was merged to main on August 2, 2026, with follow-up fixes through late August.