T09 · Insecure Skill Coding Practices
- Location
scripts/task_father.py:143- Finding
Arbitrary JSON File Overwrite or Deletion Through an Unsanitized Cron Name
- Content
View full analysis
- Remediation
View remediation
str: if not SAFE_CRON_NAME.fullmatch(name): raise ValueError( "cron name must contain only letters, digits, underscores, and hyphens" ) return name ``` 2. Explicitly reject absolute paths, path separators, `.` and `..`, even if a regular expression is also used. 3. Resolve the destination and verify that it remains beneath the intended cron directory: ```python cron_dir = (task_dir / "crons").resolve() cron_dir.mkdir(parents=True, exist_ok=True) name = validate_cron_name(name) destination = (cron_dir / f"{name}.json").resolve() if destination.parent != cron_dir: raise ValueError("cron specification path escapes the cron directory") ``` 4. Apply the same validation and containment checks to both creation and removal operations. 5. Consider refusing to overwrite an existing specification unless replacement was explicitly requested. Atomic file creation or replacement should be used to avoid partial writes. 6. Avoid following attacker-controlled symbolic links. Where the deployment threat model includes local untrusted users, use low-level file operations with appropriate no-follow and exclusive-creation controls. 7. Run the skill under a least-privileged account whose filesystem permissions are limited to the required OpenClaw workspace. 8. Use `check=True` for the `openclaw` subprocess calls, or inspect their return codes. Only report success and append successful changelog entries after the external cron operation completes successfully. ]]>
