Skip to main content
Menu
Advisories

Unauthenticated read of any document over the MongoDB wire port: OP_QUERY on a normal collection never reaches the authorization gate

GHSA-PCQW-HM7V-9M96Published Updated GitHub

Description

The MongoDB wire protocol listener (mongodbw) authenticates and authorizes only the command path. A raw OP_QUERY frame addressed to a normal collection never reaches that path, so it is served with no authentication at all and returns documents from any database on the server.

Affected component

mongodbw (the optional MongoDB protocol plugin), at HEAD f5b6f7d0fb. The plugin is opt-in via SERVER_PLUGINS=MongoDB:com.arcadedb.mongo.MongoDBProtocolPlugin, so only deployments that enabled it and exposed the Mongo port are affected.

Impact

Unauthenticated read of any document in any collection of any database on the server, by anyone who can reach the Mongo port. No credentials of any kind are required. Writes are not reachable this way (OP_INSERT/OP_UPDATE/OP_DELETE are not decoded by the bundled wire handler), and OP_MSG and OP_QUERY on <db>.$cmd are correctly gated.

Because no principal is bound, the request also escapes the per-type ACL layer, the query admission gate, the RunningQuery registry and the HA "database directory is being replaced" refusal, so it is invisible to list queries and attributed to the engine rather than to a client.

Root cause

MongoDBBackend extends AbstractMongoBackend and overrides exactly three methods: openOrCreateDatabase, handleCommand and handleClose. Every protection the module has lives inside handleCommand: the SASL principal lookup, revalidate, canAccessToDatabase, the QueryAdmissionGate ticket, the RunningQuery registration, and the DatabaseContext user binding that makes the engine's per-type ACLs enforce.

The bundled de.bwaldvogel:mongo-java-server-core:1.47.0 has a second entry point. MongoDatabaseHandler routes a decoded MongoQuery to MongoBackend.handleCommand only when the collection name starts with $cmd; for any other collection it calls MongoBackend.handleQuery(MongoQuery). AbstractMongoBackend implements that as resolveDatabase(message).handleQuery(message). MongoDBBackend does not override it, so the call lands on MongoDBDatabaseWrapper.handleQuery, which resolves the collection and reads records.

The engine then applies its documented default. SecurityHelper states the invariant and the condition under which it is safe:

No bound user means allow [...] a missing context or current user is embedded usage or an internal caller, never an anonymous request, the server binds the user before a query is planned. Stated here because the default is only safe while that holds: a caller reusing this from somewhere a request CAN arrive without a user would be reading "allow everything" as "allow this one".

The OP_QUERY path is precisely "somewhere a request CAN arrive without a user".

Where

  • mongodbw/src/main/java/com/arcadedb/mongo/MongoDBBackend.java:77, handleCommand, the only gating override.
  • mongodbw/src/main/java/com/arcadedb/mongo/MongoDBDatabaseWrapper.java:219, handleQuery(MongoQuery): no authentication, no admission, no user binding, no ProtocolContext.set.
  • engine/src/main/java/com/arcadedb/security/SecurityHelper.java:70-84, the "no bound user means allow" contract.

Reproduction

A standalone server with only the Mongo plugin enabled, a database secretdb holding one Secret document with name="topsecret-value-42", and a plain socket that sends a single OP_QUERY frame and never authenticates:

header:  messageLength | requestID=7 | responseTo=0 | opCode=2004
body:    flags=0 | "secretdb.Secret\0" | numberToSkip=0 | numberToReturn=10 | {} (empty BSON)

The reply carries the document. Observed: contains the secret value true, contains Unauthorized false. The same find sent as OP_MSG is correctly refused with Unauthorized.

Coverage table

pathreaches handleCommandauthenticatedadmission gateRunningQueryProtocolContext
OP_MSG (every modern driver)yesyesyesyesmongo
OP_QUERY on <db>.$cmdyesyesyesyesmongo
OP_QUERY on <db>.<collection>nonononoINTERNAL

Suggested fix

Override handleQuery(MongoQuery) in MongoDBBackend and route it through the same gate handleCommand uses, or better, hoist the gate so it runs for every entry point of the backend rather than being attached to one method.

The guarantee that would stop the class recurring: a test that enumerates the public entry points of MongoBackend (reflection over the interface) and fails for any one MongoDBBackend does not override or explicitly exempt, in the same shape as the existing ProtocolContextCensusTest. The defect is that the protection was attached to one method of an interface that has several doors, and only an enumeration of the doors can hold that.

