Summary
n8n before version 2.4.0 contains a SQL injection flaw in its MySQL, PostgreSQL, and Microsoft SQL workflow nodes, where identifier values from node configuration are not safely escaped.
Authenticated users with workflow creation permissions can craft malicious table or column names that result in arbitrary SQL execution, enabling unauthorized data access or modification when workflows run.
Affected context
The vulnerability appears in n8n workflows that use built-in MySQL, PostgreSQL, or Microsoft SQL nodes and rely on user-supplied configuration parameters to build SQL queries.
It is relevant in deployments where authenticated users can design or edit workflows and where node parameters such as table names, column names, or similar identifiers are concatenated into queries without adequate escaping or validation.
The risk increases when those workflows run with accounts that have broad database privileges or access to sensitive tables.
Exploit preconditions
- Attack surface: n8n workflow editor and execution engine, specifically database nodes (MySQL, PostgreSQL, MSSQL).
- Required access: Authenticated access with permission to create or modify workflows that include affected database nodes.
- Trigger point: Execution of a workflow where node configuration parameters (e.g., table or column names) are incorporated directly into SQL statements.
- Why exploitation is possible: Identifier values from node configuration are treated as trusted input and embedded into SQL strings without proper escaping or safe parameterization, allowing crafted values to alter query structure.
Why this happens
This issue stems from dynamic SQL construction that directly interpolates user-controlled identifier fields into query strings.
Instead of using parameterized queries or constrained identifier handling, n8n's database nodes treat configuration parameters as trusted values and concatenate them into SQL, enabling an attacker to inject additional clauses or commands.
Conceptually, this aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where failure to properly neutralize control characters in input allows unintended SQL behavior.
Potential impact
- Unauthorized reading of sensitive data from database tables.
- Modification or deletion of records, impacting data integrity.
- Bypassing application-level authorization checks enforced by the workflow.
- Creation or alteration of database schema objects if the connected account has sufficient privileges.
- Chaining with other issues to escalate privileges or pivot to additional systems that rely on the same database.
General mitigation guidance
Effective mitigation centers on removing direct string concatenation from query construction and limiting trust in workflow configuration input.
Common secure patterns include:
- Using parameterized queries or query builder abstractions that separate data values and identifiers from SQL control logic.
- Restricting identifier inputs to a vetted, application-controlled whitelist or mapping rather than accepting arbitrary user-provided names.
- Applying strict validation and normalization to node configuration parameters, rejecting unexpected characters or patterns that can alter query structure.
- Running database connections with least-privilege credentials, minimizing the potential impact if a workflow is abused.
- Designing workflows such that complex or ad-hoc SQL is avoided in favor of higher-level operations with controlled semantics.
How teams detect issues like this
Detection typically involves a combination of code-level and configuration-level review:
- Static analysis rules or linters that flag dynamic SQL construction and direct concatenation of user-controlled parameters in node implementations.
- Manual code review focusing on database nodes, looking for places where table or column names are derived from configuration and inserted into queries without escaping or validation.
- Security testing of workflow templates, using test inputs that include SQL metacharacters to observe whether queries can be altered.
- Policy enforcement in CI/CD pipelines that require use of parameterized database access layers and disallow raw query building in shared components.
- Monitoring database logs for unusual queries originating from n8n workflows, such as statements targeting unexpected tables or including suspicious patterns.

