Summary
n8n's Source Control feature can be abused to inject crafted Data Table JSON that results in SQL injection against the internal PostgreSQL database.
If an attacker can write to the connected git repository and an administrator pulls those changes, malicious column names may be executed as SQL, potentially compromising the instance and its data.
Affected context
This vulnerability appears in n8n deployments that:
- Use PostgreSQL as the database backend
- Have Source Control enabled and connected to a writable git repository
- Import Data Table workflow assets from version-controlled JSON files
It manifests when column names from these JSON files are interpolated into SQL queries without robust validation or sanitization. The issue is triggered only when an administrator initiates a Source Control Pull, so environments without this feature or workflow are less exposed.
Exploit preconditions
- Attack surface: n8n Source Control pull operation that imports Data Table JSON from a git repository.
- Required access: Ability to commit changes to the git repository configured in n8n Source Control; no direct access to n8n's database required.
- Trigger point: An administrator performs a Source Control Pull, causing n8n to deserialize the Data Table JSON and construct SQL using attacker-controlled column names.
- Why exploitation is possible: The application builds SQL statements directly from JSON-defined column metadata without strict validation or safe query construction, allowing crafted column names to alter the intended SQL logic.
Why this happens
The core issue is the use of untrusted metadata to dynamically construct SQL queries without enforcing strict separation between data and query syntax. Data Table column names from JSON configuration are treated as safe identifiers and interpolated into SQL statements in a way that lets attackers inject arbitrary SQL fragments.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection). Instead of using parameterized queries and vetted identifier lists, the code path trusts repository-sourced JSON as configuration, blurring the boundary between configuration and executable query structure.
Potential impact
- Attackers may read sensitive workflow and user data stored in PostgreSQL.
- Malicious SQL could modify or delete Data Tables and other application records.
- SQL injection can lead to privilege escalation within the application's data layer.
- In some setups, attackers could execute database-level functions that may enable further system compromise.
General mitigation guidance
Effective mitigation focuses on treating all repository-sourced configuration as untrusted input and enforcing safe query construction patterns. Recommended approaches include:
- Using parameterized queries for all dynamic data values and avoiding direct string concatenation of identifiers where possible.
- Restricting accepted column names to an explicit allowlist or validating them against a strict schema before building queries.
- Introducing a layer that normalizes or maps logical column names from JSON to internal, pre-defined identifiers rather than using raw values.
- Running the database with least-privilege credentials so that even if a query is abused, accessible operations are minimized.
- Designing Source Control import logic to fail closed when configuration metadata contains unexpected characters or shapes that could impact query syntax.
How teams detect issues like this
Detection generally involves identifying insecure SQL construction patterns around configuration-driven metadata and monitoring for anomalous repository changes:
- Static analysis rules targeting dynamic SQL creation that use column or table names derived from JSON or other configuration files.
- Code reviews that flag any use of unvalidated identifiers in SQL strings and ensure parameterization of values.
- Policies that require schemas and allowlists for configuration-driven Data Tables, enforced during pull requests and CI pipelines.
- Runtime monitoring and database logging to detect unusual or highly-privileged queries triggered immediately after Source Control pulls.
- Optional use of automated security scanning tools integrated with the n8n codebase and workflows to highlight SQL injection-prone patterns.

