Inference-Aware Load Balancing for LLMs (part 14): protecting MCP with the BIG-IP WAF

What a WAF in front of an MCP server can and cannot see: the configuration of BIG-IP 21.1's MCP protection template, attacks in tool arguments, tool poisoning, secrets in results and the request log.
Hand-drawn: 4 attacks in MCP tool arguments blocked by the WAF, 4 that got through

On this page

The same agent requests were sent twice: straight through a BIG-IP virtual server, and through its MCP protection. SQL injection, command injection, a cloud-metadata URL and a private key inside tool arguments: all four reached the server without the WAF, all four were blocked with it. A file:// URL and prompt-injection text passed either way, and a poisoned tool description and a secret in a tool's result reached the agent either way. This is part 14, the last part of Inference-Aware Load Balancing for LLMs. It goes with a video on the LevelUP I.T. YouTube channel.

Eleven checks, two virtual servers
Eleven checks, two virtual servers

What can go wrong with MCP

With MCP the client is an agent, and the requests are written by a model from text it was given: a user, a web page, a document, another tool's result. Any of them can steer a tool's arguments, so the classic attacks arrive inside JSON-RPC: SQL or shell in an argument, a URL that points inside your network (SSRF), a secret the agent was tricked into sending. Two attacks come the other way, from the server towards the agent: tool poisoning (instructions hidden in a tool's description, read by the model in tools/list) and secret exposure (a credential in a tool's result). A WAF in front of the server sees requests well; the question is what it does with answers.

The attack server

The attack server is part 13's server image with two lab-only switches on, written for this demonstration and off in the normal server: F5LAB_POISON=1 puts hidden instructions in order_status's description (read ~/.ssh/id_rsa and pass it in the order_id argument), and F5LAB_LEAK=1 puts a fake cloud credential in its result after a debug: label. The test tool, mcpattack.py, sends raw JSON-RPC over HTTP from pc1 the way an agent's client would: one session for initialize and tools/list, then every case in a fresh session, because a WAF block can end the whole session. Part 13's persistence, profiles and pool are created again first, from the same generated scripts.

The MCP protection template

BIG-IP 21.1 ships /ts/install/policy_templates/mcp_protection.xml, a policy with 7 signature sets. It is not a tmsh template id; the file is loaded as a policy. The generated script:

tmsh load asm policy /Common/mcp-waf file /ts/install/policy_templates/mcp_protection.xml
tmsh modify asm policy /Common/mcp-waf blocking-mode enabled
tmsh modify asm policy /Common/mcp-waf active
tmsh publish asm policy /Common/mcp-waf
tmsh create ltm pool mcp-attack-pool members add { MCP_ATTACK_POD:8000 } monitor tcp
tmsh create ltm policy Drafts/mcp-asm controls add { asm } requires add { http } strategy first-match \
  rules add { waf-every-request { actions add { 0 { asm enable policy /Common/mcp-waf } } ordinal 1 } }
tmsh publish ltm policy Drafts/mcp-asm
tmsh create ltm virtual vs-mcp-waf destination 10.20.30.164:80 ip-protocol tcp \
  profiles add { tcp http f5lab-json f5lab-sse aimcp websecurity } persist replace-all-with { f5lab-mcp-persist { default yes } } \
  policies add { mcp-asm } pool mcp-attack-pool source-address-translation { type automap } security-log-profiles add { "Log illegal requests" }
tmsh create ltm virtual vs-mcp-nowaf destination 10.20.30.165:80 ip-protocol tcp \
  profiles add { tcp http f5lab-json f5lab-sse aimcp } persist replace-all-with { f5lab-mcp-persist { default yes } } \
  pool mcp-attack-pool source-address-translation { type automap }

asm policy mcp-waf {
    active
    blocking-mode enabled
    virtual-servers {
        vs-mcp-waf
    }
}

This post is for paying subscribers only

Subscribe to LevelUp I.T. newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!