← Lab /Security & privacy

Azure Cosmos DB flaw lets attacker retrieve any account’s primary key

A crafted Gremlin query can obtain the primary key of any Azure Cosmos DB account.

Security & privacy Wiz Research 30 Jul 2026 Disclosure Real-world evidence

Published as “CosmosEscape: Taking Over Every Database in Azure Cosmos DB”

Why it matters

A single Gremlin query could compromise every Cosmos DB tenant, demonstrating the need for tighter sandbox isolation in multi-tenant cloud services.

Summary

Wiz researchers discovered that the Gremlin sandbox in Azure Cosmos DB allowed .NET reflection, leading to arbitrary code execution on the DB Gateway. By abusing a platform-wide signing key they called the Cosmos Master Key, they could retrieve the primary key of any Cosmos DB account and enumerate all accounts via the Config Store. Microsoft quickly issued a hot-fix and later a long-term architectural hardening, and found no evidence of exploitation beyond the researchers’ tests.

What they found 2

  1. A platform-wide signing key (Cosmos Master Key) can retrieve the primary key for any Cosmos DB account.

    “It worked across tenants, regions, and even API flavors - SQL, MongoDB, Cassandra, and Gremlin. It was a platform-wide key that could retrieve the primary key for any Cosmos DB account on the service, all through publicly accessible endpoints.”

  2. The Gremlin sandbox fails to block .NET reflection, enabling arbitrary code execution.

    “These restrictions, however, didn't sufficiently account for .NET reflection - allowing us to develop file read, write, and ultimately arbitrary code execution primitives, all through queries against our own database.”

Caveats 2

  • Microsoft conducted extensive reviews of access logs and found no evidence of unauthorized activity outside of the researcher’s testing activity, and no customer data was accessed.
  • CosmosEscape, a critical vulnerability in Azure’s flagship database service, Azure Cosmos DB, via its Gremlin API.

What’s new here 4

  • First remote code execution via the Gremlin sandbox in Azure Cosmos DB.
  • Discovery of a platform-wide Cosmos Master Key that can retrieve any account's primary key.
  • Ability to enumerate all Cosmos DB accounts through the Config Store.
  • Microsoft’s rapid hot-fix and subsequent long-term hardening of the service.