Summary
In affected versions of n8n, the Merge node's "Combine by SQL" mode uses an insufficiently restricted AlaSQL sandbox that allows authenticated workflow editors to execute dangerous SQL statements.
Under these conditions, an attacker who can create or modify workflows may read arbitrary local files from the n8n host and escalate to remote code execution, compromising the entire automation instance.
Affected context
This vulnerability occurs in n8n deployments that expose workflow creation or editing capabilities to users and make use of the Merge node in "Combine by SQL" mode.
The risk is present when:
- Users can configure or modify the SQL expressions executed by the AlaSQL engine
- The n8n instance runs with access to sensitive host files (e.g., configuration, credentials, environment variables)
- The n8n application process has sufficient permissions that, if compromised, would impact other services or data
The vulnerability is not exposed to unauthenticated users by default, but any user with workflow-editing permissions becomes a powerful attacker within the instance.
Exploit preconditions
- Attack surface: n8n web UI or API endpoints that allow creation or modification of workflows using the Merge node's "Combine by SQL" mode.
- Required access: Authenticated account with permissions to create or edit workflows (including node configuration).
- Trigger point: Execution of a workflow that includes a Merge node configured with attacker-controlled SQL in "Combine by SQL" mode.
- Why exploitation is possible: The AlaSQL sandbox does not enforce strict limitations on the SQL dialect and permitted functions, allowing crafted statements to:
- Access the local filesystem or environment
- Escape the intended query-only behavior
- Execute logic that ultimately results in arbitrary code execution in the n8n process context.
Why this happens
The core issue lies in relying on a sandboxed SQL engine (AlaSQL) for executing user-controlled SQL without adequately constraining what operations are allowed.
This maps to:
- CWE-94: Improper Control of Generation of Code ('Code Injection') because user-supplied SQL can trigger execution paths equivalent to evaluating attacker-controlled code within the runtime.
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in the sense that untrusted input is embedded into SQL statements executed by an engine that has capabilities beyond pure data querying.
Instead of limiting the language to safe, declarative operations on in-memory data sets, the sandbox permitted powerful statements and functions, effectively turning a data transformation feature into a code execution primitive tied to the host environment.
Potential impact
- Disclosure of sensitive local files on the n8n host (e.g., configuration files, credentials, SSH keys, environment variables).
- Execution of arbitrary commands or code with the privileges of the n8n process.
- Complete compromise of the n8n instance, including stored credentials and connected integrations.
- Pivoting to other internal systems reachable from the n8n host, using n8n's configured connections.
- Tampering with workflows to introduce persistent malicious automation or data exfiltration.
General mitigation guidance
Long-term mitigation focuses on hardening how user-defined expressions and queries are executed inside workflow engines and eliminating unsafe code execution paths:
- Constrain embedded languages: Treat SQL, JavaScript, or any embedded DSL as untrusted code. If user-defined expressions are needed, restrict them to a minimal, declarative subset without filesystem, process, or networking capabilities.
- Use hardened interpreters: Prefer execution environments that are designed for sandboxing (e.g., interpreters without access to host APIs) and configure them with explicit allow-lists of permitted functions and operations.
- Separate privileges: Run workflow engines and query evaluators under dedicated, least-privilege OS accounts with minimal file and network access so that even a sandbox breakout has limited blast radius.
- Strict node capability design: For nodes that allow user-defined logic (SQL, code, expressions), design them around pre-defined parameters and templates rather than raw, free-form source strings, wherever possible.
- Permission scoping: Limit who can define or edit nodes that execute user-supplied expressions, and consider role-based controls that distinguish between "safe" node configuration and "advanced/scripted" configuration.
- Configuration hardening: Avoid storing long-lived secrets or highly sensitive files on the same host or within the same privilege domain as the workflow engine when possible; use secret managers and network-layer protections.
How teams detect issues like this
Effective detection combines code-level and configuration-level review with runtime monitoring:
- Static analysis & code review:
- Flag use of general-purpose interpreters (SQL engines, JS evaluators) where input is directly or indirectly controlled by users.
- Search for calls into AlaSQL or similar APIs that are passed raw user-defined strings without strict validation or allow-listing.
- Review node implementations that expose "script", "SQL", or "expression" fields to ensure they enforce safe subsets and do not provide host-level capabilities.
- Policy and CI gates:
- Enforce secure coding guidelines requiring explicit sandbox configuration or allow-listing for any embedded languages.
- Integrate SAST or custom linters into CI that detect insecure sandbox or interpreter usage patterns.
- Runtime monitoring:
- Monitor the workflow engine for abnormal filesystem access patterns originating from workflow execution processes.
- Log and analyze advanced node configurations (e.g., SQL modes) for high-risk usage patterns, such as access to non-workflow data.
- Configuration audits:
- Periodically review which users or API tokens can create or edit workflows, and whether high-risk nodes or modes are enabled.
- Inspect existing workflows for use of powerful "SQL" or "code" features that may be exploitable.

