Summary
ProxySQL's GenAI/MCP run_sql_readonly tool fails to enforce its documented read-only behavior for MySQL targets in versions 3.0.0 through 3.0.8.
Because it validates only the first keyword and uses weak blacklist checks while executing the full SQL with multi-statements enabled, an MCP caller can smuggle side-effecting SQL after a benign-looking read-only query.
Affected context
This vulnerability occurs in deployments that:
- Enable the GenAI/MCP integration and expose the
/mcp/queryendpoint - Configure MySQL targets for the
run_sql_readonlytool - Rely on the tool's documented read-only contract for safety
The risk is highest when MCP backend database credentials have write or administrative privileges, or when the MCP endpoint is reachable by less-trusted callers or automated agents.
Exploit preconditions
- Attack surface: The ProxySQL MCP
/mcp/queryHTTP endpoint using therun_sql_readonlytool. - Required access: Ability to call the MCP query endpoint (network reachability) and satisfy any configured
mcp-query_endpoint_authtoken or upstream authentication. - Trigger point: Submission of a SQL payload where the first statement is read-only (for example,
SELECT) followed by a second, side-effecting statement. - Why exploitation is possible: The validator only inspects the overall SQL text with naive substring blacklisting and "first keyword" allowlisting, but then passes the entire string to a backend connection configured with
CLIENT_MULTI_STATEMENTS. This allows additional statements such asRENAME TABLE,SET,RESET,LOCK TABLES, orKILLto execute despite the read-only contract.
Why this happens
The root cause is an improper input validation pattern where security decisions are based on shallow string checks instead of the actual semantics of the entire SQL payload.
The run_sql_readonly tool assumes that:
- Checking the first keyword against a read-only allowlist, and
- Applying a simple blacklist to the raw SQL string
are sufficient to prevent state-changing operations. This is incorrect when the execution layer enables multi-statement support and does not enforce a strict single-statement or read-only mode on the backend connection.
Conceptually, this maps to CWE-20: Improper Input Validation, where validation logic fails to fully constrain untrusted input before it is used, leading to a violation of the intended read-only security contract.
Potential impact
- Attackers could perform write operations (e.g.,
RENAME TABLE,INSERT,UPDATE, orDELETEif reachable via multi-statements). - Callers may execute administrative or session-affecting SQL, such as
SET,RESET,LOCK TABLES, orKILL. - Data integrity could be impacted through schema changes or table renames.
- Application behavior may be disrupted if critical tables are renamed, locked, or otherwise modified.
- Security assumptions around "read-only" database access from GenAI/MCP workflows can be undermined, enabling lateral movement or privilege misuse depending on the database account's rights.
General mitigation guidance
Effective mitigation focuses on tightening validation, constraining execution, and minimizing trust in the MCP surface:
- Replace heuristic string checks with strict SQL parsing or use database-native features (such as read-only users and transaction modes) to guarantee no state changes.
- Enforce single-statement execution for read-only tools and disable multi-statement options like
CLIENT_MULTI_STATEMENTSwhen the contract claims read-only behavior. - Configure MCP backend credentials as least-privilege, read-only database accounts, so even if validation fails, the database enforces read-only semantics.
- Limit MCP endpoint exposure via network controls, and require strong authentication (for example, non-empty
mcp-query_endpoint_authtokens). - Introduce defensive query rules or proxy policies that block obvious multi-statement patterns and side-effecting keywords, while recognizing this as a supplement to—not a replacement for—backend permissions.
How teams detect issues like this
Organizations can detect this class of issue and its misuse by:
- Reviewing MCP and database logs for multi-statement sequences where a benign
SELECTis immediately followed by schema or administrative commands. - Adding application-level or WAF rules that flag or block MCP requests containing semicolons followed by side-effecting SQL keywords.
- Using static analysis or configuration review to identify:
- Use of
CLIENT_MULTI_STATEMENTSin code paths documented as read-only - Reliance on naive keyword-based or blacklist-driven SQL validation for security guarantees
- Incorporating security-focused code reviews for MCP- and GenAI-related features, ensuring that read-only contracts are enforced by both input validation and backend privilege configuration.

