Summary
A SQL injection flaw in n8n's legacy MySQL v1 node lets expression-evaluated values be concatenated directly into raw SQL queries without parameter binding.
When workflows use executeQuery with attacker-controlled expression inputs behind externally-reachable triggers, an attacker can run arbitrary SQL under the configured MySQL credentials.
Affected context
This vulnerability appears in n8n workflows that use the legacy MySQL v1 node's executeQuery operation with dynamic expressions (e.g., {{ $json.someField }}).
Risk increases when:
- The workflow is wired to an externally-reachable trigger such as a Webhook node, and
- User-supplied request data flows into those expressions.
Under these conditions, the expression output is inserted into the SQL string without parameterization, enabling input-driven modification of the final query.
Exploit preconditions
- Attack surface: Any n8n workflow exposing an external trigger (e.g., Webhook) that feeds data into MySQL v1
executeQueryexpressions. - Required access: Ability to send crafted requests to the exposed trigger endpoint or otherwise influence expression-sourced values used in queries.
- Trigger point: Evaluation of
{{ ... }}expressions followed by construction and execution of the raw SQL string by the MySQL v1 node. - Why exploitation is possible: The node builds SQL via string concatenation instead of using parameterized queries, so attacker-controlled expression output is treated as part of the executable SQL statement.
Why this happens
The underlying bug is the direct interpolation of evaluated expression values into query strings in the legacy MySQL v1 node.
Instead of binding values through placeholders and parameterized queries, the implementation relies on manual string assembly, allowing data to alter the query's structure.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where untrusted input is not safely separated from SQL syntax.
Potential impact
- An attacker may read sensitive data from tables accessible to the configured MySQL account.
- An attacker could modify or delete records, leading to data corruption or loss.
- Workflows and application logic can be impacted by unauthorized changes to configuration or state tables.
- Depending on database privileges, the attacker may create new accounts or escalate influence within the database environment.
General mitigation guidance
Effective mitigation focuses on removing string-based query construction and reducing trust in expression-sourced data.
Defensive patterns include:
- Using parameterized queries or prepared statements for all dynamic SQL, ensuring values are bound rather than concatenated.
- Designing workflows so that external input is validated and constrained to expected formats before being used in database operations.
- Separating query structure from data by defining fixed SQL templates and allowing only controlled, whitelisted parameters to vary.
- Assigning least-privilege credentials to the MySQL connection so that even if a query is abused, its impact is limited.
- Avoiding legacy database nodes that do not enforce secure-by-default query construction patterns.
How teams detect issues like this
Detection typically involves a mix of code and workflow review along with automated checks:
- Static analysis or workflow linting rules that flag concatenation of
{{ ... }}expression outputs into raw SQL strings. - Review of n8n workflows for use of the legacy MySQL v1 node and examination of
executeQueryoperations that accept external input. - Policy-based controls that restrict the use of non-parameterized query patterns and enforce parameter binding for all database operations.
- Logging and monitoring of unusual or overly complex SQL statements originating from workflow executions, coupled with anomaly detection on query patterns.

