T09 · Insecure Skill Coding Practices
- Location
scripts/file_transfer.py:14- Finding
Workspace Path Validation Bypass Allows Unauthorized File Upload
- Content
View full analysis
Vulnerability Details
File Location:
scripts/file_transfer.py:14-21(validation), with the validated path used atscripts/file_transfer.py:76-92
Vulnerability Type: Improper path containment validation and symlink traversal
Risk Level: HighVulnerable Code
python def is_safe_path(path_str, workspace_root): """ Check if the given path is within the workspace root to prevent directory traversal. """ try: # Convert to absolute paths and resolve any symlinks or '..' abs_path = os.path.abspath(path_str) abs_workspace = os.path.abspath(workspace_root) # Ensure the path starts with the workspace root return abs_path.startswith(abs_workspace) except Exception: return FalseThe result of this check is subsequently trusted when selecting a file for upload:
python # Security check: ensure the path is within the workspace if not is_safe_path(input_path, workspace_root): print("Error: Access denied. The file must be within the OpenClaw workspace.", file=sys.stderr) sys.exit(1) # Check if the file exists if not os.path.isfile(input_path): print(f"Error: File not found: {input_path}", file=sys.stderr) sys.exit(1) # Perform the upload output, error = run_upload(input_path)Technical Analysis
The implementation uses a lexical string-prefix comparison to determine whether a file is inside
/home/ubuntu/.openclaw/workspace. A string prefix does not enforce a filesystem directory boundary. For example, the following external path passes the check because its text begins with the workspace path:text /home/ubuntu/.openclaw/workspace-private/secret.txtIn addition,
os.path.abspath()normalizes relative path components but does not resolve symbolic links, despite the source comment claiming that it does. A path lexically located under the workspace can therefore be a sy ...[truncated 2608 chars]- Remediation
View remediation
Remediation Suggestions
-
Resolve both the workspace and candidate path to canonical filesystem paths before comparing them:
python from pathlib import Path def get_safe_file(path_str, workspace_root): try: workspace = Path(workspace_root).resolve(strict=True) candidate = Path(path_str).resolve(strict=True) if not candidate.is_relative_to(workspace): return None if not candidate.is_file(): return None return candidate except (OSError, RuntimeError): return None -
For Python versions without
Path.is_relative_to(), useos.path.commonpath()rather thanstartswith():python if os.path.commonpath([str(candidate), str(workspace)]) != str(workspace): return None -
Explicitly reject symbolic links when links are not required. Validate every relevant path component or use descriptor-based filesystem operations that do not follow links.
-
Reduce validation/use race conditions by securely opening the validated file first and uploading from that already-open descriptor where supported. On Linux, consider
os.open()withO_NOFOLLOWand verify the opened file usingfstat(). -
Pass the canonical validated path—not the original untrusted path—to the upload function.
-
Add regression tests for:
- Sibling-prefix paths such as
workspace-private/file. ..traversal.- Symlinks targeting files outside the workspace.
- Broken and recursively resolving symlinks.
- Replacement of a validated file or link before upload.
- Sibling-prefix paths such as
-
Update
SKILL.mdso its security guarantees accurately reflect the implemented controls and any remaining limitations.
-
