SurrealDB memory exhaustion via string::replace using regex
HighCVE-2025-71395 · Published Apr 11, 2025 · updated Jul 19, 2026
An authenticated user can craft a query using the `string::replace` function that uses a Regex to perform a string replacement. As there is a failure to restrict the resulting string length, this enables an attacker to send a `string::replace` function to the SurrealDB server exhausting all the memory of the server due to string allocations. This eventually results in a Denial-of-Service situation for the SurrealDB server. This issue was discovered and patched during an code audit and penetration test of SurrealDB by cure53. Using CVSSv4 definitions, the severity is High. ### Impact An authenticated user can crash the SurrealDB instance through memory exhaustion ### Patches A patch has been created that enforces a limit on string length `SURREAL_GENERATION_ALLOCATION_LIMIT` - Versions 2.0.5, 2.1.5, 2.2.2, and later are not affected by this issue ### Workarounds Affected users who are unable to update may want to limit the ability of untrusted clients to run the `string::replace` function in the affected versions of SurrealDB using the `--deny-functions` flag described within [Capabilities](https://surrealdb.com/docs/surrealdb/security/capabilities#functions) or the equivalent...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| surrealdb crates.io | >= 2.2.0, < 2.2.2 | 2.2.2 |
| >= 2.1.0, < 2.1.5 | 2.1.5 | |
| < 2.0.5 | 2.0.5 |
Details and references
An authenticated user can craft a query using the `string::replace` function that uses a Regex to perform a string replacement. As there is a failure to restrict the resulting string length, this enables an attacker to send a `string::replace` function to the SurrealDB server exhausting all the memory of the server due to string allocations. This eventually results in a Denial-of-Service situation for the SurrealDB server. This issue was discovered and patched during an code audit and penetration test of SurrealDB by cure53. Using CVSSv4 definitions, the severity is High. ### Impact An authenticated user can crash the SurrealDB instance through memory exhaustion ### Patches A patch has been created that enforces a limit on string length `SURREAL_GENERATION_ALLOCATION_LIMIT` - Versions 2.0.5, 2.1.5, 2.2.2, and later are not affected by this issue ### Workarounds Affected users who are unable to update may want to limit the ability of untrusted clients to run the `string::replace` function in the affected versions of SurrealDB using the `--deny-functions` flag described within [Capabilities](https://surrealdb.com/docs/surrealdb/security/capabilities#functions) or the equivalent `SURREAL_CAPS_DENY_FUNC` environment variable. ### References [SurrealQL Documentation - DB Functions (string::replace)](https://surrealdb.com/docs/surrealql/functions/database/string#stringreplace) [SurrealDB Documentation - Capabilities](https://surrealdb.com/docs/surrealdb/security/capabilities#functions) [SurrealDB Documentation - Environment Variables](https://surrealdb.com/docs/surrealdb/cli/env) [#5619 ](https://github.com/surrealdb/surrealdb/pull/5619) [#5638 ](https://github.com/surrealdb/surrealdb/pull/5638)
- CVSS 4.0
- CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-789
- Also known as
- CVE-2025-71395
More SurrealDB advisories
All SurrealDB| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Apr 112025 | SurrealDB bypass of deny-net flags via redirect results in server-side request forgery (SSRF) | Medium | 2.0.5+2 more |
| Apr 112025 | SurrealDB CPU exhaustion via custom functions result in total DoS | High | 2.0.5+2 more |
| Apr 112025 | SurrealDB no JavaScript script function default timeout could facilitate DoS | Low | 2.0.5+2 more |
| Apr 112025 | SurrealDB server-takeover via SurrealQL injection on backup import | Critical | 2.0.5+2 more |
| Apr 102025 | SurrealDB has local file read of 2-column TSV files via analyzers | Low | 2.1.5+1 more |
| Apr 102025 | SurrealDB vulnerable to memory exhaustion via nested functions and scripts | Medium | 2.0.5+2 more |