Summary
A critical expression sandbox bypass in n8n allows certain free identifiers used in expressions to resolve against process-global objects. An authenticated user with workflow-edit permission may mutate host objects during expression evaluation, causing changes to persist across the process until it is restarted.
Affected context
The issue occurs in n8n deployments that evaluate user-controlled workflow expressions inside a sandbox and permit authenticated users to edit workflows. It becomes risky when expression evaluation exposes process globals through spread, computed-key, switch-case, or class-extension contexts, allowing mutations to affect shared runtime state rather than only the current expression.
Exploit preconditions
- Attack surface: n8n workflow expression evaluation - Required access: An authenticated account with permission to edit
workflows
- Trigger point: Evaluation of an expression using affected language
constructs
- Why exploitation is possible: The sandbox incorrectly resolves certain
free identifiers against process-global objects, permitting expression
evaluation to reach and mutate shared host state
Why this happens
The underlying bug is an incomplete isolation boundary in the expression sandbox. Identifier resolution for specific syntactic positions can escape the intended expression scope and bind to process-global objects. This behavior maps to CWE-95: Improper Neutralization of Directives in Dynamically-Evaluated Code, because user-influenced expressions are evaluated with access to runtime behavior that should remain outside the sandbox.
Potential impact
- An attacker may alter shared objects within the n8n process.
- Malicious changes could persist across workflow executions until restart.
- Workflow behavior, execution results, or connected integrations could be affected.
- The issue could enable broader application compromise depending on exposed host objects and process privileges.
- Data integrity or automation reliability could be degraded.
General mitigation guidance
Mitigation generally focuses on strengthening expression isolation and reducing the authority available to evaluated code. Secure-by-default patterns include using a narrowly defined allowlist of expression capabilities, preventing access to process globals and host objects, and resolving identifiers only within an explicit evaluation scope. Expression inputs can be treated as untrusted, with structural validation and policy enforcement applied before evaluation. Workflow-edit permissions should follow least privilege, and execution processes should run with only the permissions required for their tasks. Shared mutable state should also be minimized or isolated so that expression evaluation cannot create process-wide side effects.
How teams detect issues like this
Detection approaches include static analysis for dynamic evaluation paths, unsafe global-object exposure, and incomplete identifier allowlists. Code review should examine sandbox scope construction, handling of computed properties, spread expressions, switch cases, and class inheritance expressions. Runtime monitoring can look for unexpected mutations to shared process objects or changes in workflow behavior after expression execution. Policy enforcement can require security review for expression-engine changes and restrict workflow-edit permissions. Automated code review tools may help identify sandbox escapes and dangerous host-object references.

