Summary
A flaw in n8n's Merge node SQL Query mode allowed authenticated users who can create or modify workflows to write arbitrary files to the n8n server's filesystem.
Under these conditions, an attacker-controlled workflow could plant executable files or modify server-side resources, potentially leading to remote code execution.
Affected context
This vulnerability occurs in n8n instances where:
- The Merge node is used in SQL Query mode inside workflows, and
- Users have permissions to create or modify workflows that are executed by the n8n server.
The issue is relevant in deployment models where workflow authors are not fully trusted or where compromised accounts can alter workflows.
It does not require direct shell or filesystem access; instead, the workflow engine itself becomes the vehicle for writing attacker-controlled files to the server's filesystem.
Exploit preconditions
- Attack surface: The n8n web interface / API used to define and update workflows.
- Required access: Authenticated user with permission to create or modify workflows containing the Merge node in SQL Query mode.
- Trigger point: Execution of a malicious or modified workflow that causes the Merge node to perform operations resulting in arbitrary file writes on the server.
- Why exploitation is possible: The Merge node's SQL Query mode permits user-controlled data to influence file write behavior without proper restrictions or validation, allowing crafted workflow configurations to direct data into attacker-chosen paths or files.
Why this happens
The core issue maps to CWE-434: Unrestricted Upload of File with Dangerous Type and, more broadly, arbitrary file write.
In this case, the workflow engine and the Merge node's SQL Query mode expose functionality that allows user-controlled inputs and workflow definitions to influence where and what the server writes to disk.
Because these file operations are not adequately constrained—such as by limiting file locations, types, or usage—the system effectively allows an authenticated user to place arbitrary content into server-side files.
This breaks expected security policy boundaries (CWE-693: Protection Mechanism Failure) and enables follow-on attacks, such as planting executable scripts or configuration files that the n8n runtime or its environment may later load and execute.
Potential impact
- Arbitrary file creation and modification on the n8n server filesystem.
- Placement of attacker-controlled scripts or modules that may be executed by the application stack or underlying platform.
- Escalation to remote code execution within the n8n server context.
- Tampering with server-side configuration, logs, or data files.
- Facilitation of persistence, lateral movement, or further compromise in the hosting environment, depending on deployment.
General mitigation guidance
Effective mitigation focuses on constraining how workflow definitions can influence server-side file operations and ensuring server protections are enforced by default:
- Restrict workflow-capable nodes so they cannot directly or indirectly perform unconstrained file writes to arbitrary locations.
- Enforce strict validation and sanitization on any path-like or file-related parameters derived from workflow definitions or user inputs.
- Apply strong least-privilege principles to the n8n process, limiting filesystem permissions and preventing write access to sensitive directories such as application code, configuration, and system paths.
- Introduce server-side policy controls to separate "trusted" administrative workflows from untrusted or semi-trusted user workflows, and disable high-risk capabilities for the latter.
- Use execution sandboxes or containerization where feasible, so that even if arbitrary files are written, their impact is contained within a tightly scoped environment.
How teams detect issues like this
Detection typically involves a combination of configuration review, code analysis, and runtime monitoring:
- Static analysis / code review: Look for workflow nodes or plugins that can perform file writes based on user-controlled parameters, especially where file paths or content are derived from SQL queries or other dynamic expressions.
- Policy enforcement: Implement guardrails in the workflow builder to prevent certain node configurations (e.g., disallow file-writing behaviors except in admin-controlled contexts).
- Logging and monitoring: Enable detailed workflow execution logs and monitor for suspicious patterns such as workflows repeatedly writing to unexpected directories or creating executable-looking files.
- Automated checks: Integrate security scanning tools into CI/CD pipelines to flag patterns where workflow logic interacts with the filesystem without robust constraints.
- Filesystem auditing: Where possible, use OS or container-level auditing to track new file creation and changes in application directories, correlating them back to workflow executions.

