SQL Injection in MCP Servers
Classic SQLi and read-only-mode bypasses in the database connectors (MCP servers) and LLM gateways that expose SQL engines to AI agents — where the “untrusted input” is often the agent itself.
How it works
Model Context Protocol servers wrap a database as tools (execute_query, describe_table, update_data) for an LLM agent. They inherit every SQLi failure mode of ordinary software, with two twists: (1) tools frequently interpolate agent-supplied identifiers (table names, filters) that can’t be parameterized, and (2) they advertise a read-only mode as the primary safety guarantee — so a read-only bypass, not just data theft, is the core finding. These are OWASP-Top-10 bugs in new plumbing (Datadog case study). Related surface: LLM gateways that store provider credentials in SQL. Link: MCP Security.
Techniques / payloads (bypass patterns)
- Transaction escape — Anthropic’s reference Postgres MCP server ran queries inside a read-only transaction; appending
COMMIT;ends it and lets subsequent statements write (Datadog). - Statement chaining /
ATTACH— sqlite-mcp: statement chaining inexecute_queryand SQLi indescribe_tableboth enableATTACH DATABASEto escape read-only, read arbitrary SQLite files, and create files anywhere the process can write (sqlite-mcp). - Comment-parsing divergence — DBHub (GHSA-j656-3hf2-fvjc): its parser treats
--as a comment regardless of the next char, but MySQL/MariaDB only start a--comment when followed by whitespace. SoSELECT 1--1;DROP TABLE victimpasses the read-only check as one SELECT, but the connector (opened withmultipleStatements: true) runs both (DBHub). - PRAGMA/stacked-statement injection — Tabularis (CVE-2026-118378): a crafted
table_nameintodescribe_tablecloses thePRAGMAargument and appends stacked statements to read/modify/drop SQLite data, bypassing read-only and write-approval (Tabularis). - Identifier-validation vs. lexer mismatch — SurrealDB MCP (GHSA-cr79-9p8r-p5wx): escaped backticks mishandled between identifier validation and SQL lexing let an attacker break out of a quoted identifier; mssql-mcp interpolated unparameterized table names/predicates in
update_data/delete_data, reaching stacked statements andxp_cmdshell.
Notable cases
- Anthropic reference Postgres MCP — deprecated/archived but still ~21k weekly npm downloads; patched in the Zed Industries fork (Datadog).
- Tabularis CVE-2026-118378 (CVSS 4.0: 8.5) — read-only bypass in the SQLite driver before 0.28.0.
- DBHub, sqlite-mcp, mssql-mcp (patched 0.6.0), SurrealDB (fixed 4.0.0) — a cluster of 2026 MCP DB-connector SQLi/read-only bypasses; a bug hunter tracked three serious MCP DB flaws, one left unpatched (The Register).
- LiteLLM CVE-2026-42208 / Kong AI Gateway — LLM gateways with SQLi in key-verification and usage counters, leaking stored provider credentials (covered in SQL Injection and Union-Based SQL Injection).
Defenses
Parameterize queries and validate identifiers in MCP tools exactly as in any app — read-only mode is not a substitute. Enforce read-only at the database/connection layer (a read-only role, default_transaction_read_only), not by parsing the SQL string, since parser divergence defeats string checks. Disable multipleStatements/stacked queries on the connection. Don’t expose deprecated reference servers to sensitive data. Treat the agent’s SQL as untrusted input, because indirect prompt injection can make the agent emit attacker-chosen queries (Indirect Prompt Injection).
Related
Sources
- MCP Vulnerability Case Study: SQLi in the Postgres MCP Server · original
- DBHub: MySQL comment interpretation bypasses read-only validation · original
- sqlite-mcp: read-only bypass via statement chaining and SQLi · original
- Tabularis MCP SQL injection read-only bypass (CVE-2026-118378) · original
- SurrealDB MCP tool identifier statement injection · original
- mssql-mcp SQL injection via unparameterized table names · original
- Bug hunter tracks down three serious MCP database flaws · original