# CVE-2025-71397: SurrealDB denial of service via nested FOR loops in custom functions

Source: https://junglewise.ai/threats/cve-2025-71397-surrealdb-denial-of-service-via-nested-for-loops-in-custom  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-07-18. Updated: 2026-07-18  
License: CC BY 4.0 with a link back

CVE-2025-71397 · Severity: medium · CVSS 4 · Published 2026-07-18

SurrealDB, a multi-model cloud database, is vulnerable to a denial-of-service attack that can completely freeze the server. An authorized user with permission to create functions can use nested loops to exhaust the server's CPU resources. This causes the database to stop responding to all other users and queries, requiring a manual restart to restore service.

Technologies: [surrealdb (crates.io)](https://junglewise.ai/threats/technologies/surrealdb). Vendors: [crates.io](https://junglewise.ai/threats/vendors/crates-io).

## Quick answers

**Is CVE-2025-71397 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2025-71397 being exploited in the wild.

**How severe is CVE-2025-71397?** Medium severity, with a CVSS score of 4, published 18 July 2026.

**Which products and versions are affected?** surrealdb (crates.io) SEMVER:introduced=2.2.0,fixed=2.2.2.

**Is there a fix for CVE-2025-71397?** Yes. surrealdb (crates.io): upgrade to 2.2.2 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2025-71397 attacked?** It is attacked over the network, in a hosted service.

**Am I affected by CVE-2025-71397?** Check whether you run surrealdb (crates.io) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- surrealdb (crates.io): upgrade to 2.2.2 or later

  ```sh
  cargo update -p surrealdb
  ```


## Technical details

A vulnerability in the SurrealQL parser and interpreter allows for CPU exhaustion via the DEFINE FUNCTION statement. While individual FOR loops have iteration constraints, the engine fails to limit the cumulative iterations of nested loops. An attacker with OWNER or EDITOR privileges can define and execute a function with multiple nested loops (e.g., several levels of 1,000,000 iterations), which bypasses configured execution timeouts. This results in 100% CPU utilization, preventing the server from processing other queries or accepting new connections. The issue is resolved in versions 2.0.5, 2.1.5, and 2.2.2 by adding context cancellation and timeout checks within each loop iteration.

## Affected products

- SurrealDB SurrealDB < 2.0.5, 2.1.x < 2.1.5, 2.2.x < 2.2.2

## Identifiers

- CVE-2025-71397
- GHSA-pxw4-94j3-v9pf

## Timeline

- 2025-04-10: advisory: Vendor advisory published via GitHub
- 2026-07-18: disclosed: NVD publication date

## References

- [https://github.com/surrealdb/surrealdb/security/advisories/GHSA-pxw4-94j3-v9pf](https://github.com/surrealdb/surrealdb/security/advisories/GHSA-pxw4-94j3-v9pf)
- [https://www.vulncheck.com/advisories/surrealdb-before-cpu-exhaustion-via-nested-for-loops](https://www.vulncheck.com/advisories/surrealdb-before-cpu-exhaustion-via-nested-for-loops)

## Related threats

- [SurrealDB use-after-free in KV backends via affinitypool spawn_local](https://junglewise.ai/threats/cve-2026-121417-surrealdb-before-3-3-0-contains-a-use-after-free-vulnerability)
- [SurrealDB JSON parser denial of service via uncontrolled recursion](https://junglewise.ai/threats/surrealdb-json-parser-denial-of-service-via-uncontrolled-recursion-3037f8a0)
- [SurrealDB ES512 algorithm silently downgraded to ES384](https://junglewise.ai/threats/surrealdb-es512-algorithm-silently-downgraded-to-es384-f0af29b8)
- [SurrealDB permission bypass via WHERE clause evaluation](https://junglewise.ai/threats/surrealdb-permission-bypass-via-where-clause-evaluation-afa6f001)
- [SurrealDB authorization bypass in KILL statement](https://junglewise.ai/threats/surrealdb-authorization-bypass-in-kill-statement-fc230d0f)
