GHSA-h4h3-3rfj-x6fq
MEDIUMGHSA-h4h3-3rfj-x6fq is a medium-severity (CVSS 4.3) vulnerability in surrealdb. O3 Security confirms whether GHSA-h4h3-3rfj-x6fq is actually reachable in your code before you act, and blocks exploitation at runtime until you patch.
SurrealDB: Indexed ORDER BY leaks the value ordering of a SELECT-restricted field
Blast Radius
surrealdbReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects crates.io packages — download data is not available via public APIs for these ecosystems.
Description
A field can be hidden from a user with a field-level SELECT permission (DEFINE FIELD code ON secret PERMISSIONS FOR select WHERE owner = $auth.id). When that field is indexed, a record user who cannot read it could still recover the relative ordering of its values across every record by issuing ORDER BY <field>: the field came back null as intended, but the rows were returned in the hidden values' true sorted order.
To satisfy the sort, the planner selects the field's index and walks it in value order; the field-level permission is applied later, when the row is projected, so the value is nulled but the row order already encodes it. The guard that withholds restricted fields from the WHERE path was never applied to ORDER BY.
Impact
What an attacker can do:
- As a record (scope) user with table SELECT, learn the relative ordering of a field hidden by a field-level SELECT permission, across other users' records, by ordering on it when an index covers the field — the value returns
null, but the rows come back in the hidden values' order. - With rows they control in the same table, use that ordering to narrow the hidden values toward exact ones.
What it can't do:
- Read the field value directly — only its relative ordering leaks; the projected value is correctly redacted.
- Cross table, record, or namespace/database boundaries — the table's SELECT permission and any row-level
WHEREare still enforced, so only records the caller may already read are ordered. - Leak anything when the restricted field is not indexed, affect root or record-owner sessions, or modify data (confidentiality only).
Patches
The query planner now applies the field-permission guard to the ORDER BY clause as well as the WHERE clause. When an ordered field is hidden from the caller by a field-level SELECT permission, the index sort pushdown is withheld and the rows are sorted after redaction instead, so the row order no longer reflects the hidden values. The dynamic-scan fallback is closed the same way, and a regression test was added.
The fix is included in SurrealDB 3.1.5.
Workarounds
Users unable to upgrade are advised to consider the following:
- Force the legacy executor with
SURREAL_PLANNER_STRATEGY=compute-only; the sort then runs after redaction, so no ordering leaks. - Do not place an index on a field whose values are hidden by a field-level SELECT permission — without the index the leak does not occur.
- Do not rely on field-level SELECT permissions to hide values on indexed fields from record users; restrict at the table level instead.
- Use namespace / database isolation as the primary trust boundary where feasible.
References
- SurrealQL Documentation — DEFINE FIELD
- SurrealQL Documentation — DEFINE INDEX
- SurrealQL Documentation — DEFINE TABLE … PERMISSIONS
- Related advisory (same class, indexed COUNT variant): GHSA-c8jx-96c9-8xrp
fix(planner): prevent ORDER BY value-ordering oracle on restricted SELECT fieldsfix(planner): close ORDER BY value-ordering oracle on the DynamicScan fallback
Acknowledgements
Thanks to George Chen (@geo-chen) for finding and reporting this issue.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🦀crates.io | surrealdb | ≥ 3.0.0&&< 3.1.5 | 3.1.5 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for surrealdb. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.
Fix
Update surrealdb to 3.1.5 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-h4h3-3rfj-x6fq is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 pinpoints whether GHSA-h4h3-3rfj-x6fq is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.
Tailored to GHSA-h4h3-3rfj-x6fq. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-h4h3-3rfj-x6fq in your dependencies?
O3 detects GHSA-h4h3-3rfj-x6fq across crates.io dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.