T09 · Insecure Skill Coding Practices
- Location
scripts/local_material_batch.py:31- Finding
Symlink Traversal Allows Reading Files Outside the Inbox
- Content
View full analysis
list[Path]: inbox = root / "Inbox" if not inbox.exists(): return [] return sorted(p for p in inbox.rglob("*") if p.is_file()) def process_text(path: Path) -> str: return path.read_text(encoding="utf-8", errors="replace") ``` ### Technical Analysis The recursive discovery function treats every path for which `Path.is_file()` returns true as a valid Inbox file. Symbolic links that resolve to regular files also satisfy this condition. Before reading a discovered file, the implementation does not: - Reject symbolic links. - Resolve the candidate path and verify that it remains under the resolved Inbox directory. - Revalidate the path immediately before opening it. Consequently, a symbolic link with a supported text extension can point to any file readable by the process. `process_text()` follows the link and reads the target. The disclosed content is subsequently written into the generated `text.md`, `text.json`, and batch `manifest.json` artifacts. The use of `path.relative_to(root)` does not prevent this issue because it validates the lexical location of the symbolic link, not the location of its resolved target. ### Attack Path 1. An attacker or untrusted archive gains the ability to place an entry in the workflow's `Inbox` directory. 2. The attacker creates a supported text path such as `Inbox/imported-note.txt` as a symbolic link to a sensitive local file readable by the user running the Skill. 3. The user runs: ```bash python3 scripts/local_material_batch.py run ``` 4. `discover()` includes the symbolic link because `is_file()` follows it and recognizes its target as a regular file. 5. `process_text()` follows the link and reads the external target. 6. The se ...[truncated 942 chars]- Remediation
View remediation
list[Path]: inbox = (root / "Inbox").resolve() if not inbox.is_dir(): return [] items = [] for candidate in inbox.rglob("*"): if candidate.is_symlink(): continue resolved = candidate.resolve(strict=True) if not resolved.is_relative_to(inbox): continue if resolved.is_file(): items.append(resolved) return sorted(items) ``` Additional hardening should include: 1. Revalidate the resolved path immediately before reading it to reduce time-of-check/time-of-use risk. 2. Open files with platform-supported no-follow semantics where available. 3. Document that imported archives must not preserve symbolic links unless explicitly trusted. 4. Add automated tests covering: - A symlink to a file outside `Inbox`. - A symlink to a directory outside `Inbox`. - Nested symlink chains. - Replacement of a validated file with a symlink before reading. 5. Run the workflow under a minimally privileged account that cannot read unrelated sensitive files. ]]>
