Summary
SurrealDB's reference-delete cascades may bypass permissions on records that reference a deleted record. An authenticated user who can trigger the cascade could cause referencing records to be deleted, unset, or processed by custom expressions despite restrictive delete or update permissions.
Affected context
The issue affects SurrealDB versions from 2.2.0 before 4.0.0 when a schema uses REFERENCE ON DELETE cascades. It becomes risky when an authenticated user can delete a referenced record and the cascade acts on referencing records without enforcing their target-table permissions.
Exploit preconditions
- Attack surface: Database operations involving
REFERENCE ON DELETEcascades - Required access: An authenticated user with sufficient permission to delete a referenced record
- Trigger point: Deletion of that record initiates actions on records that reference it
- Why exploitation is possible: Cascade processing may not enforce the target records' delete or update permissions
Why this happens
The underlying issue is an authorization check that is missing or not correctly applied during reference-cascade processing. This maps to CWE-863: Incorrect Authorization: an operation affecting a record proceeds without correctly enforcing the permissions that govern that record. The same concern applies when cascade behavior invokes custom expressions.
Potential impact
- Referencing records could be deleted despite restrictive delete permissions.
- Fields on referencing records could be unset despite restrictive update permissions.
- Custom expressions could run on records without the expected authorization checks.
- Data integrity or application-level access-control assumptions could be undermined.
General mitigation guidance
Defensive patterns include ensuring that every cascade action enforces the permissions applicable to the affected record, rather than relying only on authorization of the initiating deletion. Review cascade and custom-expression behavior against a deny-by-default policy, limit who can define or change reference actions, and keep database roles narrowly scoped. Where appropriate, prefer explicit, controlled handling of related records over implicit actions that cross permission boundaries.
How teams detect issues like this
Review database authorization and cascade code for paths that modify records without checking permissions on those records. Add tests covering reference deletions when target-table update and delete permissions deny access, including cases involving custom expressions. Static analysis and policy checks can flag cascade handlers that bypass shared authorization routines or allow privileged expressions to run without an explicit permission boundary.

