GHSA-PVV9-H693-M8R4
SurrealDB LIVE query notification expressions allow write side effects that bypass the write-blocking guard
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-PVV9-H693-M8R4 divulgada · CVSS 5.4 (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
SurrealDB's LIVE query notification pipeline evaluates subscriber-supplied WHERE clauses and field projections with write-blocking disabled, allowing embedded write subqueries (CREATE, UPDATE, DELETE, RELATE) to execute atomically within other users' triggering transactions. The `permission_predicate` guard introduced in GHSA-66r2-5gwj-gxm2 to block side effects in PERMISSIONS predicates was never extended to LIVE notification expression evaluation, violating a documented security invariant in SECURITY_GUIDE.md that requires these expressions to be side-effect free.
Root Cause
The write-blocking guard at `surrealdb/core/src/expr/expression.rs:432` rejects mutating statements only when `opt.permission_predicate` is `true`. In the LIVE notification pipeline, `Document::lq_compute` creates the evaluation options via `opt.new_with_perms(true)` (`surrealdb/core/src/doc/lives.rs:109`), which sets the `perms` field but leaves `permission_predicate` at its default `false` (`surrealdb/core/src/dbs/options.rs:66`). The PERMISSIONS predicate evaluation at `lq_allow` (`lives.rs:577`) correctly uses `opt.new_for_permission_predicate()` to enable the guard, but the WHERE clause evaluation (`lq_check` at `lives.rs:539`) and field projection evaluation (`Fields::compute` at `lives.rs:342`) both run with the unguarded options.
Affected functions:
- Document::lq_compute (surrealdb/core/src/doc/lives.rs): creates options with permission_predicate=false (line 109) and evaluates subscriber projections at line 342 without write-blocking
- Document::lq_check (surrealdb/core/src/doc/lives.rs): evaluates subscriber WHERE clause at line 539 with permission_predicate=false; no guard against write subqueriesImpact
An authenticated user with a database-level session, SELECT permission on the watched table (required for LIVE query registration since version 3.1.0), and write permission on a target table can register a LIVE query containing write subqueries in the projection or WHERE clause. When any other user subsequently writes to the watched table, the subscriber's write subqueries execute atomically within the triggering user's transaction.
The subscriber does not gain new write targets; standard table-level permissions (`perms: true`) still apply to the injected writes. The demonstrated capabilities that exceed normal access are:
- Transaction injection: The subscriber's writes execute atomically within another user's transaction, sharing commit and rollback semantics. This is not achievable through independent queries.
- Write amplification: N registered LIVE subscriptions with write expressions multiply write load by N for every triggering event. The triggering user has no visibility into or control over this amplification.
- Post-revocation side effects: Because the WHERE clause evaluates before the PERMISSIONS check (`lq_check` at line 253 runs before `lq_allow` at line 270), write side effects in the WHERE clause that reference document fields can exfiltrate data even after the subscriber's SELECT permission is revoked.
Proof of Concept
Dependencies: SurrealDB server with auth and realtime enabled (default configuration)
Setup: Two authenticated sessions with database-level access-- Session A (subscriber): register LIVE query with write subquery in projection
LIVE SELECT *, (CREATE audit CONTENT {source: name, ts: time::now()}) AS exfil FROM person-- Session B (any user): write to the watched table
CREATE person:1 SET name = 'Alice'-- Expected result on vulnerable version:
-- The LIVE notification pipeline evaluates the projection at lives.rs:342
-- with permission_predicate=false. The CREATE audit subquery passes through
-- expression.rs:432 without hitting the guard, executes under the subscriber's
-- permissions, and commits atomically with Session B's CREATE person:1.
--
-- SELECT * FROM audit returns:
-- [{id: audit:..., source: 'Alice', ts: '...'}]Attack Chain
- Exposure: An authenticated user with a database-level session connects via WebSocket, HTTP API, or SDK. LIVE query registration requires `ctx.realtime()` (enabled by default) and `opt.valid_for_db()`.
- Control: The subscriber controls the entire LIVE query definition, including the field projection and WHERE clause expressions. No validation rejects write subqueries at registration time; `has_direct_write()` is not called for LIVE queries.
- Path: The subscription definition (including the unvalidated Fields and condition) is stored verbatim via `txn.replace` at `lives.rs:170`. When any user writes to the watched table, `process_table_lives_inner` (`lives.rs:56`) iterates all subscriptions. For each subscription, `lq_compute` creates options with `new_with_perms(true)` at line 109, which does not set `permission_predicate`.
- Guard: The write-blocking guard at `expression.rs:432` checks `opt.permission_predicate && matches!(self, Expr::Create | Expr::Update | ...)`. Since `permission_predicate` is `false` in the LIVE notification context, the guard does not fire for any write statement. The `lq_allow` PERMISSIONS check at `lives.rs:577` correctly uses `new_for_permission_predicate()`, but it only covers the PERMISSIONS predicate, not the subscriber's expressions.
- Primitive: Write subqueries in the projection and WHERE clause execute with the subscriber's stored auth and `perms=true`, checked against standard table-level permissions. The writes share the triggering user's transaction context (`ctx.tx()` at `lives.rs:121`).
- Result: The subscriber achieves atomic transaction injection, write amplification proportional to the number of registered LIVE subscriptions with write expressions, and, in the case of post-revocation scenarios, data exfiltration through WHERE clause side effects.
Bypass Evidence
GHSA-66r2-5gwj-gxm2 introduced the `permission_predicate` mechanism to block write side effects in PERMISSIONS predicates. That fix correctly applies `new_for_permission_predicate()` at all 16 PERMISSIONS predicate evaluation sites. However, the LIVE notification expression evaluation sites were not included in the fix's scope because they are subscriber-supplied expressions rather than stored PERMISSIONS predicates.
The gap is structural: `new_with_perms(true)` at `lives.rs:109` sets `perms` (enabling table-level permission checks) but does not set `permission_predicate` (which would enable write-blocking). The function `new_for_permission_predicate()` sets `permission_predicate=true` and `perms=false`, which is the correct combination for PERMISSIONS predicates but not for LIVE notification expressions (which need `perms=true` AND write-blocking).
The project's `SECURITY_GUIDE.md` at line 387 documents: "Live query WHERE clauses must be side-effect free (no writes, deletes, event emissions, or external calls)." This invariant is not enforced at any layer: not at parse time (the parser accepts write statements in all expression contexts), not at registration time (`has_direct_write()` exists but is not called for LIVE queries), and not at notification-time compute (`permission_predicate` is not set).
Affected Versions
- Ecosystem: crates.io (Rust)
- Package: surrealdb
- Confirmed affected range: `<= 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 vulnerability exists since the original LIVE query implementation and predates the `permission_predicate` mechanism. In versions before the GHSA-66r2-5gwj-gxm2 fix (surrealdb-core < 3.2.0), no write-blocking guard exists at all, making writes possible in both PERMISSIONS predicates and LIVE notification expressions. After the fix, PERMISSIONS predicates are protected but LIVE notification expressions remain unguarded.
Suggested Fix
The security invariant from SECURITY_GUIDE.md must be enforced: LIVE query WHERE clauses and field projections must reject write operations. Two complementary approaches exist:
- Registration-time rejection: Call `has_direct_write()` (or an equivalent AST inspection) on the LIVE query's condition and field projection before storing the subscription. This prevents write subqueries from being registered.
- Notification-time blocking: Apply a write-blocking flag analogous to `permission_predicate` when evaluating LIVE notification expressions. A new flag or the existing `permission_predicate` (with `perms` remaining `true`) would cause the guard at `expression.rs:432` to reject mutating statements.
Both approaches should be applied. Registration-time rejection catches the common case; notification-time blocking provides defense-in-depth against subscription definitions created before the fix.
No interim mitigation is available beyond restricting untrusted users' ability to register LIVE queries by removing SELECT permission or gating LIVE registration at the application layer.
Reported by zx (GitHub: @manus-pi).
Patches
A patch has been created that evaluates a LIVE query's notification expressions (its projection and WHERE clause) under the write-blocking guard, so a subscription can no longer perform write side effects.
- Version 4.0.0 and later are not affected by this issue.
References
- SurrealQL Documentation — LIVE SELECT
https://surrealdb.com/docs/surrealql/statements/live - `fix(live): LIVE query notification expressions allow write side effects` (commit `92fde2b792`)
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-pvv9-h693-m8r4Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
