---
id: CVE-2025-71397
title: >-
  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 nest…
summary: >-
  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 nest…
severity: medium
cvss: 6.5
cvssVector: 'CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H'
cwe:
  - CWE-835
vendor: surrealdb
product: surrealdb
affected:
  - surrealdb < 2.0.5
  - 'surrealdb >= 2.1.0, < 2.1.5'
  - 'surrealdb >= 2.2.0, < 2.2.2'
patched:
  - surrealdb 2.2.2
published: '2026-07-18'
updated: '2026-09-29'
sourceUpdated: '2026-09-29T19:10:00.160'
source: NVD
sourceUrl: 'https://nvd.nist.gov/vuln/detail/CVE-2025-71397'
references:
  - url: >-
      https://github.com/surrealdb/surrealdb/security/advisories/GHSA-pxw4-94j3-v9pf
    label: disclosure@vulncheck.com
  - url: >-
      https://www.vulncheck.com/advisories/surrealdb-before-cpu-exhaustion-via-nested-for-loops
    label: disclosure@vulncheck.com
tags:
  - nvd
  - cve.org
epss: 0.00551
epssPercentile: 0.45859
ingestedAt: '2026-07-19T05:29:21.300Z'
ssvc:
  exploitation: none
  automatable: 'no'
  technicalImpact: partial
  timestamp: '2026-07-20T15:12:40.333706Z'
scores:
  nvd: 6.5
  cna: 7.1
---

## Overview

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

- `surrealdb < 2.0.5`
- `surrealdb >= 2.1.0, < 2.1.5`
- `surrealdb >= 2.2.0, < 2.2.2`

## Remediation

Upgrade past the affected range:

- `surrealdb 2.2.2`
