Summary
An input validation flaw in n8n's MongoDB node allows an authenticated workflow editor to craft malicious filter values that are passed directly to MongoDB as query filters.
Under these conditions, an attacker can cause unintended documents to be matched and overwritten with attacker-controlled content, risking data integrity wherever such workflows run.
Affected context
This vulnerability arises in n8n workflows that use the MongoDB node's "Find And Replace" operation and accept dynamic, user-influenced filter values.
It becomes relevant when authenticated users can edit workflows or configure node parameters, and those filter values are treated as trusted and forwarded directly to the database engine.
The risk is higher in environments where the MongoDB node points to production databases or where workflow designers share access across teams without strict role boundaries.
Exploit preconditions
- Attack surface: n8n workflow editor and MongoDB node configuration.
- Required access: Authenticated access with permissions to create or edit workflows containing MongoDB "Find And Replace" operations.
- Trigger point: Execution of a workflow where the MongoDB node uses an attacker-supplied filter value as the query filter.
- Why exploitation is possible: The filter value is not validated, normalized, or constrained before being passed to MongoDB, enabling crafted input to match broader or unintended sets of documents and drive overwrite operations.
Why this happens
The underlying issue is an injection-style flaw where application logic passes externally controlled data into a database query without sufficient validation or constraint.
In the affected MongoDB node, filter parameters are treated as trusted and forwarded as-is to the query engine, which corresponds to CWE-89: Improper Neutralization of Special Elements used in an SQL Command when generalized to NoSQL query construction.
Abstractly, the insecure pattern is: allowing workflow-configurable query filters to be fully expressive objects without schema restrictions, type checks, or safe construction helpers, so the database interprets attacker-designed filters as legitimate query criteria.
Potential impact
- Unintended modification or overwrite of legitimate documents in MongoDB collections.
- Data corruption in workflows that rely on the "Find And Replace" operation for critical records.
- Loss of application integrity where downstream processes consume tainted or incorrect data.
- Potential expansion of access to data that the workflow designer did not intend to touch, depending on filter scope.
General mitigation guidance
Effective mitigation focuses on constraining and sanitizing query filters before they reach the database.
Common defensive patterns include:
- Applying strict schema validation to MongoDB node input, limiting which fields and operators can be used in filters.
- Constructing queries through well-defined, typed configuration objects rather than accepting arbitrary filter structures.
- Enforcing role-based workflows so only trusted users can author database-modifying operations, and using least-privilege database credentials.
- Adding server-side checks that reject overly broad or ambiguous filters for data modification operations.
How teams detect issues like this
Teams can look for this class of issue by:
- Using static analysis or configuration linting to identify nodes or components that pass user-controlled filters directly into database APIs.
- Reviewing workflow definitions for MongoDB operations that both read and write data, especially "Find And Replace" patterns with unconstrained filter fields.
- Implementing policy checks in CI/CD that flag workflows containing arbitrary query objects or dangerous operators for manual review.
- Leveraging automated security scanning tools that understand infrastructure-as-code or workflow-as-code formats to surface injection-like patterns in database nodes.

