Summary
OpenClaw versions prior to 2026.2.19 contain a local command injection issue in the generation of Windows scheduled task gateway.cmd scripts, caused by unsafe handling of command-line metacharacters and expansion-sensitive characters.
A local attacker who can control arguments used to generate these service scripts may inject arbitrary commands, including via metacharacter-only input or crafted CR/LF sequences, which then execute in the scheduled task's security context.
Affected context
The vulnerability occurs during the creation of Windows scheduled task scripts (gateway.cmd) within OpenClaw deployments that:
- Dynamically generate command files based on user- or service-supplied arguments
- Concatenate or interpolate arguments directly into cmd.exe command lines or batch file content
- Do not properly escape or validate Windows shell metacharacters, environment expansion tokens, or line breaks
It is primarily relevant where scheduled tasks run with elevated or service-level privileges and accept parameters influenced by local users or other processes.
Exploit preconditions
- Attack surface: Local system (Windows host running OpenClaw)
- Required access: Ability to control or influence arguments used in gateway.cmd script generation (e.g., local user, scheduled job configurator, or compromised local component)
- Trigger point: Execution of the generated Windows scheduled task that invokes the vulnerable gateway.cmd script
- Why exploitation is possible:
- Arguments are embedded directly into shell commands or batch scripts without robust quoting or escaping
- Windows cmd metacharacters (such as command separators and redirection operators) and CR/LF sequences are interpreted by the shell as control syntax
- The scheduled task runs the resulting gateway.cmd file in a context that may have higher privileges than the attacker
Why this happens
The root cause is the improper construction of command lines and batch scripts from untrusted or semi-trusted input, a classic CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Instead of treating user-controlled values as opaque data passed as arguments, the generation logic embeds them directly into gateway.cmd content or cmd.exe command strings.
Because expansion-sensitive characters, metacharacters, and CR/LF sequences are not rigorously neutralized, the Windows command interpreter treats them as control syntax, allowing injected commands to be parsed and executed alongside the intended command.
This pattern reflects an insecure abstraction where the shell is used as a transport mechanism for user-influenced parameters rather than isolating those parameters from command parsing.
Potential impact
- Local attackers could execute arbitrary OS commands in the security context of the scheduled task.
- Attackers may escalate privileges if scheduled tasks run with service, administrative, or SYSTEM-level rights.
- Integrity of OpenClaw configuration and local data could be compromised through unauthorized modification or deletion.
- Local persistence mechanisms could be installed by embedding backdoor commands into recurring scheduled tasks.
- System confidentiality may be impacted by exfiltration of sensitive files or credentials accessible to the task context.
General mitigation guidance
Effective mitigation focuses on removing dependence on shell parsing for user-influenced operations and strictly neutralizing any remaining shell interactions:
- Avoid shell command construction where possible:
- Prefer direct invocation of underlying executables or APIs with parameter arrays (e.g., using process-creation APIs that do not require shell parsing).
- Treat gateway scripts as configuration wrappers with fixed structure, not as templates with arbitrary string interpolation.
- Strong argument handling and encoding:
- When cmd or batch scripts must be used, rigorously quote and escape all variables inserted into command lines.
- Treat CR/LF,
%,&,|,>,<,^,"and similar characters as untrusted and either reject or encode them such that the shell cannot interpret them as control syntax. - Apply strict validation with allowlists for expected formats (e.g., alphanumeric, hyphens, known option sets) instead of attempting to blacklist bad characters.
- Privilege and execution-hardening:
- Run scheduled tasks and associated gateway.cmd scripts with the minimum privileges necessary, avoiding administrative or SYSTEM accounts where feasible.
- Limit which local users or components are allowed to influence script-generation arguments, employing OS-level access controls.
- Prefer non-interpreted task definitions (e.g., direct executable paths with arguments) over generic shell command lines.
- Secure-by-default configuration:
- Make safe argument handling the default behavior in script generation utilities.
- Centralize command-building logic so consistent escaping and validation rules are applied across all scheduled tasks.
How teams detect issues like this
Detection typically involves both code-centric and configuration-centric review:
- Static analysis patterns:
- Flag locations where user-controlled input is concatenated into strings passed to cmd.exe,
CreateProcesswithcmd /c, or written into.cmd/.batfiles. - Look for script templates that interpolate raw variables into gateway.cmd without a dedicated escaping function.
- Identify any handling of CR/LF or other control characters that are preserved when generating command scripts.
- Code review signals:
- Inline string construction for scheduled task commands that mixes literals with potentially tainted variables.
- Absence of centralized helper functions for building safe command lines or escaping Windows shell metacharacters.
- Business logic that assumes local inputs are "trusted" simply because they come from the same host or service.
- Runtime and configuration analysis:
- Inspect generated gateway.cmd files for unexpected extra lines, command separators, or environment expansion patterns.
- Monitor scheduled task executions for anomalous spawned processes or commands that are not part of the intended job definition.
- Automated tooling:
- Use SAST tools configured with rules for OS command injection (CWE-78) in Windows contexts.
- Incorporate pre-commit or CI checks that specifically scan for dangerous shell invocation patterns or script-generation constructs.

