Summary
Windmill's NativeTS executor interpolates workspace environment variable values directly into JavaScript string literals without escaping single quotes, enabling JavaScript code injection.
A workspace admin who defines a crafted environment variable can execute arbitrary JavaScript in the context of every NativeTS script in that workspace, affecting all executions that rely on those interpolated values.
Affected context
This vulnerability occurs within Windmill workspaces using the NativeTS executor where environment variables are injected into generated JavaScript source code.
It is relevant when:
- Workspace-level environment variables are defined by administrators or privileged users
- NativeTS scripts rely on these environment variables and they are interpolated into JavaScript string literals
- The interpolation logic does not properly escape special characters (notably single quotes) before embedding values into code
The issue is confined to the JavaScript execution environment of the NativeTS worker and is not tied to the sandbox/NSJAIL configuration.
Exploit preconditions
- Attack surface: NativeTS code generation and execution path in the Windmill worker.
- Required access: Ability to define or modify workspace environment variables (typically workspace admin or equivalent privileged role).
- Trigger point: Execution of any NativeTS script in the affected workspace that uses environment variables subject to interpolation.
- Why exploitation is possible: Environment variable values are concatenated into JavaScript source as string literals without escaping single quotes, allowing an attacker to break out of the intended string context and inject arbitrary JavaScript statements.
Why this happens
The root cause is unsafe construction of JavaScript source code from data values in worker.rs, where environment variables are interpolated into string literals without proper escaping.
This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection'), where user-controlled or administrator-controlled input is used as part of dynamically generated code.
Instead of treating environment variables as pure data and passing them through a safe serialization or escaping mechanism, the implementation directly embeds them into code, enabling an attacker with control over those values to alter the program's behavior at runtime.
Potential impact
- Arbitrary JavaScript execution within the NativeTS runtime for all affected scripts in the workspace
- Unauthorized access to data handled by NativeTS scripts, including secrets or API responses available to those scripts
- Manipulation of workflow logic, resulting in incorrect actions, data corruption, or privilege misuse within the automation environment
- Lateral movement within the Windmill environment via abuse of the scripting context, depending on available APIs and integrations
General mitigation guidance
Effective mitigation focuses on treating environment variables as untrusted data and eliminating direct string-based code construction:
- Use robust escaping or encoding routines when embedding environment variable values into JavaScript, especially for quotes and control characters.
- Prefer structured parameter passing (e.g., JSON objects, sandboxed configuration objects) instead of interpolating values into source code strings.
- Centralize code generation logic so that escaping and serialization practices are consistent and easier to audit.
- Apply least-privilege principles to workspace administration, minimizing who can define or alter environment variables that affect code paths.
- Implement defensive runtime checks that limit or validate dynamically generated code in executor components.
How teams detect issues like this
Organizations can look for this class of issue and signs of exploitation using:
- Static analysis rules or linters that flag string concatenation or interpolation patterns where environment variables or configuration values are embedded into JavaScript source code.
- Code review checklists emphasizing safe handling of configuration data in code generators and worker components (e.g., review of
worker.rsand similar executors). - Centralized logging of NativeTS script compilation or execution, with alerts for unusual changes in workspace environment variables that correlate with unexpected script behavior.
- Use of automated security testing tools that search for CWE-94 patterns, especially in languages and components responsible for generating or executing dynamic code.

