T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/yotta_learn.py:425
- Finding
- Unrestricted promotion target permits arbitrary file overwrite## Vulnerability Details **File Location**: `scripts/yotta_learn.py:425-445` **Vulnerability Type**: Unrestricted path traversal and arbitrary file write **Risk Level**: Medium ### Technical Analysis The `promote` command accepts `--to` as an unrestricted path and joins it directly to the selected learning directory. Python's `pathlib` discards the base path when the right operand is absolute. Relative paths containing `../` can likewise escape the intended directory. The destination is then passed to `_atomic_write_text`, which creates missing parent directories and replaces an existing file. There is no canonical-path containment check and no allowlist restricting the destination to `AGENTS.md` or `CLAUDE.md`. ```python target_name = args.to if not target_name or target_name == "auto": target_name = "CLAUDE.md" if (directory / "CLAUDE.md").exists() else "AGENTS.md" target = directory / target_name old = _read_text(target) if entry.summary and entry.summary[:60] in old: print("[提示] 目标文件已包含相似内容,跳过(自动去重)") return 0 if not old.endswith("\n"): old += "\n" _atomic_write_text(target, old + block + "\n") ``` The unrestricted option is registered here: ```python p_promote.add_argument("--to", help="目标文件(默认 auto:CLAUDE.md 优先)") ``` This exceeds the minimum privileges needed to promote an entry into one of the two declared agent instruction files. It does not independently elevate operating-system privileges: the process remains limited to files writable by the invoking user. ### Attack Path 1. An attacker convinces a user or automation workflow to invoke `promote` with a crafted `--to` value, or controls parameters passed to the CLI. 2. The attacker supplies an absolute path or a traversal path such as `../../some-file`. 3. The command reads the existing destination, appends the generated promotion block, and atomically replaces the file. 4. If the destination is an agent configuration o ...[truncated 924 chars]
- Remediation
- ## Remediation Suggestions - Remove arbitrary `--to` support unless it is essential. - Allow only the exact basenames `AGENTS.md` and `CLAUDE.md`. - Resolve both the base and destination paths and enforce containment with `Path.relative_to`. - Reject absolute paths, `..` components, symlinks, devices, and non-regular destination files. - Require explicit confirmation before modifying an existing instruction file. - Escape or delimit promoted learning text so it is treated as quoted data rather than agent instructions. - Add tests for absolute paths, traversal paths, symlink destinations, and existing-file overwrite behavior.
