Summary
OpenClaw contains a path traversal vulnerability in its Feishu media download flow where untrusted media keys are directly interpolated into temporary file paths.
An attacker who can influence Feishu media key values can use directory traversal sequences to escape the expected temporary directory and write arbitrary files within the permissions of the OpenClaw process.
Affected context
This issue appears in deployments of OpenClaw that use the Feishu integration for media downloading, specifically in the extensions/feishu/src/media.ts component.
The vulnerability manifests when media keys returned from Feishu (or any upstream source acting as Feishu) are treated as trusted and interpolated into file paths located under os.tmpdir(), without normalization, sanitization, or restriction to a known-safe directory.
Environments where OpenClaw's Feishu flow processes media keys originating from external or potentially manipulated Feishu responses are more exposed, especially when the OpenClaw process runs with access to sensitive filesystem locations.
Exploit preconditions
- Attack surface: Feishu media download flow in OpenClaw (server-side integration).
- Required access: Ability to control or significantly influence Feishu media key values that OpenClaw processes (e.g., via a compromised Feishu app, manipulated API responses, or control of content that drives media key generation).
- Trigger point: Invocation of the media download logic in
extensions/feishu/src/media.ts, where the media key is interpolated into a temporary file path underos.tmpdir(). - Why exploitation is possible: The media key, treated as data, is interpolated directly into filesystem paths without enforcing a safe base directory, canonicalization, or checks against traversal patterns (e.g.,
../), making it possible to escapeos.tmpdir()and write files in arbitrary locations reachable by the OpenClaw process.
Why this happens
The root cause is the failure to validate and constrain user-influenced path components before constructing filesystem paths, matching CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
In the affected code path, untrusted media key values are interpolated into a temporary file path derived from os.tmpdir() but not canonicalized or checked to ensure they remain within that directory.
By including directory traversal sequences or absolute path indicators in the media key, an attacker can cause the application to resolve the final path outside of the intended temporary directory, enabling arbitrary file writes within the privileges of the OpenClaw process.
Abstractly, this pattern reflects a common bug class: combining untrusted strings with filesystem paths without enforcing a strict, canonical base directory and without rejection or normalization of traversal constructs.
Potential impact
- Creation or overwriting of arbitrary files accessible to the OpenClaw process.
- Planting or modifying configuration files that OpenClaw or co-located services may later read and act upon.
- Tampering with application logs or data files, potentially obscuring other malicious activity or corrupting data.
- In specific environments, possible escalation to remote code execution if attackers can overwrite scripts, hooks, or other executable artifacts that are subsequently loaded or executed by trusted components.
- Lateral movement across application components that share the same filesystem and trust relationships.
General mitigation guidance
Effective mitigation focuses on constraining path construction and reducing trust in external identifiers:
- Treat media keys and similar identifiers as opaque tokens, never as path fragments, and map them to filesystem-safe names (e.g., using generated IDs or safe hashing) instead of interpolating them directly into paths.
- Enforce a hard-coded, canonical base directory for temporary and downloaded files, and ensure that resolved paths are checked to remain under this directory after normalization.
- Normalize and validate paths before use, rejecting any input containing traversal constructs (
.., leading slashes, or platform-specific equivalents) or unexpected characters for the given environment. - Apply least-privilege principles to the OpenClaw runtime: run the process with minimal filesystem permissions and restrict write access to only those directories strictly needed for operation.
- Consider using higher-level storage abstractions (e.g., object stores, sandboxed temp directories) that decouple user-controlled identifiers from direct filesystem paths.
How teams detect issues like this
Organizations can identify similar vulnerabilities through a combination of static and process-based approaches:
- Static analysis: Configure rules to flag direct concatenation or interpolation of untrusted input into filesystem paths (especially uses of
os.tmpdir()followed by externally influenced components) and to highlight uses of../or absolute paths derived from request or API data. - Code review: During manual review, treat any path construction using values sourced from external APIs (such as Feishu responses), HTTP parameters, or message payloads as a high-risk pattern and verify that each such path is restricted to a known-safe directory and validated after canonicalization.
- Policy enforcement: Introduce engineering guidelines or linting rules that require path-joining helpers with built-in validation and prohibit direct string concatenation for building paths, particularly in integration layers dealing with third-party platforms.
- Runtime monitoring: Where feasible, monitor the application for unexpected write operations outside designated directories (e.g., using OS-level auditing or container-level policies) as a compensating control to detect potential exploitation attempts.
- Automated code scanning or SAST tools that understand filesystem APIs in the project's language can be configured to continuously scan for path traversal patterns as part of CI workflows.