Credit

Reported by @ruispereira.

---

Update 2026-10-21: still present at main b4a6cb68a5

Re-checked this against main after the 2026-10-20 work, because MongoDBBackend now overrides six methods rather than three and that looked like a fix. It is not one.

The three new overrides come from commit 0f9ceadcc2 (issue #10390, PR #10400), which is about tagging the request thread with a protocol, not about authorization. It is the only commit touching mongodbw/ in that range.

MongoDBBackend.handleQuery(MongoQuery) at main is tag-only:

/** An OP_QUERY on a collection: the library hands it to the database's handleQuery, past every command. */
@Override
public QueryResult handleQuery(final MongoQuery query) {
  final String enclosing = tagAsMongo();
  try {
    return super.handleQuery(query);
  } finally {
    restoreProtocol(enclosing);
  }
}

No SASL principal lookup, no revalidate, no canAccessToDatabase, no admission ticket, no RunningQuery, no DatabaseContext user binding. Not a thinner copy of the gate: no copy at all. The javadoc the author wrote on that method states the problem ("past every command") and the method answers it with a label rather than a check.

One consequence we did not report the first time

AbstractMongoBackend.handleQuery is resolveDatabase(message) then MongoDatabase.handleQuery, and resolveDatabase's computeIfAbsent calls openOrCreateDatabase, which is server.getDatabase(name). So an unauthenticated OP_QUERY can also OPEN a database that is on disk and closed, not only read one that is already open.

Door enumeration, from the dependency's bytecode

MongoBackend declares 15 methods. The library's Netty handler invokes six of them from a client socket:

methodgated
handleCommandyes
handleMessage (OP_MSG, unwraps to handleCommand)yes
handleQuery (OP_QUERY on a collection)no
getCurrentOperationstag-only override, but AbstractMongoBackend returns empty and touches no database
getServerStatusnot overridden; reads host, version, pid, uptime and cursor count only, no resolveDatabase
handleCloseyes

Why the existing tests cannot see it

MongoDBAuthorizationTest, the regression test for the earlier advisory, passes because the modern com.mongodb driver sends OP_MSG, which is the one door that was never open. Every OP_QUERY test in the module also uses that driver and authenticates. No test sends a legacy OP_QUERY on a non-$cmd collection.

Suggested fix, unchanged

Route handleQuery through the same gate handleCommand uses, or hoist the gate so it runs for every entry point of the backend. The guarantee that closes the class: a test that enumerates the public entry points of MongoBackend by reflection and fails for any one MongoDBBackend neither overrides nor explicitly exempts. The project already has that shape in ProtocolContextCensusTest, and 0f9ceadcc2 added a per-module reflection enumeration for the tagging concern specifically, so the mechanism is in the tree already and could be reused for the authorization concern.

---

Update 2026-10-22: still present, and it also OPENS a closed database

Re-checked at main. MongoDBBackend.handleQuery(MongoQuery) is unchanged and still tag-only:

public QueryResult handleQuery(final MongoQuery query) {
  final String enclosing = tagAsMongo();
  try {
    return super.handleQuery(query);
  } finally {
    restoreProtocol(enclosing);
  }
}

No principal lookup, no revalidate, no canAccessToDatabase, no admission ticket, no RunningQuery, no user binding. The only commit touching mongodbw since the last update is the TIMESERIES delete work, which does not go near authorization.

The part we understated

The route does more than read. From the bundled library's bytecode, AbstractMongoBackend.handleQuery is resolveDatabase(message) then MongoDatabase.handleQuery, and resolveDatabase is computeIfAbsent(name, openOrCreateDatabase). In this tree:

// MongoDBBackend
protected MongoDatabase openOrCreateDatabase(final String databaseName) {
  return new MongoDBDatabaseWrapper(server.getDatabase(databaseName), plugin, this);
}

// ArcadeDBServer
public ServerDatabase getDatabase(final String databaseName) {
  return getDatabase(databaseName, false, true);
}

That third argument is allowLoad, and refuseIfClosedByCommand is false. So an unauthenticated OP_QUERY naming a database that is on disk and closed will open it, including one an operator closed deliberately with close database to take a cold backup or to replace its files. The same request then reads it, because the engine's per-type layer takes its no-user no-op path.

Test coverage of the vulnerable door

handleQuery and OP_QUERY appear in exactly one mongodbw test, the protocol-tag one. The existing authorization regression test passes because the modern driver sends OP_MSG, which is the one door that was never open.

Suggested fix, unchanged in substance

Route handleQuery through the gate handleCommand uses, or hoist the gate above both. The guarantee that closes the class rather than this method: enumerate MongoBackend's entry points by reflection and fail for any one MongoDBBackend neither overrides nor explicitly exempts. That mechanism already exists in this repository for the protocol-tag concern and could be reused.

---

Validation update 2026-10-23

Both reported vulnerabilities are fixed. Two small residuals follow.

I re-validated all four reports against the hardening work, each against its own report rather than the commit message. All four come back COMPLETE, every fix has a test, and I made each test inert and re-ran it: none was inert, and in each case the failure on the inert tree reproduces the original report verbatim, including the admin group coming back widened for the groups-file case.

Worth saying explicitly: the rename fix also closes an escape I did not report, detaching a non-empty bucket from a restricted type. And stop() no longer takes the policy lock before cancelling, so the shutdown stall is gone.

Two residuals remain. Neither is the reported vulnerability and neither needs an embargo in my view, but both belong in this thread rather than a public issue.

1. A type alias still leaks the sample count of a denied TIMESERIES type

LocalDatabase.countType gates on the name the caller passed rather than on type.getName(), and an alias is not a key of the access snapshot, so the default-allow arm fires:

public long countType(final String typeName, final boolean polymorphic) {
  ...
  final DocumentType type = schema.getType(typeName);
  ...
  checkPermissionsOnType(typeName, SecurityDatabaseUser.ACCESS.READ_RECORD);

SELECT count(*) through the alias answers, while reads and writes through the same alias are still refused. Record-backed types are unaffected. Gating on type.getName() is a one line change.

This is the same shape as the rename escape: a permission keyed by a name, consulted with a name the caller chose. The narrower patch closes the rename route; the alias route is the other way to present a second name for the same type.

2. "A reload never writes the live file" is still conditional

With a root password configured, a reload that needs it is applied rather than refused, and server-users.jsonl is rewritten from memory. No loop, no stall, no widening, so this is a much smaller thing than what was reported. I mention it only because the guarantee as stated in the class is unconditional and this is the one case where it does not hold.

One observation, not a finding

On the MongoDB side an empty or $-prefixed database name still takes the admin branch, so a command there is authenticated but not checked against canAccessToDatabase and runs with no principal bound. That is unchanged from before the fix and I could not reach it by any supported route that creates such a database, so I am noting it rather than reporting it.

---

Update, 2026-10-25, re-validated at main d9faba8ca3

The fix holds. MongoDBLegacyOpQueryAuthorizationTest is 5 of 5 green at main, and this is the one of our four reports where the census we asked for was actually delivered: the reflection census over MongoBackend's entry points at MongoDBLegacyOpQueryAuthorizationTest:103 means a door added later cannot quietly skip the gate.

Two things to pass on.

The census asserts less than the guarantee it protects

It asserts that an unauthenticated channel is refused on each door. It does not assert that each door binds the principal. A future door that authenticates and then calls super.<door>(...) directly, skipping runAuthorized, passes the census today.

What would make it unbreakable: extend the same census to assert, for each gated door, that a request from an authenticated but per-type-denied principal is refused by the per-type layer, not only that an unauthenticated one is refused.

An asymmetry we did not reproduce

handleCommand still exempts the admin namespace. isAdminDatabase at MongoDBBackend.java:355 is databaseName == null || isEmpty() || startsWith("$") || "admin".equals(databaseName), and the admin branch at :212-220 authenticates but runs no canAccessToDatabase, except for dropDatabase and getMore, and no runAuthorized, so no principal is bound.

handleQuery closed exactly this on its own door, and says so in its own comment: an admin, local or $-prefixed name is no exemption on this door. handleCommand did not.

We are stating this as an asymmetry in the code, not as a demonstrated bug. Reaching it needs a database literally named admin, or the empty name, or a $-prefixed one, and we did not build a wire client to try. We would rather tell you about the asymmetry than sit on it until we have a reproduction, but we are not claiming more for it than a code read supports. If you know that no supported route can create such a database, this is nothing.

Affected versions

References

GitHub · ArcadeData/arcadedb