NoSQL Query Operators and Input Types
See how a query object can replace an access code, then validate the input while keeping workspace checks in place.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
A SharedDesk member has a link to a private handbook in the Green workspace. They know its document ID, but they do not know the access code. The app should return the handbook only when the workspace and the exact code both match.
The problem starts when the request supplies a small query object instead of a code string. MongoDB can interpret that object as an instruction. This is NoSQL operator injection: input changes the check instead of supplying the value to check.
We'll begin with the handbook lookup. A selector means the query object; a tenant means the workspace. Later sections cover more advanced searches, saved filters, and database wrappers.
Read a selector as a small language
In an ordinary MongoDB equality selector, a plain value describes what a field must equal. Operator objects describe conditions to evaluate. The following selectors have different meanings even though both are valid object structures in JavaScript.
// Plain equality: match this literal access code.
const literalSelector = {
tenantId: 'workspace-green',
documentId: 'doc-handbook',
accessCode: 'fixture-code-known-to-owner',
};
// Operator condition: the code need only be non-null.
const operatorSelector = {
tenantId: 'workspace-green',
documentId: 'doc-handbook',
accessCode: { $ne: null },
};
In the second selector, the workspace and document predicates still exist. An attacker does not thereby gain unrestricted access to every tenant. The secret-code comparison, however, no longer requires knowing the secret. If the feature's rule requires that knowledge, a workspace member who knows a public document identifier can cross the document's access boundary.
Compare this with a selector over a user's own already visible orders. Broadening an order-number match while retaining a user restriction may not disclose anything the user could not already read. A changed query is not automatically a useful security finding. State which rule the changed selector violates and which result becomes unauthorized.
NoSQL is also a broad product category. Redis commands, document databases, search engines, and graph stores expose different interfaces. The operator-object examples in this lecture concern MongoDB-style selectors. Do not transfer their behavior to another system merely because both are called NoSQL databases.