SurrealDB CPU exhaustion via custom functions result in total DoS
Key facts
- Attack vector
- —
- Privileges required
- —
- User interaction
- —
- Attack complexity
- —
- Impact type
- Denial of service
- Confidentiality · integrity · availability
- —
- Fix status
- Fixed
No CVSS vector from any source. Fix status from GitHub. Impact type from CWE-835.
Summary
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](https://surrealdb.com/docs/surrealdb/security/capabilities#functions), to either block all custom functions, or only allow trusted functions to execute. ### References [SurrealQL Documentation - DEFINE FUNCTION Statement](https://surrealdb.com/docs/surrealql/statements/define/function) [SurrealQL Documentation - FOR Statement](https://surrealdb.com/docs/surrealql/statements/for) [SurrealDB Documentation - Capabilities](https://surrealdb.com/docs/surrealdb/security/capabilities#functions) [SurrealDB Documentation - Environment variables](https://surrealdb.com/docs/surrealdb/cli/env#command-environment-variables) [#5597](https://github.com/surrealdb/surrealdb/pull/5597)
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | surrealdb (crates.io) | 2.2.0 to before 2.2.2 | 2.2.2 | Patch available | GHSA-pxw4-94j3-v9pf |
| — | surrealdb (crates.io) | 2.1.0 to before 2.1.5 | 2.1.5 | Patch available | GHSA-pxw4-94j3-v9pf |
| — | surrealdb (crates.io) | before 2.0.5 | 2.0.5 | Patch available | GHSA-pxw4-94j3-v9pf |
- surrealdb (crates.io) Vendor— Affected 2.2.0 to before 2.2.2 Fixed in 2.2.2 Patch available GHSA-pxw4-94j3-v9pf
- surrealdb (crates.io) Vendor— Affected 2.1.0 to before 2.1.5 Fixed in 2.1.5 Patch available GHSA-pxw4-94j3-v9pf
- surrealdb (crates.io) Vendor— Affected before 2.0.5 Fixed in 2.0.5 Patch available GHSA-pxw4-94j3-v9pf
Remediation
- Fix · GHSA-pxw4-94j3-v9pf surrealdb (crates.io) Fixed in 2.2.2 Advisory →
- Fix · GHSA-pxw4-94j3-v9pf surrealdb (crates.io) Fixed in 2.1.5 Advisory →
- Fix · GHSA-pxw4-94j3-v9pf surrealdb (crates.io) Fixed in 2.0.5 Advisory →
Timeline
- 2026-10-03 Threatist record created from GHSA-pxw4-94j3-v9pf
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences