Summary
n8n contains an expression sandbox escape in the $fromAI handler that can expose host-language functionality through unsafe property resolution. An attacker with workflow-build privileges may use this behavior to execute arbitrary code in the main n8n process.
Affected context
The vulnerability affects n8n workflows that use the $fromAI handler and run on versions with the unsafe placeholder-resolution behavior. Risk arises when a user who can build or modify workflows can cause the handler to process attacker-controlled placeholder names, including reserved properties, within the expression sandbox.
Exploit preconditions
- Attack surface: n8n workflow expressions using the
$fromAIhandler - Required access: Permission to create or modify workflows
- Trigger point: Resolution of a caller-supplied placeholder name
- Why exploitation is possible: Property resolution does not sufficiently restrict access to own, non-reserved properties and can expose a live host-prototype reference, allowing the sandbox boundary to be bypassed
Why this happens
The underlying bug is insufficient isolation between expression data and host-language object capabilities. The $fromAI handler resolves caller-controlled property names without requiring own-property access and permits reserved keys; when the input is a primitive, this behavior can expose an object prototype associated with the host runtime. That reference can provide a path to dynamic function construction and code execution, matching CWE-94: Improper Control of Generation of Code ('Code Injection').
Potential impact
- An attacker may execute arbitrary JavaScript in the main n8n process
- Workflow execution credentials and stored secrets could be exposed
- The n8n service could be modified, disrupted, or used for persistence
- Connected systems and data may be accessed or altered
- The host environment could be used for further lateral movement, depending on privileges
General mitigation guidance
Mitigation generally focuses on preserving a strict separation between workflow data and host-language capabilities.
Common defensive patterns include:
- Resolve only explicitly allowlisted data properties and require own-property checks
- Reject reserved names and prototype-related property paths
- Normalize or constrain primitive and object inputs before expression evaluation
- Use capability-limited expression runtimes that do not expose constructors, prototypes, or dynamic code-generation APIs
- Apply least privilege to the n8n service account and isolate its execution environment
- Restrict workflow-building permissions to trusted users and separate authoring from execution privileges
- Treat workflow definitions and expression inputs as untrusted content by default
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis rules for unrestricted dynamic property access, prototype traversal, and use of dynamic function construction
- Code review checks for expression handlers that accept caller-controlled property names
- Tests covering reserved keys, inherited properties, primitive inputs, and prototype-chain exposure
- Policy enforcement that blocks dynamic code generation and disallowed host objects in sandboxed runtimes
- Monitoring for unexpected workflow changes, unusual process behavior, and access to sensitive environment resources
Automated security review tools may help flag dangerous property-resolution and sandbox-boundary patterns, but should be supplemented with runtime isolation testing.

