Skip to content

GHSA-m7rc-8w7m-r9qr CVE-2025-71393

SurrealDB vulnerable to memory exhaustion via nested functions and scripts

Medium crates.io
Severity
0.0 / 10
Medium · CVSS 4.0
Exploit chance (EPSS)
0.46%
Chance of exploitation in the next 30 days. Higher than 40.00% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-674 Uncontrolled Recursion
Fix
2.2.2
Upgrade surrealdb to this version or later

Description

In order to prevent DoS situations due to infinite recursions, SurrealDB implements a limit of nested calls for both native functions and embedded JavaScript functions.

However, in SurrealDB instances with embedded scripting functions enabled, it was found that this limit can be circumvented by utilizing both at the same time. If a native function contains JavaScript which issues a new query that calls that function, the recursion limit is not triggered.

Once executed, SurrealDB will follow the path of infinite recursions until the system runs out of memory, prior to the recursion limit being triggered.

This vulnerability can only affect SurrealDB servers explicitly enabling the scripting capability with --allow-scripting or --allow-all and equivalent environment variables SURREAL_CAPS_ALLOW_SCRIPT=true and SURREAL_CAPS_ALLOW_ALL=true.

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 Medium, matched by our CVSS v4 assessment.

Impact

For SurrealDB instances with embedded scripting functions enabled, this attack could be used to perform a DoS attack on the server by an authenticated user.

Patches

A patch has been created that further limits scripting function call limit recursion depth and disallows multiple calls to surreadb.query() to run in parallel in a scripting function.

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

Workarounds

Deny execution of embedded scripting functions through the configuration of capabilities by starting SurrealDB with the --deny-scripting flag or the equivalent environment variable SURREAL_CAPS_DENY_SCRIPT=true. This has a usability implication, although scripting functions are disabled by default.

References

SurrealDB Documentation - Capabilities SurrealQL Documentation - Scripting Functions

Affected versions

crates.io

PackageVulnerableFixed in
surrealdb
>= 2.2.0, < 2.2.2
2.2.2
surrealdb
>= 2.1.0, < 2.1.5
2.1.5
surrealdb
< 2.0.5
2.0.5

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

surrealdb crates.io → 2.2.2

cargo
cargo update -p surrealdb --precise 2.2.2

Severity breakdown

CVSS 4.0 0.0

CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N

Attack vector
Network
Attack complexity
Low
Attack requirements
Present
Privileges required
Low
User interaction
None
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
High
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None

CVSS 3.1 6.5

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

Weakness

CWE-674: Uncontrolled Recursion

The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.

How to prevent it
  • Implementation: Ensure that an end condition will be reached under all logic conditions. The end condition may include checking against the depth of recursion and exiting with an error if the recursion goes too deep. The complexity of the end condition contributes to the effectiveness of this action.
  • Implementation: Increase the stack size.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-8rw6-p7m8-63jp
SurrealDB: Array element-level (field.*) SELECT permissions leak denied elements to record users
High Also affects surrealdb
GHSA-848m-r628-vrxw
SurrealDB: Custom API route lets authenticated callers override namespace/database scope via URL path
High Also affects surrealdb
GHSA-m3c3-78fh-w3w7
SurrealDB allows bypass of deny-net flags via DNS resolution
High Also affects SurrealDB
GHSA-whwg-vh4f-pmmf
SurrealDB: Edge PERMISSIONS FOR delete bypassed when a connected node is deleted
Medium Also affects surrealdb
GHSA-fwg2-gr34-q3w8
SurrealDB: ES512 silently downgraded to ES384 due to jsonwebtoken crate limitation
Medium Also affects surrealdb
GHSA-c8jx-96c9-8xrp
SurrealDB: Field-level SELECT permissions bypassed via indexed COUNT fast paths
Medium Also affects surrealdb
GHSA-wp87-mgvq-5j93
SurrealDB: USE NS/DB implicit creation bypasses DEFINE authorization
Medium Also affects surrealdb
GHSA-97vg-427p-8hx5
SurrealDB: Port-specific --deny-net rules silently bypassed on HTTP redirect
Medium Also affects surrealdb
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor