Injection Protection Policy

Related Documentation
Made by
Kong Inc.
Priority
1007
Minimum Version
AI Gateway - 2.0
Tags

Don’t attach the Injection Protection Policy to an AI Consumer or an AI Consumer Group. Doing so stops the data plane from applying configuration changes. The data plane keeps running its previous configuration until you detach the policy.

Requests that carry SQL, script, or other injection payloads in a path, query string, header, or body can reach your models and tools unchecked. The Injection Protection AI Policy compares each request against regular expressions for known injection patterns, and either rejects matching requests or logs them. This policy can complement your existing firewall solution by adding a layer of customizable protection to prevent injection attacks, or it can eliminate some content-based attacks if you don’t have an existing firewall. Attach the policy to your AI Models, AI Agents, or AI MCP Servers, or apply it globally.

How does the Injection Protection Policy work?

The Injection Protection Policy processes each request in the following order:

  1. When an AI Model requires authentication, AI Gateway authenticates the client.
  2. The policy extracts content from the locations you configure.
  3. The policy compares that content against the regular expressions for the selected injection_types and any custom_injections.
  4. When the content matches, the policy acts according to enforcement_mode:
    • block: AI Gateway rejects the request with an error response before it reaches the provider, agent, or tool.
    • log_only: AI Gateway sends the request on and records the match.

Every match writes a warning to the data plane log, whichever enforcement mode you use. The entry names the injection type, the action taken, the location, and the content that matched:

threat detected: 'sql', action taken: block, found in query, query param value: q: ' OR 1=1 --

AI Gateway rejects blocked requests before a streaming response starts. Clients receive a standard JSON error response for streaming and non-streaming requests.

The xpath_abbreviated type matches strings such as //* and </script>, so it can match ordinary content. Run the policy with enforcement_mode set to log_only and review the log before you block traffic.

Scopes

Apply the Injection Protection Policy globally to inspect all AI Gateway traffic on the data plane, or attach it to an AI Model, an AI Agent, or an AI MCP Server to inspect that entity only. For details about how scopes work, see AI Policy scopes.

Global scope applies the same patterns to all traffic, so a pattern that matches ordinary content, such as xpath_abbreviated, affects every entity. To limit that risk, attach the policy to one entity first, or start with log_only.

On an AI MCP Server, the policy inspects every MCP request, including initialize and tools/list.

Looking for on-prem configuration? Convert the kongctl configuration to a decK yaml file and use deck file ai2kong. See Configure Kong AI Gateway on-prem for more information.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!