llamaCVEVulnerability Intelligence
/
Advisory · GitHub · crates.io · surrealdb

GHSA-3287-HPM5-3F8R

SurrealDB DDL statements bypass namespace/database implicit-creation authorization added by GHSA-wp87-mgvq-5j93 fix

Texto original en inglés · Ver en español

Parche disponible
Descargar PNG JSON
CVSS 3.1
4.2
Media
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:L Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche el mismo día de la divulgación
Exposición18 dDesde la divulgación, 3 nov 2026, 10:50 a. m.
Detección17 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de vector CVSS 3.1 y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, no automatizable e impacto técnico parcial. Hay versiones corregidas disponibles.
Ponle etiqueta y a la cola. Ordenadito.Hoy toca orden, no heroísmo.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche 4.0.0
Monitoreo
Detectada +1
3 nov 26
20 nov 26
21 nov 26
3 nov 26
8 nov 26
12 nov 26
17 nov 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-3287-HPM5-3F8R divulgada · CVSS 4.2 (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
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

Several DDL statements (DEFINE FUNCTION, DEFINE PARAM, DEFINE EVENT, DEFINE FIELD, DEFINE ANALYZER, DEFINE DATABASE, and others) can recreate a dropped namespace and database by reaching the same creation sinks that the GHSA-wp87-mgvq-5j93 fix gated for USE statements. A database-level Editor with an active WebSocket or embedded SDK session that was established before the namespace was dropped can execute a DDL statement and silently recreate the namespace without holding root-level DEFINE NAMESPACE permission.

Root Cause

The GHSA-wp87-mgvq-5j93 fix added authorization checks (`should_materialize_ns_on_use` / `should_materialize_db_on_use`) to the three USE entry points (the SurrealQL executor, the RPC `yuse` method, and `Datastore::process_use`). These checks verify that the caller holds `is_allowed(Action::Edit, ResourceKind::Namespace.on_root())` before creating a missing namespace. However, the same creation sinks are reachable through Context wrapper functions called by DDL statements, and those wrappers perform no equivalent authorization check.

Affected functions:
  Context::get_ns_db_ids  (surrealdb/core/src/ctx/context.rs:663)
    Calls ensure_ns_db without namespace-creation authorization.
    Called by: DEFINE FUNCTION (function.rs:55), DEFINE PARAM (param.rs:52),
              DEFINE EVENT (event.rs:47), DEFINE FIELD (field.rs:180),
              DEFINE ANALYZER (analyzer.rs:94), and other DB-level DDL.

  Context::get_ns_id  (surrealdb/core/src/ctx/context.rs:640)
    Calls get_or_add_ns without namespace-creation authorization.
    Called by: DEFINE USER ON NS (user.rs:172) and related NS-level DDL.

Creation sink:
  get_or_add_db_upwards (surrealdb/core/src/kvs/tx.rs:2468) with upwards=true
    calls get_or_add_ns (catalog/providers.rs:109) which creates a
    NamespaceDefinition in the KV store when the namespace does not exist.

Impact

A database-level or namespace-level Editor can recreate a namespace that a root administrator deliberately dropped, provided they hold an active in-memory session (WebSocket or embedded SDK) that was authenticated before the namespace removal. The attacker cannot create arbitrary new namespaces; they can only recreate the specific namespace associated with their session. The recreated namespace is empty (it receives a new internal namespace ID, so old data is not exposed).

This crosses the root authorization boundary: namespace creation requires `is_allowed(Action::Edit, ResourceKind::Namespace.on_root())` per the GHSA-wp87-mgvq-5j93 fix, but a database-level Editor does not hold that permission. In multi-tenant deployments where namespaces represent tenants, a deprovisioned tenant could recreate its namespace context.

Exploitation requires: (1) authentication is enabled (the default), (2) the attacker has an active session established before the namespace drop, (3) a root administrator drops the attacker's namespace. HTTP-per-request authentication would fail because the namespace's access method definitions were deleted with the namespace. There is no default session TTL for WebSocket connections.

Proof of Concept

Dependencies: A running SurrealDB >= 3.1.0 instance with authentication enabled (default).
Setup: A namespace "tenant_a" exists with a database "app" and a DB-level Editor user.
  1. The DB Editor authenticates via WebSocket and receives a session at Level::Database("tenant_a", "app").
  2. A root administrator drops the namespace: REMOVE NAMESPACE tenant_a.
  3. The DB Editor (session still active) sends: DEFINE FUNCTION fn::test() {RETURN 1}.
-- Step 1: As root, set up the namespace and Editor user
USE NS tenant_a DB app;
DEFINE USER editor ON DATABASE PASSWORD 'test' ROLES EDITOR;

-- Step 2 (separate session): Editor authenticates
SIGNIN { user: 'editor', pass: 'test', ns: 'tenant_a', db: 'app' };

-- Step 3: Root drops the namespace
REMOVE NAMESPACE tenant_a;

-- Step 4: Editor's session is still active; DDL recreates the namespace
DEFINE FUNCTION fn::test() { RETURN 1 };

-- Step 5: Root verifies the namespace was recreated
INFO FOR ROOT;
-- Output includes "tenant_a" in the namespaces list
Expected result: The DEFINE FUNCTION statement succeeds. The namespace "tenant_a"
and database "app" reappear in the KV store catalog. The root administrator's
REMOVE NAMESPACE operation has been undone by a lower-privileged user.

Attack Chain

  1. Exposure: The attacker is a DB-level Editor who authenticated via WebSocket while the namespace existed. DDL statements are available to any authenticated session via the SurrealQL executor.
  2. Control: The attacker controls which DDL statement to execute. The namespace and database names come from `session.ns` / `session.db`, set at authentication time and persisted in the session's Options.
  3. Path: DefineFunctionStatement::compute (function.rs:33) checks `is_allowed(Edit, Function, Db)` at line 41 (passes for DB Editor), then calls `ctx.get_ns_db_ids(opt)` at line 55, which calls `ensure_ns_db` (catalog/providers.rs:1004), which calls `get_or_add_db_upwards` with `upwards=true` (tx.rs:2468). With `upwards=true`, `get_or_add_ns` (tx.rs:2492) creates the namespace if it does not exist.
  4. Guard: The only guard before the creation sink is `is_allowed(Edit, Function, Db)` at function.rs:41, which checks permission to edit functions, not permission to create namespaces. The GHSA-wp87-mgvq-5j93 fix's `should_materialize_ns_on_use` is applied only to the three USE entry points; DDL statements bypass it entirely.
  5. Primitive: Namespace and database creation in the KV store via `get_or_add_ns` (catalog/providers.rs:109) and `put_db` (tx.rs:2514).
  6. Result: A DB-level Editor performs a root-only operation (namespace creation). The root administrator's `REMOVE NAMESPACE` is reversed. The authorization boundary between DB Editor and root namespace management is violated.

Bypass Evidence

The GHSA-wp87-mgvq-5j93 fix added authorization checks to three USE entry points:
- The SurrealQL executor (executor.rs:710-752) calls `should_materialize_ns_on_use` / `should_materialize_db_on_use`.
- The RPC `yuse` method (protocol.rs:486-541) calls the same helpers.
- `Datastore::process_use` (ds.rs:4204-4266) calls the same helpers.

These helpers verify `auth.is_allowed(Action::Edit, &ResourceKind::Namespace.on_root())` at ds.rs:4138 before permitting namespace creation. DDL statements reach the identical creation sinks (`get_or_add_ns`, `ensure_ns_db`) through `Context::get_ns_db_ids` (context.rs:663) and `Context::get_ns_id` (context.rs:640), neither of which invokes the `should_materialize_*` helpers or any equivalent authorization check. The `Option<&Context>` parameter passed to `ensure_ns_db` is used only for sequence ID allocation, not authorization.

Refutation attempts: (1) searched for hidden guards between `is_allowed(Edit, Function, Db)` and `get_or_add_ns`; none found; (2) verified that strict mode does not gate implicit creation in the `get_ns_db_ids` path (stale docstrings); (3) confirmed `REMOVE NAMESPACE` does not invalidate active sessions; (4) confirmed the recreated namespace gets a new internal ID, so no old data is exposed.

Affected Versions

  • Ecosystem: crates.io
  • Package: surrealdb
  • Confirmed affected range: >= 3.1.0, <= 3.3.0
  • Latest release checked: 3.3.0 (crates.io, published 2026-09-24)
  • Fix status: not fixed

The vulnerability was introduced in 3.1.0, the version that shipped the GHSA-wp87-mgvq-5j93 fix. Before 3.1.0, the broader GHSA-wp87-mgvq-5j93 vulnerability (USE path also lacked authorization for namespace creation) subsumes this finding. The incomplete fix created a distinct vulnerability class from 3.1.0 onward: DDL statements bypass the authorization gate that USE now enforces.

Suggested Fix

The Context wrapper functions `get_ns_db_ids`, `get_ns_id`, and `get_db` should enforce the same authorization invariant as the GHSA-wp87-mgvq-5j93 fix before calling `ensure_ns_db` or `get_or_add_ns`: verify that the caller holds `is_allowed(Action::Edit, ResourceKind::Namespace.on_root())` for namespace creation and `is_allowed(Action::Edit, ResourceKind::Database.on_ns(ns))` for database creation when the target does not already exist. The check should be centralized in `ensure_ns_db` or `get_or_add_db_upwards` rather than added to each DDL caller, to prevent future callers from inheriting the same gap.

Alternatively, the `expect_ns_db_ids` variant (which errors when the namespace or database does not exist, rather than creating them) could replace `get_ns_db_ids` in DDL handlers that should not implicitly create namespaces.

Interim mitigations: (1) set `--deny-arbitrary-query *` for guest principals; (2) require all callers to `signin` before issuing statements; (3) revoke namespace-level tokens promptly and terminate WebSocket sessions when a namespace is dropped.

Reported by zx (GitHub: @manus-pi).

Patches

A patch has been created that requires the appropriate DEFINE authority before a DDL statement may implicitly create a namespace or database, closing the unauthorized implicit-creation path.

  • Version 4.0.0 and later are not affected by this issue.
References
  • SurrealQL Documentation — DEFINE NAMESPACE / DATABASE https://surrealdb.com/docs/surrealql/statements/define/namespace
  • `fix(ddl): DDL statements implicitly recreate a namespace/database without authorization` (commit `4d7c220cda`)

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:H
BajaAlta
PrivilegiosPR:L
NingunoBajosAltos
InteracciónUI:N
NingunaRequerida
AlcanceS:U
CambiadoSin cambio
ConfidencialidadC:N
AltoBajoNinguno
IntegridadI:L
AltoBajoNinguno
DisponibilidadA:L
AltoBajoNinguno
Score de explotaciónQué tan fácil y probable es que la exploten
5.9/ 10Medio
Vector 5.9 (moderada) · sin evidencia de explotación.
Versiones

Rangos afectados

Afectada Corregida Última
surrealdb< 4.0.0
4.0.0
4.0.1
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
crates.iosurrealdb
Corregida 4.0.0 0 d 4.0.1 no afectada
Versiones corregidas4.0.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/surrealdb/surrealdb/security/advisories/GHSA-3287-hpm5-3f8r

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.