Skip to content
Access control Write-up Intermediate

Remote Code Execution in CouchDB (and Privilege Escalation in the Npm Registry)

A discrepancy between CouchDB's Erlang JSON parser and the JavaScript parser used in validation scripts allowed an attacker to create an admin user by sending duplicate keys. This gave full control of the database, potentially enabling remote code execution and modification of npm packages.

justi.cz

Published on justi.cz

tl;dr There was a vulnerability in CouchDB caused by a discrepancy between the database’s native JSON parser and the Javascript JSON parser used during document validation. Because CouchDB databases are meant to be exposed directly to the internet, this enabled privilege escalation, and ultimately remote code…

The author, on justi.cz

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 use of two different JSON parsers with inconsistent handling of duplicate keys, where the validation parser kept the last value but the internal parser kept the first.

What the attacker needed

CouchDB exposed to the internet; No authentication required for user creation

The fix

The vulnerability was fixed by the CouchDB team.

How it was found

  1. Send a PUT request to the _users database with a JSON document containing duplicate 'roles' keys.
  2. The validation script sees an empty roles array, but the internal parser stores the first value, which includes the _admin role.
  3. The attacker now has an admin account and can define a custom query_server language, leading to command execution.

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.

CouchDB is a database that stores JSON documents. It used two different programs to read the same JSON: one for internal storage and one for checking rules. Because they handled duplicate keys differently, an attacker could sneak in an extra admin role that the checker missed, gaining admin rights.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.