Skip to content

GHSA-9722-9j67-vjcr CVE-2024-58367

SurrealDB: Improper Authorization in Select Permissions

Medium crates.io
Severity
0.0 / 10
Medium · CVSS 4.0
Exploit chance (EPSS)
0.36%
Chance of exploitation in the next 30 days. Higher than 29.54% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-285 Improper Authorization
Fix
Available
2 packages have a fixed version

Description

Due to the order in which permissions were processed, some statements, filters and computations could lead to leaking field values or record contents to users without the required permissions. This behavior could be triggered in different scenarios:

  • When performing a SELECT operation on a table, the values that would be returned were iterated over, field permissions would be validated and any unauthorized value would be removed from the result returned. However, performing a SELECT VALUE operation (e.g. SELECT VALUE private FROM data) would result in a non-iterable value, which would not be removed from the returned result.

  • When aliasing a field (e.g. SELECT private AS public FROM data) for which the user did not have SELECT permissions within a SELECT query, permissions would be checked against the field of the resulting document containing the aliased field instead of the original document containing the original field. As a consequence, the original field value would be returned as the returned field would not match the original field where permissions had been defined.

  • When calling a function in the context of a SELECT query and passing a field with permissions as an argument to the function (e.g. SELECT string::lowercase(private) FROM data), the function would receive the field value before it had been removed from the document due to SELECT permissions. As a result, the function would have access to the value of the field regardless of field permissions. This case includes functions called from within events and other clauses that support function calling.

  • When executing a query containing a WHERE clause filtering records by a field that the querying user does not have access to SELECT (e.g. SELECT public FROM data WHERE private ~ "secret"), the response of that query would still take the value of the field into account. Even though the value of the protected field would not be returned, this behavior could be used as a side channel by the querying user to infer information about the value of the field.

  • When performing UPDATE or DELETE operations over a table with a user that had those permissions but no SELECT permission, the RETURN BEFORE clause could be used (e.g. DELETE data RETURN BEFORE) to read the contents of the records prior to the authorized update or the deletion despite the querying user not being authorized to perform SELECT operations.

  • When performing UPDATE operations on a table for which the user had SELECT and UPDATE permissions, the SET clause could reference fields that the user had UPDATE but no SELECT permission for (e.g. UPDATE data SET public = private) in order to update the value of a field that the user had permission to SELECT to the value of another field for which the user did not.

Impact

Clients that were authorized by table permissions to execute SELECT statements for a table but were not authorized by field permissions to run SELECT queries for a specific field could still have been able to gain knowledge of the value of that field. Additionally, clients that were authorized to execute UPDATE or DELETE statements for a table but not authorized to execute SELECT statements for the same table may have been able to gain knowledge of the contents of records in that table. This could only be exploited by users who were already authorized to execute queries on the database with the affected table or field.

Due to its relationship with table and field permissions, which apply mainly to record users rather than system users, this issue mostly affects users relying on SurrealDB as a backend-as-a-service rather than SurrealDB as a traditional database backend.

Patches

The behavior when evaluating table or field permissions and filtering records or fields as a result of those evaluations has been improved to consider permissions before any changes to the document have been made and, when relevant, permissions after changes to the document have taken place. When a user is unauthorized to view record contents and field values by permissions, the returned documents will behave as if the record or field did not exist in order to prevent leaking any information.

  • Version 2.0.4 and later are not affected by this issue.

Workarounds

Users affected by this issue and unable to update should not rely on the authorization provided by field permissions when it comes to the SELECT permission. Instead, read access to fields in affected versions should be restricted at the table level. When allowing the UPDATE or DELETE operations for records via table permissions, users should not rely of the authorization provided by the SELECT permission. Instead, users should not allow clients to UPDATE or DELETE records that they should not be able to view.

Affected versions

crates.io

PackageVulnerableFixed in
surrealdb
< 2.0.4
2.0.4
surrealdb-core
< 2.0.4
2.0.4

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

surrealdb crates.io → 2.0.4

cargo
cargo update -p surrealdb --precise 2.0.4

surrealdb-core crates.io → 2.0.4

cargo
cargo update -p surrealdb-core --precise 2.0.4

Severity breakdown

CVSS 4.0 0.0

CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N

Attack vector
Network
Attack complexity
Low
Attack requirements
None
Privileges required
Low
User interaction
None
Confidentiality (vulnerable system)
High
Integrity (vulnerable system)
None
Availability (vulnerable system)
None
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None

CVSS 3.1 6.5

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
None
Availability
None

Weakness

CWE-285: Improper Authorization

The product does not perform or incorrectly performs an authorization check when an actor attempts to access a resource or perform an action.

How to prevent it
  • Architecture and Design: Divide the product into anonymous, normal, privileged, and administrative areas. Reduce the attack surface by carefully mapping roles with data and functionality. Use role-based access control (RBAC) to enforce the roles at the appropriate boundaries. Note that this approach may not protect against horizontal authorization, i.e., it will not protect a user from attacking others with the same role.
  • Architecture and Design: Ensure that you perform access control checks related to your business logic. These checks may be different than the access control checks that you apply to more generic resources such as files, connections, processes, memory, and database records. For example, a database may restrict access for medical records to a specific database user, but each record might only be intended to be accessible to the patient and the patient's doctor.
  • Architecture and Design: Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, consider using authorization frameworks such as the JAAS Authorization Framework [REF-233] and the OWASP ESAPI Access Control feature [REF-45].
  • Architecture and Design: For web applications, make sure that the access control mechanism is enforced correctly at the server side on every page. Users should not be able to access any unauthorized functionality or information by simply requesting direct access to that page. One way to do this is to ensure that all pages containing sensitive information are not cached, and that all such pages restrict access to requests that are accompanied by an active and authenticated session token associated with a user who has the required permissions to access that page.
  • System Configuration, Installation: Use the access control capabilities of your operating system and server environment and define your access control lists accordingly. Use a "default deny" policy when defining these ACLs.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-8rw6-p7m8-63jp
SurrealDB: Array element-level (field.*) SELECT permissions leak denied elements to record users
High Also affects surrealdb
GHSA-848m-r628-vrxw
SurrealDB: Custom API route lets authenticated callers override namespace/database scope via URL path
High Also affects surrealdb
GHSA-66r2-5gwj-gxm2
SurrealDB: Writes in a PERMISSIONS clause bypass table permissions
Medium Also affects surrealdb-core
GHSA-m3c3-78fh-w3w7
SurrealDB allows bypass of deny-net flags via DNS resolution
High Also affects SurrealDB
GHSA-whwg-vh4f-pmmf
SurrealDB: Edge PERMISSIONS FOR delete bypassed when a connected node is deleted
Medium Also affects surrealdb
GHSA-fwg2-gr34-q3w8
SurrealDB: ES512 silently downgraded to ES384 due to jsonwebtoken crate limitation
Medium Also affects surrealdb
GHSA-c8jx-96c9-8xrp
SurrealDB: Field-level SELECT permissions bypassed via indexed COUNT fast paths
Medium Also affects surrealdb
GHSA-wp87-mgvq-5j93
SurrealDB: USE NS/DB implicit creation bypasses DEFINE authorization
Medium Also affects surrealdb
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor