The vulnerability is a prompt injection issue in OpenClaw, where the current working directory path was not sanitized before being included in an LLM prompt. An attacker who can control the directory name where OpenClaw is executed could use special characters (like newlines) to inject malicious instructions into the system prompt, potentially leading to unintended agent behavior.
The analysis of the fix commit 6254e96acf16e70ceccc8f9b2abecee44d606f79 reveals the vulnerable parts of the code. A new sanitization function, sanitizeForPromptLiteral, was introduced and applied in two key places:
-
resolveRunWorkspaceDir in src/agents/workspace-run.ts: This function is responsible for resolving the workspace directory path. Before the patch, it would process a user-provided path without any sanitization. The returned workspaceDir could contain malicious characters. The patch introduces a call to the new sanitizeForPromptLiteral function to clean the path.
-
buildAgentSystemPrompt in src/agents/system-prompt.ts: This function constructs the system prompt for the agent. It was directly embedding the workspaceDir and other path-related strings from sandboxInfo into the prompt. Since these values were not sanitized, it was possible to inject newlines and other control characters, thus altering the prompt's structure and instructions. The patch applies sanitizeForPromptLiteral to all these values before they are included in the prompt.
The identified functions are the ones that either process the malicious input (resolveRunWorkspaceDir) or use it to construct the vulnerable output (buildAgentSystemPrompt). An attacker exploiting this vulnerability would cause these functions to appear in a runtime profile.