Summary
A SQL injection vulnerability in n8n's TimescaleDB and legacy Postgres v1 nodes allows authenticated workflow creators to supply crafted parameters that are concatenated into SQL queries without proper sanitization.
Under these conditions, arbitrary SQL can be executed against the connected database within the privileges of the configured database account, making misuse of workflow configuration highly risky in shared or multi-user environments.
Affected context
This vulnerability arises in n8n workflow automations that use the TimescaleDB node or the legacy Postgres v1 node and allow users to configure query-related parameters.
It is relevant in deployments where multiple authenticated users can create or modify workflows and where these nodes connect to production or sensitive databases with broad privileges.
The risk is heightened in cases where workflow configuration is treated as trusted logic and where database accounts used by n8n have extensive read/write or administrative capabilities.
Exploit preconditions
- Attack surface: n8n web interface and API for creating or editing workflows that use TimescaleDB or Postgres v1 nodes.
- Required access: Authenticated user account with permissions to create or modify workflows, and the ability to set or update node parameters.
- Trigger point: Execution of a workflow that includes a vulnerable node whose query or parameters incorporate user-supplied values into SQL statements.
- Why exploitation is possible: Node implementations allow user-controlled parameters to be interpolated directly into SQL commands without consistent parameterization or escaping, enabling crafted values to alter the intended query structure.
Why this happens
The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In affected n8n nodes, workflow parameters that control query behavior are treated as trusted input and combined with SQL strings, rather than being bound as typed parameters through safe query interfaces.
This pattern allows a user who can configure node properties to inject SQL fragments that change the semantics of the query, bypass intended constraints, or introduce additional commands, all executed within the scope of the configured database account.
Potential impact
- Authenticated users may execute arbitrary SQL statements on the connected database.
- Attackers could read sensitive tables or exfiltrate data accessible to the n8n database account.
- Workflows could be used to modify or delete records, leading to data integrity loss or application disruption.
- In some configurations, SQL injection could enable creation of new accounts or escalation of privileges within the database.
- Malicious queries may be used to pivot to other application layers that depend on the compromised database.
General mitigation guidance
Effective mitigation focuses on eliminating the ability for workflow parameters to alter SQL structure and ensuring database interactions are strictly parameterized.
Recommended design patterns include:
- Treat all workflow-supplied values as untrusted and bind them using prepared statements or parameterized queries, rather than string concatenation.
- Limit node capabilities so users configure only declarative parameters (e.g., filters, fields, limits) that are mapped to safe query constructs rather than raw SQL.
- Constrain database accounts used by automation nodes to least privilege, restricting high-risk operations such as schema changes or broad administrative actions.
- Introduce validation layers that enforce schemas or allowlists for query-related parameters, rejecting unexpected or structurally unsafe inputs.
- Apply defense-in-depth controls at the database level (e.g., restrictive roles, auditing, and query controls) to reduce the impact of any injected queries.
How teams detect issues like this
Detection can be approached through both application-level and database-level controls:
- Use static analysis or code review to identify locations where node implementations construct SQL strings from user-configurable parameters; look for concatenation or template interpolation instead of parameter binding.
- Establish secure coding standards for workflow node development, with automated checks that flag direct assembly of SQL using user-controlled values.
- Monitor database logs and query audit trails for anomalous patterns originating from n8n connections, such as unexpected statements, mass updates, or schema operations.
- Employ policy enforcement in CI/CD pipelines that require new nodes or query logic to pass security-focused tests for injection resistance.
- Consider runtime monitoring or database firewalls that can detect and block suspicious SQL constructs commonly associated with injection attacks.

