Mongoid translates string-typed criteria in where() clauses into MongoDB's $where operator, which executes the string as server-side JavaScript. When you write Widget.where(status: user_input) with a string value for status, Mongoid does not generate a parameterized field comparison. It routes that string directly to MongoDB's query engine for JavaScript evaluation. The developer receives no warning, no exception, no indication that their query has been transformed from a safe comparison into arbitrary code execution.
This is not an exotic misuse of the API. This is what developers naturally write. A developer familiar with ActiveRecord's where() method expects parameterization—they expect the ORM to protect them from injection by treating user input as data, not code. Mongoid silently violates that expectation by checking the type of the value and, finding a string, routing it through $where. The path of least resistance is also the most dangerous one.
The practical impact: any code path that passes string values to where() clauses is potentially exploitable. This includes direct parameter binding (where(status: params[:status])) but extends to any query built from data that could be influenced by an attacker—including through business logic, internal services, or configuration that the application itself retrieves. The "unauthenticated attacker" framing in CVSS scoring obscures this: the real question is whether any production query path could receive a string value that originates from or could be manipulated by untrusted input.
Detection is hampered by the silent routing. Unlike SQLAlchemy's text() or Django's Raw(), which at least appear explicitly in code review, the string-to-JavaScript translation happens inside Mongoid's query routing layer. A codebase audit for text() or Raw() would surface the danger; auditing for strings passed to where() is far less straightforward.
Patch or no patch, audit every where() call in your codebase that could receive string values from any input source—request parameters, deserialized data, configuration, or business logic outputs. Convert those to explicit hash criteria using symbols or MongoDB's query operators ($eq, $in, etc.) rather than relying on type-based routing. If you must use $where with JavaScript, do so explicitly and with full awareness that it enables code execution on your database server.