GHSA-FH2Q-8F75-M4H6
REFERENCE ON DELETE CASCADE/UNSET/CUSTOM bypasses target table PERMISSIONS FOR delete/update
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-FH2Q-8F75-M4H6 divulgada · CVSS 8.1 (GitHub) | |
| Remediación | Parche 4.0.0 | surrealdb · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
In SurrealDB, when a record is deleted that is referenced by fields defined with `DEFINE FIELD ... REFERENCE ON DELETE CASCADE`, `ON DELETE UNSET`, or `ON DELETE CUSTOM`, the cascade operation on the referencing table executes with permissions unconditionally suppressed. An authenticated user who can delete a record on the referenced table can trigger unauthorized deletion, modification, or expression execution on records in a referencing table, even when that table has `PERMISSIONS FOR delete NONE` or `PERMISSIONS FOR update NONE`.
Root Cause
The function `Document::purge_references` in `surrealdb/core/src/doc/purge.rs` unconditionally disables permission checks before executing cascade operations on referencing tables. This violates the security invariant documented in `SECURITY_GUIDE.md` (lines 141-143): "When system-internal code paths (events, views, cascades) set `perms=false`, this suppression must not extend to user-supplied expressions or user-controlled data lookups beyond the strictly required scope."
// CASCADE path (purge.rs:376):
stm.compute(stk, ctx, &opt.clone().with_perms(false), None)
// UNSET path (purge.rs:385):
let opt = opt.clone().with_perms(false);
// CUSTOM path (purge.rs:453):
let opt = opt.clone().with_perms(false);The `with_perms(false)` call sets the `perms` field on the `Options` struct to `false`. When the cascade DELETE or UPDATE later calls `check_perms` (at `surrealdb/core/src/ctx/context.rs:612-614`), the function returns `Ok(false)` immediately without evaluating the target table's `PERMISSIONS` clause:
pub fn check_perms(&self, opt: &Options, action: Action) -> Result<bool> {
if !opt.perms {
return Ok(false);
}
// ... remaining permission logic never reached
}The parallel function `purge_edges` (purge.rs:186-232) was fixed in v3.1.0 (CVE-2026-49997, GHSA-whwg-vh4f-pmmf) to preserve the caller's `opt` and thus respect edge table permissions. The comment at purge.rs:222-227 explicitly documents this security requirement. `purge_references` retains the pre-fix pattern at all three cascade sites.
Impact
An authenticated user with DELETE permission on a referenced table (e.g., `user`) can:
- CASCADE: Delete all records in a referencing table (e.g., `audit_log`) that point to the deleted record, bypassing `PERMISSIONS FOR delete NONE` on that table.
- UNSET: Modify records in a referencing table by clearing reference fields, bypassing `PERMISSIONS FOR update NONE`.
- CUSTOM: Execute admin-defined expressions against records in a referencing table with system-level privileges, bypassing all PERMISSIONS clauses.
This requires an administrator to have configured `DEFINE FIELD ... REFERENCE ON DELETE CASCADE|UNSET|CUSTOM` on the referencing table. This is a documented, production-intended feature for referential integrity. The administrator who defines both a REFERENCE cascade and restrictive PERMISSIONS expects both policies to be enforced.
The attacker cannot cross namespace or database isolation boundaries, and cannot delete records on tables where they lack DELETE permission on the referenced endpoint. The primitive is reliable and deterministic: a single DELETE statement triggers the cascade.
Proof of Concept
Requirements: SurrealDB >= 2.2.0 (REFERENCE ON DELETE feature), any supported backend.
Setup: root access to define schema, then switch to a record-scoped access user.- As root, define a schema with a referenced table and a referencing table that denies deletes:
DEFINE ACCESS user_access ON DATABASE TYPE RECORD
SIGNUP ( CREATE type::record('user', $id) )
SIGNIN ( SELECT * FROM type::record('user', $id) )
DURATION FOR TOKEN 1h, FOR SESSION 1h;
DEFINE TABLE user SCHEMALESS
PERMISSIONS FOR select, create, delete FULL;
DEFINE TABLE audit_log SCHEMALESS
PERMISSIONS
FOR select, create FULL,
FOR delete NONE;
DEFINE FIELD user ON audit_log TYPE record<user> REFERENCE ON DELETE CASCADE;
CREATE user:alice;
CREATE audit_log:log1 SET user = user:alice, action = "login", ts = "2026-01-01";
CREATE audit_log:log2 SET user = user:alice, action = "export", ts = "2026-01-02";- As the record-scoped user `user:alice`, confirm that direct deletion is blocked:
DELETE audit_log:log1;
-- Returns: [] (silently denied by PERMISSIONS FOR delete NONE)
SELECT * FROM audit_log:log1;
-- Returns: [{ action: 'login', id: audit_log:log1, ... }] (record survives)- Delete the user record to trigger the cascade:
DELETE user:alice;Expected: audit_log records survive (cascade blocked by PERMISSIONS FOR delete NONE)
Actual: audit_log:log1 and audit_log:log2 are deleted, bypassing the permission policyAttack Chain
- Exposure: The DELETE statement is accessible to any authenticated user via HTTP, WebSocket, RPC, or GraphQL interfaces. The `purge_references` cascade triggers automatically for any table with incoming `REFERENCE ON DELETE` fields.
- Control: The attacker controls which record to delete (e.g., `DELETE user:alice`). The cascade targets are determined by REFERENCE field definitions; the attacker selects the trigger record and thereby controls which referencing records are affected.
- Path: `Document::delete` (delete.rs:34) calls `purge_record_data` (purge.rs:40), which calls `purge_references` (purge.rs:70). The function scans reference keys (purge.rs:293-303), decodes each to identify the foreign table, field, and record (purge.rs:323-346), and dispatches to the ON DELETE strategy handler.
- Guard: No guard exists between the strategy dispatch and the `with_perms(false)` suppression. The `table_may_have_incoming_references` check (purge.rs:289) is a catalog optimization, not a security control.
- Primitive: The cascade DELETE/UPDATE enters the document pipeline with `opt.perms == false`. When `check_perms` (context.rs:613) is called, it returns `Ok(false)` unconditionally, causing `check_delete_permissions` (check.rs:413) to skip the target table's PERMISSIONS evaluation entirely.
- Result: Records in permission-restricted tables are deleted (CASCADE), modified (UNSET), or subjected to arbitrary expression execution (CUSTOM) as if the caller had root privileges. Audit trails, integrity guarantees, and data availability for the affected tables are compromised.
Bypass Evidence
The fixed `purge_edges` function (purge.rs:228) preserves the caller's `opt` parameter, ensuring edge table permissions are evaluated during graph edge cleanup. The comment at purge.rs:222-227 explains the security rationale: "an edge table's `PERMISSIONS FOR delete` clause must still apply even when the cascade is triggered by deleting one of the endpoint vertices."
The unfixed `purge_references` function applies the identical pre-fix pattern that CVE-2026-49997 corrected in `purge_edges`. The three `with_perms(false)` calls at purge.rs:376, 385, and 453 suppress all permission evaluation for the cascade, regardless of the target table's PERMISSIONS configuration. No intervening guard, AuthLimit, or auth-level restriction exists in the cascade path.
The strongest attempt to invalidate this finding was the argument that permission suppression is intentional for referential integrity (as documented in the `purge_references` docstring at purge.rs:251). This argument was rejected because the maintainers accepted the identical design as a vulnerability in CVE-2026-49997 for `purge_edges`, the project's `SECURITY_GUIDE.md` (lines 141-143) explicitly flags this pattern, and lines 847-857 classify reference cascade operations as a confused deputy risk.
Affected Versions
- Ecosystem: crates.io
- Package: `surrealdb`
- Confirmed affected range: `>= 2.2.0, <= 3.3.0`
- Latest release checked: 3.3.0 (published 2026-09-24 on crates.io)
- Fix status: not fixed in any published version
The REFERENCE ON DELETE feature was introduced in v2.2.0. Both the 2.x line (latest: 2.7.0) and 3.x line (latest: 3.3.0) are actively maintained and affected. The introduction boundary is based on official feature documentation; the upper bound is verified from the source of the 3.3.0-nightly build corresponding to the latest published release.
Suggested Fix
Propagate the caller's permission context into the cascade operation at all three sites in `Document::purge_references`, matching the fix already applied to `Document::purge_edges` at purge.rs:228. Replace each `opt.clone().with_perms(false)` with the caller's `opt` so that cascade DELETE and UPDATE operations are evaluated against the target table's `PERMISSIONS` clauses.
This means a cascade that the caller lacks permission to complete will fail. Consider whether the failure should abort the triggering DELETE (current behavior for REJECT strategy) or silently skip the blocked cascade operation, consistent with the existing behavior of direct DELETE against a table with `PERMISSIONS FOR delete NONE`.
As an interim mitigation, restrict DELETE permission on referenced tables to principals who are also trusted to delete or modify records in all referencing tables.
Reported by zx (GitHub: @manus-pi).
Patches
A patch has been created that runs a REFERENCE ON DELETE CASCADE/UNSET/CUSTOM (THEN) clause under the caller's permissions, so a record user's cascade can no longer perform writes the caller is not permitted to make.
- Version 4.0.0 and later are not affected by this issue.
References
- SurrealQL Documentation — DEFINE FIELD (REFERENCE)
https://surrealdb.com/docs/surrealql/statements/define/field - `fix(exec): run REFERENCE ON DELETE THEN under the caller's permissions` (commit `f980336355`)
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
crates.iosurrealdb |
Corregida | 4.0.0 | 0 d | 4.0.1 no afectada |
4.0.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/surrealdb/surrealdb/security/advisories/GHSA-fh2q-8f75-m4h6Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
