Summary
OpenClaw previously embedded the current working directory path directly into the agent's system prompt without sanitizing control or format characters.
If an attacker can cause OpenClaw to run in a directory whose name contains characters like newlines or Unicode bidi/zero‑width markers, they can break the prompt structure and inject their own instructions into the LLM context.
Affected context
This vulnerability arises when OpenClaw is executed in a workspace directory whose name includes control characters (such as newlines), explicit line/paragraph separators, or Unicode formatting characters (such as bidi or zero-width markers).
In affected versions, this path is interpolated directly into the system prompt that guides the AI assistant's behavior.
In environments where an attacker can influence the working directory name (e.g., shared machines, malicious project archives, or CI environments with untrusted job parameters), the AI's instruction boundary can be unintentionally extended, allowing prompt manipulation.
Exploit preconditions
- Attack surface: LLM system prompt construction within OpenClaw.
- Required access: Ability to influence or create the directory in which OpenClaw runs, including control over the directory name.
- Trigger point: Launching OpenClaw while its current working directory contains crafted control/format characters in its path.
- Why exploitation is possible: The workspace path is embedded into the system prompt without stripping control and formatting characters, allowing directory names to introduce new lines or logical segments in the prompt and inject attacker-controlled instructions that the model may follow.
Why this happens
The issue stems from treating a filesystem path as benign text and directly concatenating it into a security-sensitive prompt without normalizing or constraining its character set.
This maps to CWE-77: Improper Neutralization of Special Elements used in a Command in an LLM context: special characters (e.g., newline, Unicode control/format characters) are not neutralized before being interpreted by the downstream "command engine" (the LLM).
Because prompt boundaries and instruction hierarchy are implicitly derived from text structure, these characters can alter control flow at the semantic level, enabling attacker-controlled directives to be interpreted as authoritative instructions.
Potential impact
- The AI assistant may follow attacker-specified instructions embedded via the directory name.
- Data within the workspace or connected tools may be accessed, modified, or exfiltrated based on injected directives.
- Automated tasks (e.g., file editing, command suggestions, API calls) could be steered towards unintended, attacker-aligned outcomes.
- Safety policies and guardrails enforced mainly at the prompt level may be bypassed or weakened.
- Downstream systems that trust the assistant's actions or outputs may be indirectly compromised.
General mitigation guidance
Effective mitigation focuses on treating all dynamic strings interpolated into prompts as untrusted and constraining their influence on prompt structure:
- Apply strict sanitization to any user-controllable or environment-derived text before it enters the system prompt, including workspace paths, user labels, and metadata.
- Strip or normalize Unicode control/format characters and explicit line/paragraph separators from such values, or replace them with safe placeholders.
- Use structured prompt construction (e.g., well-defined templates and field encodings) that avoids letting raw strings control line breaks or section delimiters.
- Conceptually separate "data fields" (like paths) from "instruction text," ensuring that dynamic values cannot be interpreted as additional instructions.
- Apply least-privilege to the assistant's capabilities so that even if prompt influence occurs, the blast radius of misbehavior is constrained.
How teams detect issues like this
Detection primarily involves examining how prompts are built and where untrusted data flows into system messages:
- Use static analysis or code scanning to identify places where environment-derived strings (paths, usernames, project names) are interpolated into prompts without sanitization or encoding.
- During code review, flag any direct concatenation of user-controlled or filesystem-controlled values into LLM system or developer messages.
- Implement internal policies requiring explicit sanitization/encoding helpers for all prompt parameters, and enforce their use with linting or CI checks.
- Log prompt construction in controlled environments (with care for privacy) to spot anomalous characters or unexpected line breaks originating from metadata fields.

