T09 · Insecure Skill Coding Practices
- Location
scripts/read_mail.py:16- Finding
Unchecked Path Components Permit Arbitrary Local File Disclosure and Filesystem Writes
- Content
View full analysis
Vulnerability Details
File Location:
scripts/read_mail.py, lines 16-36
Vulnerability Type: Path traversal and insufficient path containment
Risk Level: HighVulnerable Code
python base_dir = Path("/Users/zhaoruiwu/.openclaw/workspace/hera-agents") inbox_dir = base_dir / agent_name / "inbox" mail_file = inbox_dir / mail_file_name if not mail_file.exists(): print(f"❌ Mail not found: {mail_file_name}") print(f" Check inbox with: python3 list_inbox.py {agent_name}") return # Read and display content content = mail_file.read_text() print("\n" + "=" * 60) print("📖 MESSAGE CONTENT") print("=" * 60 + "\n") print(content) print("\n" + "=" * 60) # Mark as read read_marker = mail_file.with_suffix(".read") read_marker.touch() print(f"✓ Marked as read: {mail_file_name}")Technical Analysis
Both
agent_nameandmail_file_nameare accepted directly from command-line arguments and used to construct filesystem paths without validation or containment checks.Python's
pathlibdiscards preceding path components when a later component is absolute. Consequently, an absolutemail_file_namecausesmail_fileto refer directly to the supplied location rather than a file beneath the intended inbox. Relative paths containing..can also escape the inbox directory.The selected path is passed to
read_text(), and its contents are printed before any.readmarker operation occurs. The script then derives another attacker-influenced path usingwith_suffix(".read")and callstouch(), creating or modifying that file if process permissions allow.Similar unchecked agent-path construction occurs in:
scripts/list_inbox.py:20-21scripts/send_mail.py:18-22scripts/send_mail.py:31-50
In
send_mail.py, an absolute or traversing agent path can redirect inbox and outbox operations into unintended writable directories, provided the selected ...[truncated 1771 chars]- Remediation
View remediation
Remediation Suggestions
-
Define an explicit allowlist of valid agent names rather than accepting arbitrary path components.
-
Require
mail_file_nameto be a plain basename ending in.md. -
Reject absolute paths,
.., path separators, null bytes, and unexpected suffixes. -
Resolve the inbox and candidate paths before access, then verify containment:
python inbox_dir = (base_dir / agent_name / "inbox").resolve() mail_file = (inbox_dir / mail_file_name).resolve() if not mail_file.is_relative_to(inbox_dir): raise ValueError("Mail path escapes the inbox") -
Require the target to be a regular file and consider rejecting symbolic links:
python if not mail_file.is_file() or mail_file.is_symlink(): raise ValueError("Invalid mail file") -
Construct read markers from a validated mail identifier rather than an arbitrary supplied path.
-
Apply equivalent resolution and containment checks to every path constructed in
list_inbox.pyandsend_mail.py. -
Run the skill under a dedicated, least-privileged account with filesystem access restricted to the HERA workspace.
-
