Skip to content
RCE Write-up Advanced

CosmosEscape: Taking Over Every Database in Azure Cosmos DB

A sandbox escape in Cosmos DB's custom Gremlin engine allowed code execution on the multi-tenant DB Gateway, which held a platform-wide signing key that could retrieve the primary key of any Cosmos DB account. An attacker could enumerate all databases and gain full read/write access to any account, including Microsoft's internal ones.

Yuval Avrahami Follow

Published on wiz.io

Wiz Research uncovered CosmosEscape, a critical vulnerability in Azure’s flagship database service, Azure Cosmos DB, via its Gremlin API. The vulnerability could have been exploited to compromise every database in the service, including Microsoft's own internal databases - potentially enabling a cross-service attack.

Yuval Avrahami, on wiz.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Gremlin sandbox did not sufficiently restrict .NET reflection, allowing queries to escape into arbitrary code execution on the DB Gateway, which held an unscoped platform-wide signing key.

Impact

An attacker could have enumerated all Cosmos DB accounts and gained full read/write access to any database, including Microsoft's internal and network-isolated ones; Microsoft found no evidence of exploitation.

What the attacker needed

A Cosmos DB account with Gremlin API access; ability to send Gremlin queries

The fix

Microsoft deployed a hot fix within 48 hours, later completed a hardened architecture migration, eliminated the Cosmos Master Key, and added new guardrails.

How it was found

  1. Run a Gremlin query against your own Cosmos DB account and observe a .NET exception revealing a custom engine.
  2. Craft a Gremlin query that bypasses the sandbox restrictions using .NET reflection to achieve code execution on the DB Gateway.
  3. Use credentials on the cluster to access the signing key that retrieves account primary keys.
  4. Use the signing key to retrieve the primary key of any target Cosmos DB account.
  5. Query the Config Store to enumerate accounts or filter by tenant or subscription ID.
  6. Use the retrieved primary key to read and write the target's databases.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Cosmos DB is a cloud database service. Its Gremlin query feature ran customer queries in a restricted environment, but the restrictions could be bypassed to run arbitrary code on a shared backend service. That service held a powerful secret that could unlock any customer's database, so one flaw could have exposed every database in the service.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Yuval Avrahami

View all

8 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.