Summary
SurrealDB fails to properly escape table and field names in command-line exports, allowing malicious SurrealQL to be embedded in backup data. If a higher-privileged user imports a crafted export, the injected query may execute with that user's privileges, potentially enabling privilege escalation and instance takeover.
Affected context
The vulnerability occurs in SurrealDB deployments that use the command-line export and import workflow while permitting authenticated System Users with OWNER or EDITOR roles to create tables or fields. It is especially relevant to applications that allow user-defined schema names, because malicious identifiers may be preserved in exported backups and later interpreted as SurrealQL during import.
Exploit preconditions
- Attack surface: SurrealDB command-line export and subsequent import workflows
- Required access: Authenticated System User permissions sufficient to create or modify tables or fields, such as OWNER or EDITOR
- Trigger point: Import of an attacker-influenced backup by a higher-privileged user
- Why exploitation is possible: Table and field names are not safely escaped before being written to export output, allowing embedded SurrealQL to be interpreted during import
Why this happens
The underlying bug is improper neutralization of dynamically generated query elements in exported SurrealQL. Table and field identifiers supplied through database metadata are incorporated into export statements without context-appropriate escaping, so attacker-controlled names can alter the meaning of commands when the backup is later imported. This behavior maps to CWE-77: Improper Neutralization of Special Elements used in a Command, and represents a second-order injection because the malicious input is stored first and executed only when processed later.
Potential impact
- A higher-privileged import operation may execute attacker-controlled SurrealQL
- An attacker could potentially escalate database privileges
- The SurrealDB instance could be taken over at root-level scope
- Data may be modified, disclosed, or destroyed
- Backups and downstream environments could be used for persistence or lateral compromise
General mitigation guidance
Mitigation generally focuses on treating schema identifiers and exported backup content as untrusted data.
Common defensive patterns include:
- Escaping or quoting table and field names according to the target SurrealQL context
- Using structured export and import representations that separate identifiers from executable query text
- Restricting which roles may create user-controlled tables or fields
- Applying strict naming policies and validating identifiers against an allowlist
- Treating imported backups as untrusted until reviewed and validated
- Running import operations with the minimum privileges required
- Separating backup restoration environments from production systems where practical
How teams detect issues like this
Organizations can look for this issue through:
- Static analysis of export code for string interpolation involving table or field names
- Code review signals involving unescaped identifiers in generated SurrealQL
- Tests using metacharacters and query syntax in user-controlled schema names
- Policy checks requiring context-aware escaping or structured query construction
- Monitoring imports of backups created from environments that permit user-defined schema objects
- Automated security review tools that flag command or query construction from untrusted metadata

