SurrealDB MCP: escaped backticks could inject SurrealQL
A high-severity advisory shows how MCP identifier validation and SurrealQL lexing disagreed. What broke, who is affected, and what to check this week.
On 3 November 2026 SurrealDB published a high-severity advisory for its built-in Model Context Protocol (MCP) integration. An identifier passed through an MCP tool could carry an escaped backtick that the MCP validator treated as the end of the name, while SurrealQL's lexer still treated the escape as part of the identifier. The mismatch let a caller break out of a quoted identifier and run a SurrealQL statement the tool arguments were never meant to allow. The fix is in SurrealDB 4.0.0. Teams that expose SurrealDB to coding agents through MCP should treat the version check as urgent, not as a routine upgrade note.
What the advisory says
The advisory, GHSA-cr79-9p8r-p5wx, affects the surrealdb Rust package below 4.0.0. The patched line is 4.0.0 and later. SurrealDB rates it high. The advisory lists no CVE identifier.
The mechanism sits in the MCP tool layer, in surrealdb/mcp/src/tools/mod.rs (consume_backtick_ident, validate_identifier) and in the CRUD tools that build queries from those identifiers. In short:
- The MCP identifier validator treats the first backtick as the closing delimiter of a quoted identifier, even when a backslash sits in front of it.
- SurrealQL's SQL parser recognises an escaped backtick as a literal backtick inside the identifier, so the quote is not closed there.
- An identifier that contains that escape can therefore leave the quoted region and continue as raw SurrealQL once the query string is assembled.
The impact the advisory states is arbitrary SQL query execution through MCP tool invocation, bypassing the constraints the tool arguments were supposed to enforce. Reported by ARSB. The remediation SurrealDB recommends is to keep MCP identifier parsing in sync with the SurrealQL lexer, or to build queries with parameterised AST nodes instead of string interpolation. The patch commit named in the advisory is ec41ae8f15.
A separate write-up by Tim McAllister restates the same mismatch and the same upgrade advice: move to 4.0.0 or later, and until then restrict MCP tool access to trusted callers and least-privilege database roles. That page is secondary analysis; the facts below follow the vendor advisory.
Why two parsers for one string is a pattern
MCP tools often take names (tables, fields, namespaces) as plain strings and then embed them in a query language the host product already speaks. Validation at the MCP boundary and lexing inside the database are easy to implement separately. When those two views of escaping disagree, the "safe" path at the edge is not the path the engine executes.
This is not a prompt-injection story. The model does not have to be tricked into choosing a dangerous tool. Anyone who can invoke the MCP tool with a crafted identifier can try the break-out, subject to whatever authentication the SurrealDB MCP surface already requires. The advisory does not claim remote unauthenticated access; it claims that once a tool call is accepted, argument constraints on identifiers are not enough.
The same class of bug shows up wherever an agent-facing API reuses a host language's quoting rules without sharing that language's lexer. Identifier validation that stops at "contains only safe characters" is incomplete when the host language has an escape that changes where a quote ends.
Who is affected
Affected installations are those running SurrealDB below 4.0.0 with the MCP server integration in use. If SurrealDB is only used through its usual query APIs and never exposed as an MCP server to agents, this particular advisory does not apply. If agents or automation call SurrealDB MCP tools against a cluster still on 3.x, they are in scope.
The advisory lists no CVSS vector and labels the severity high, which is the vendor's own rating. No exploitation is claimed in the advisory text.
What it means for engineering and security leaders
Three operational points follow from the advisory, independent of SurrealDB's product roadmap.
Inventory beats hope. Knowing which MCP servers developers run is no longer optional. A SurrealDB MCP entry in a project .mcp.json, a desktop client config or a shared agent profile is a live query path into a database. Earlier articles on this blog have argued that an MCP server entry is a command; here the command is a query builder with a broken identifier fence.
Argument schemas are not a security boundary by themselves. Tool definitions that describe "identifier" or "table name" fields give the model (and the caller) a shape. They do not guarantee that the string that arrives is safe once another parser sees it. For databases behind MCP, prefer parameterised construction on the server, and treat free-form identifiers as hostile until proven otherwise.
Version pinning for agent dependencies needs the same discipline as application dependencies. Coding agents pull MCP servers and SDKs outside the application lockfile. SurrealDB 4.0.0 has to appear in whatever inventory you use for agent tooling, not only in the service's own deploy pipeline.
Practical takeaways
- Check the SurrealDB version on every environment that exposes MCP tools. Upgrade to 4.0.0 or later where the MCP integration is enabled.
- Search agent configs for SurrealDB MCP servers (project and user-level). Confirm each one points at a patched instance.
- Until you can upgrade, limit who can call the MCP tools, and give those connections database roles that cannot run arbitrary statements beyond what the product needs.
- Review how your own MCP servers build queries. If they interpolate identifiers into SQL or SurrealQL strings, ask whether validation and lexing share one definition of escaping.
- Add "parser agreement" to MCP security review. When a tool wraps an existing query language, the review should name the lexer that will see the string and the validator that claimed it was safe.
- Record the advisory in your vulnerability process as GHSA-cr79-9p8r-p5wx against
surrealdb< 4.0.0, patched in 4.0.0.
Where a gateway fits
The SpanDock MCP gateway documentation says every connector starts read-only for everyone, that destructive tools still need approval when write access is granted, and that every call is recorded. The MCP gateway is on the Premium and Enterprise plans. The page does not describe SurrealDB, identifier escaping or statement injection, so a gateway narrows who can call which tools and keeps an audit trail; it does not replace upgrading SurrealDB or fixing how a connector builds queries.