T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:71
- Finding
- Unrestricted Caller-Controlled Output Directory and Broad Archival Operation<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:71-81`, `SKILL.md:96`; `references/companion-contract.md:27-29`; `references/failure-modes.md:68-76` **Vulnerability Type**: Arbitrary file destination and unsafe directory archival **Risk Level**: Medium ### Vulnerable Code From `SKILL.md`: ```markdown | `output_dir` | absolute path | no | derived | Where plan.md, findings/, and report.md land. | | `refresh` | bool | no | `false` | When true, allow overwriting a prior run in the same `output_dir`. | ``` ```markdown If the caller provides `output_dir`, use it verbatim. Otherwise derive the default: ``` ```markdown **Re-run protection.** Before writing anything, check whether `output_dir` already contains `plan.md` or `report.md`. If it does and `refresh` is not `true`, refuse with a message naming the existing folder. When `refresh: true`, archive the prior contents into `<output_dir>/.archive-<timestamp>/` first, then start fresh. ``` From `references/failure-modes.md`: ```markdown **Rule:** before writing anything to `output_dir`, check whether it already contains `plan.md` or `report.md`. - **If it does and `refresh` is not `true`:** refuse with a message naming the existing folder. - **If it does and `refresh: true`:** move the existing contents to `<output_dir>/.archive-<YYYYMMDD-HHMMSS>/` first, then proceed with a fresh run. The archive preserves the audit trail. - **If it does not:** proceed normally. ``` ### Technical Analysis The Skill accepts any absolute path and explicitly directs the Agent to use it verbatim. It does not require path canonicalization, workspace confinement, ownership validation, symlink rejection, or confirmation that the target is a directory created and owned by this Skill. The `refresh: true` workflow increases the risk because it directs the Agent to move the directory's “existing contents,” rather than limiting the operation to kno ...[truncated 1887 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Confine all output to a fixed, dedicated workspace root such as `.beagle/research/`. 2. Canonicalize the requested path before use and verify that it remains beneath the approved root. 3. Reject symbolic links, traversal components, filesystem roots, home directories, and other sensitive locations. 4. Create a unique run directory owned by the Skill rather than accepting arbitrary absolute destinations verbatim. 5. Add a Skill-specific ownership marker and require it before allowing `refresh`. 6. Archive only known Skill artifacts: - `plan.md` - `report.md` - `findings/` - a Skill-owned metadata file 7. Never move all existing directory contents. 8. Require explicit user confirmation before refreshing any caller-provided directory. 9. Use collision-resistant archive names and fail closed if the archive destination already exists. 10. Validate every final write path again immediately before performing filesystem operations to reduce symlink and time-of-check/time-of-use risks. ]]>
