Skip to content

Query constraints on objectId, sessionToken, _rperm, _wperm and authData keys are forwarded to MongoDB without operator validation #10872

Open

Description

@mtrezza

New Issue Checklist

Issue Description

With the MongoDB adapter, query constraints on a regular field go through transformConstraint in src/Adapters/Storage/Mongo/MongoTransform.js, which only accepts the operators of the Parse query language and rejects anything else with error 107 bad constraint: <operator> (for example $not or $elemMatch).

Constraints on a few keys skip that step. transformQueryKeyValue returns the client value untouched for objectId (mapped to _id), sessionToken (mapped to _session_token), _rperm and _wperm, and for authData.<provider>.<field> on _User (mapped to _auth_data_<provider>.<field>). Whatever operator document the client sends under these keys is forwarded to MongoDB as-is, so MongoDB operators that Parse Server does not expose, and arbitrary nesting of them, are evaluated by the database for these keys only.

Examples that MongoDB accepts and evaluates (verified on MongoDB 8.0.23 with a two-document collection):

{"objectId":{"$not":{"$not":{"$regex":"^a"}}}}            -> _id:{$not:{$not:{$regex:"^a"}}}
{"_wperm":{"$elemMatch":{"$not":{"$regex":"^z"}}}}        -> _wperm:{$elemMatch:{$not:{$regex:"^z"}}}
{"_wperm":{"$all":[{"$elemMatch":{"$regex":"^a"}}]}}      -> forwarded verbatim

The same shapes on a regular field are rejected with 107 bad constraint: $not / bad constraint: $elemMatch. Related to this, reduceInRelation (src/Controllers/DatabaseController.js, relatedIds = query[key]['$in'].map(r => r.objectId)) reads pointer object ids from the client without a type check and queries the join table through owningIds before validateQuery runs; a non-string id is rejected by both adapters' $in handling for String fields (107 bad atom on MongoDB, 102 type mismatch on Postgres), so this part only produces a confusing error rather than reaching the database.

Steps to reproduce

Start Parse Server with MongoDB, create any object, then:

curl -s -G http://localhost:1337/parse/classes/TestObject -H 'X-Parse-Application-Id: APP_ID' \
  --data-urlencode 'where={"objectId":{"$not":{"$not":{"$regex":"^a"}}}}'

# same operator shape on a regular field
curl -s -G http://localhost:1337/parse/classes/TestObject -H 'X-Parse-Application-Id: APP_ID' \
  --data-urlencode 'where={"name":{"$not":{"$not":{"$regex":"^a"}}}}'

Actual Outcome

The first query runs on MongoDB and returns the objects whose id starts with a; the second is rejected with {"code":107,"error":"bad constraint: $not"}.

Expected Outcome

Constraints on objectId, sessionToken, _rperm, _wperm and authData.* accept the same operators as any other field and reject unsupported operator documents with the same 107 error, for example by running them through transformConstraint (with the existing special handling for _GlobalConfig/_GraphQLConfig numeric ids and the authData key mapping) instead of returning the raw value. Optionally, reduceInRelation validates that pointer object ids are strings before querying the join table, as reduceRelationKeys already does for $relatedTo.

Environment

Server

  • Parse Server version: 9.11.1-alpha.2
  • Operating system: macOS 27.0.1
  • Local or remote host: local

Database

  • System (MongoDB or Postgres): MongoDB (Postgres not checked)
  • Database version: 8.0.23
  • Local or remote host: local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): REST API (curl)
  • SDK version: n/a

Logs

n/a

Activity

  1. parse-github-assistant commented on Nov 5, 2026

    @parse-github-assistant

    🚀 Thanks for opening this issue!

    ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

  2. Mani7527 commented on Nov 23, 2026

    @Mani7527

    Hi! I'd like to work on this. I confirmed it still reproduces on current alpha: transformQueryKeyValue in MongoTransform.js returns the raw client value for objectId, sessionToken, _rperm, _wperm and authData.*.

    My plan:

    • Add failing tests (MongoDB) showing that $not / $elemMatch operator documents on these keys are rejected with 107 bad constraint, the same as on a regular field
    • Run constraint values on these keys through transformConstraint, keeping the existing _GlobalConfig / _GraphQLConfig numeric id handling and the authData key mapping
    • Add tests that the supported operators ($in, $nin, $exists, $eq, $ne, $regex, ...) and the internal ACL queries on _rperm / _wperm keep working

    I'll keep the optional reduceInRelation type check out of this PR to keep it small, unless you'd prefer it included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions