The vulnerability lies in the incorrect application of permissions within SurrealDB's live query mechanism. When a user subscribes to a live query, they should only receive updates for data they are authorized to see. However, the flaw caused the system to evaluate permissions based on the user who triggered the data change (e.g., via an UPDATE or DELETE statement), not the user who was subscribed to the live query.
The root cause is traced to the surrealdb_core::doc::document::Document::lives function. This function is the central hub for handling live query notifications. The original implementation failed to switch the permission context to that of the live query subscriber. It processed the data change with the permissions of the user who initiated the change. Consequently, if a high-privileged user modified a record, a low-privileged user subscribed to a matching live query could receive a notification containing sensitive data they were not supposed to see.
The patch addresses this by making several key changes:
- In the
lives function, it now explicitly creates a new options object (lqopt) that contains the authentication details of the live query subscriber.
- It then uses this
lqopt to perform a new compute_reduced_target operation, which correctly strips out any fields from the record that the subscriber is not permitted to view.
- The logic for handling live query data selection was moved out of the generic
pluck function and into a new, dedicated lq_pluck function to ensure the correct context is always used.
The vulnerable functions Document::lives and Document::pluck would appear in a runtime profile during exploitation. An attacker would first establish a live query on a table. Then, when a privileged user modifies a record in that table, the lives function would be invoked on the server. This would in turn call pluck (in the vulnerable version), which would incorrectly apply permissions and send the sensitive data to the attacker.