T09 · Insecure Skill Coding Practices
- Location
scripts/init_project.py:43- Finding
Arbitrary Filesystem Write Through Unvalidated Path Components
- Content
View full analysis
`', f'`{projects_root}`') if write_text(system_path, content, overwrite=overwrite): created.append(str(system_path)) else: skipped.append(str(system_path)) files = [ '00_恢复入口.md', '00_文档总索引与当前进度.md', '01_项目会话与恢复机制说明.md', '99_关键决策记录.md', 'checkpoints/README.md', 'session-backups/README.md', ] for rel in files: target = project_dir / rel content = read_template(base_dir, rel) content = content.replace('<项目名称>', project_ ...[truncated 3462 chars]- Remediation
View remediation
Path: candidate_component = Path(component) if ( candidate_component.is_absolute() or component in {"", ".", ".."} or len(candidate_component.parts) != 1 ): raise ValueError("Expected one safe path component") root = root.resolve() candidate = (root / candidate_component).resolve() if not candidate.is_relative_to(root): raise ValueError("Destination escapes the configured root") return candidate ``` 4. **Harden overwrite behavior** - Remove the undocumented `overwrite` parameter if it is unnecessary. - Otherwise, require explicit confirmation for every existing file. - Use exclusive creation mode for new files to reduce race conditions. - Create a backup before replacing an existing file. 5. **Defend against symbolic-link writes** - Reject destination files and parent directories that are symbolic links. - Revalidate paths immediately before writing. - Where supported, use operating-system primitives that prevent symlink following. 6. **Improve documentation and tests** - Document the exact accepted format for all path-related field ...[truncated 214 chars]
