T09 · Insecure Skill Coding Practices
- Location
scripts/generate-proposals.py:128- Finding
Telemetry-Controlled Path Traversal in Proposal Output
- Content
View full analysis
= cutoff: all_scores.append(skill_data) except: continue ``` ```python skill_name = skill_data["skill"] ``` ```python proposal_file = PROPOSALS_DIR / "pending" / f"{skill_name}.json" proposal_file.write_text( json.dumps(proposal, indent=2, ensure_ascii=False), encoding="utf-8" ) ``` ### Technical Analysis The proposal generator reads the `skill` field from JSON files under `~/.openclaw/data/gungun/health-scores/` without validating its format. That value is subsequently incorporated directly into an output path. `pathlib.Path` does not prevent traversal through components such as `../`. An attacker who can modify a health-score file can therefore cause the resolved proposal path to escape the intended `proposals/pending` directory. Depending on the crafted value, the write may create or overwrite a JSON file elsewhere within the current user's writable filesystem. Although normal health snapshots derive Skill names from local directory entries, the proposal generator independently trusts every matching JSON file. A malicious local process, compromised Skill, or corrupted data file could inject a crafted record without passing through the normal health-score generation flow. ### Attack Path 1. The attacker obtains the ability to create or modify a JSON file in `~/.openclaw/data/gungun/health-scores/`. This could occur through another Skill operating under the same user account or another local process with access to that directory. 2. The attack ...[truncated 1538 chars]- Remediation
View remediation
str: if not isinstance(skill_name, str): raise ValueError("Skill name must be a string") if not SKILL_NAME_PATTERN.fullmatch(skill_name): raise ValueError("Invalid skill name") if skill_name in {".", ".."}: raise ValueError("Invalid skill name") return skill_name ``` 2. Resolve the final path and verify that it remains below the intended directory: ```python pending_dir = (PROPOSALS_DIR / "pending").resolve() pending_dir.mkdir(parents=True, exist_ok=True) safe_name = validate_skill_name(skill_name) proposal_file = (pending_dir / f"{safe_name}.json").resolve() if proposal_file.parent != pending_dir: raise ValueError("Proposal path escapes the pending directory") ``` 3. Validate the complete health-record schema before processing it, including the types and ranges of `skill`, `timestamp`, `total`, `scores`, and `stats`. 4. Use restrictive directory and file permissions where supported. Proposal and telemetry directories should not be writable by unrelated users. 5. Consider atomic writes through a temporary file created inside the destination directory, followed by `os.replace()`, to reduce corruption from interrupted or concurrent runs. 6. Log and reject malformed records instead of silently suppressing all exceptions with a bare `except`. ]]>
