CVE-2025-71397
JSON

7.1high

SurrealDB before 2.2.2 CPU Exhaustion via nested FOR loops

Severity
7.1high CVSS:4.0 by VulnCheck
Exploit likelihood
0.41% (higher than 37% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
VulnCheck
Also known as
GHSA-pxw4-94j3-v9pf

Description

SurrealDB before 2.0.5, 2.1.x before 2.1.5, and 2.2.x before 2.2.2 allows authenticated users with OWNER or EDITOR permissions (at the root, namespace, or database level) to define custom database functions via DEFINE FUNCTION using nested FOR loops. Although a single loop's iteration count is constrained, nesting multiple loops (e.g., each with 1,000,000 iterations) is not, so an attacker can execute a function that consumes all server CPU time. Configured timeouts do not stop the execution, rendering the server unresponsive to other queries and connections until it is manually restarted.

Affected

Product or packageVersionsReported by
surrealdb surrealdbfrom 2.2.0 before 2.2.2, from 2.1.0 before 2.1.5, before 2.0.5
Not affected: 2.2.2, 2.1.5, 2.0.5
CVE List, NVD
surrealdb (crates.io)from 2.2.0 before 2.2.2, from 2.1.0 before 2.1.5, before 2.0.5GitHub Advisory Database

All scores

VulnCheck7.1high CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
GitHubhigh CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
NVD6.5medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

Classification

CWE-835

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

SurrealDB before 2.0.5, 2.1.x before 2.1.5, and 2.2.x before 2.2.2 allows authenticated users with OWNER or EDITOR permissions (at the root, namespace, or database level) to define custom database functions via DEFINE FUNCTION using nested FOR loops. Although a single loop's iteration count is constrained, nesting multiple loops (e.g., each with 1,000,000 iterations) is not, so an attacker can execute a function that consumes all server CPU time. Configured timeouts do not stop the execution, rendering the server unresponsive to other queries and connections until it is manually restarted.

GitHub Advisory Database

SurrealDB allows authenticated users with OWNER or EDITOR permissions at the root, database or namespace levels to define their own database functions using the DEFINE FUNCTION statement

A custom database function comprises a name together with a function body. In the function body, the user programs the functionality of the function in terms of SurrealQL. The language includes a FOR keyword, used to implement for-loops.

Whilst the parser and interpreter constrain the number of iterations for a single for-loop, nesting several for-loops with a large number of iterations is possible. Thus, an attacker could define a function that comprises several nested for-loops with an iteration count of 1.000.000 each.

Executing the function will consume all the CPU time of the server, timeouts configured will not break the CPU consumption, and the function execution monopolizes all CPU time of the SurrealDB server, effectively preventing the server from executing functions, queries, commands of other users, or allowing further connections being established to the server.

Terminating the stuck server requires manual intervention which forces a quit on the server process, as the server application is not responsive any longer.

This issue was discovered and patched during an code audit and penetration test of SurrealDB by cure53, the severity defined within cure53's preliminary finding is high, matched by our CVSS v4 assessment.

Impact

Denial of Service vulnerability resulting in a stuck SurrealDB server requiring manual restart.

Patches

A patch has been introduced that adds a check in the ForEachStatement that checks if the context has been cancelled or timed out for every iteration.

  • Versions 2.0.5, 2.1.5, 2.2.2, and later are not affected by this issue.
Workarounds

For SurrealDB users that are unable to upgrade, consider setting the --allow-functions and/or --deny-functions options or corresponding SURREAL_CAPS_ALLOW_FUNC and/or SURREAL_CAPS_DENY_FUNC environment variables, documented within capabilities, to either block all custom functions, or only allow trusted functions to execute.

References

SurrealQL Documentation - DEFINE FUNCTION Statement SurrealQL Documentation - FOR Statement SurrealDB Documentation - Capabilities SurrealDB Documentation - Environment variables #5597

NVD (es)

SurrealDB antes de 2.0.5, 2.1.x antes de 2.1.5, y 2.2.x antes de 2.2.2 permite a usuarios autenticados con permisos de PROPIETARIO o EDITOR (a nivel de raíz, espacio de nombres o base de datos) definir funciones personalizadas de base de datos a través de DEFINE FUNCTION usando bucles FOR anidados. Aunque el recuento de iteraciones de un solo bucle está restringido, el anidamiento de múltiples bucles (por ejemplo, cada uno con 1.000.000 de iteraciones) no lo está, por lo que un atacante puede ejecutar una función que consume todo el tiempo de CPU del servidor. Los tiempos de espera configurados no detienen la ejecución, dejando al servidor sin respuesta a otras consultas y conexiones hasta que se reinicia manualmente.

References

Sources

SourceRecordLicence
CVE ListCVE-2025-71397 changed 2026-10-29CVE Terms of Use
GitHub Advisory DatabaseGHSA-pxw4-94j3-v9pf changed 2026-07-19CC-BY-4.0
NVDCVE-2025-71397 changed 2026-10-29Public domain