The vulnerability, GHSA-wp87-mgvq-5j93, allowed unauthorized creation of namespaces and databases in SurrealDB. The core of the issue was that the USE NS <name> and USE DB <name> commands were designed to automatically create the specified resource if it didn't exist. However, the logic for this implicit creation failed to check if the session had the necessary DEFINE NAMESPACE or DEFINE DATABASE permissions.
This flaw was present in all three primary code paths that handle the USE command:
- The RPC handler (
surrealdb::core::rpc::protocol::RpcProtocol::handle), which processes requests from clients.
- The
Datastore::process_use method (surrealdb::core::kvs::ds::Datastore::process_use), used by internal components and embedded SDKs.
- The SurrealQL query executor (
surrealdb::core::dbs::executor::Executor::execute), which handles raw SQL statements.
In all three locations, the code would proceed to create the resources without any authorization check. This meant that an unauthenticated guest user could connect to a SurrealDB instance and create an arbitrary number of namespaces and databases, potentially leading to resource exhaustion or interfering with legitimate database administration.
The patch addresses this by introducing authorization checks at each of these three entry points. Before attempting to create a namespace or database, the code now verifies that the session has the equivalent of DEFINE permissions. This ensures that implicit creation via the USE command is governed by the same security policy as explicit DEFINE statements, effectively closing the authorization bypass.