/

CVE-2025-71392

Severity:

HIGH RISK

(8.0)

Command Injection (CWE-77) in SurrealDB CLI Export

CVE-2025-71392

Analyzed

Vulnerability type

Category:

SurrealQL Injection

CWE:

CWE-77

Impact:

Privilege Escalation and Database Takeover

Severity:

HIGH RISK

(8.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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

Sources

SourceLink
github.comgithub.com/surrealdb/surrealdb/security/advisories/GHSA-ccj3-5p93-8p42
vulncheck.comvulncheck.com/advisories/surrealdb-before-surrealql-injection-via-export

Frequently asked

questions

Exploitation is generally indirect. An attacker must first create malicious table or field names and then influence a backup that a higher-privileged user or process later imports.

The attacker needs authenticated System User access with permissions such as OWNER or EDITOR, or access through an application that grants equivalent schema-creation capabilities.

Ensure that exported identifiers are context-appropriately escaped or represented through a structured format that cannot be interpreted as executable SurrealQL.

Treat schema names and backup files as untrusted input, enforce naming and privilege policies, test second-order injection paths, and isolate or review backup imports before they reach privileged environments.

Find out what's already
exploitable in your codebase.